Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions bindings/csharp/Regorus.Tests/RegorusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ public void Rule_conflict_preserves_error_status_and_reports_previous_location()
Assert.IsFalse(ex.Message.Contains('"'));
}

[TestMethod]
public void Package_metadata_preserves_legacy_projection_while_rule_paths_remain_canonical()
{
using var engine = new Engine();
var package = engine.AddPolicy(
"namespace.rego",
"""
package graph.defUniqueName["1.0.0"]

default deny := false
deny := true if { input.blocked == true }
""");

Assert.AreEqual("data.graph.defUniqueName.1.0.0", package);
var packageNames = JsonNode.Parse(engine.GetPolicyPackageNames()!);
Assert.AreEqual(
"graph.defUniqueName.1.0.0",
packageNames![0]!["package_name"]!.GetValue<string>());
Assert.AreEqual(
"namespace.rego",
packageNames[0]!["source_file"]!.GetValue<string>());

engine.SetInputJson("""{"blocked":false}""");
Assert.AreEqual(
"false",
engine.EvalRule("data.graph.defUniqueName[\"1.0.0\"].deny"));
}

[TestMethod]
public void Evaluation_using_file_policies_succeeds()
{
Expand Down
16 changes: 16 additions & 0 deletions bindings/csharp/Regorus/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public void ClearPolicyLengthConfig()
});
}

/// <summary>
/// Adds a policy and returns its legacy dot-joined package metadata.
/// Quoted string contents omit their delimiter quotes. This value is
/// not a canonical rule path; use bracket notation for string
/// components when evaluating a rule.
/// </summary>
public string? AddPolicy(string path, string rego)
{
return Utf8Marshaller.WithUtf8(path, pathPtr =>
Expand All @@ -128,6 +134,11 @@ public void SetRegoV0(bool enable)
});
}

/// <summary>
/// Adds a policy file and returns its legacy dot-joined package
/// metadata, not a canonical rule path. Quoted string contents omit
/// their delimiter quotes.
/// </summary>
public string? AddPolicyFromFile(string path)
{
return Utf8Marshaller.WithUtf8(path, pathPtr =>
Expand Down Expand Up @@ -261,6 +272,11 @@ public void SetGatherPrints(bool enable)
});
}

/// <summary>
/// Returns policy package metadata with its legacy dot-joined text and
/// no <c>data</c> prefix. Quoted string contents omit their delimiter
/// quotes; use canonical bracketed paths for rule lookup.
/// </summary>
public string? GetPolicyPackageNames()
{
return UseHandle(enginePtr =>
Expand Down
Loading
Loading