-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetPoliciesTest.cs
More file actions
108 lines (99 loc) · 3.48 KB
/
GetPoliciesTest.cs
File metadata and controls
108 lines (99 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using NUnit.Framework;
using OPADotNet.Ast.Models;
using OPADotNet.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace OPADotNet.Embedded.Tests
{
internal class GetPoliciesTest
{
[Test]
public async Task TestGetSinglePolicy()
{
OpaClientEmbedded opaClientEmbedded = new OpaClientEmbedded();
var txn = opaClientEmbedded.OpaStore.NewTransaction(true);
var rawPolicy = @"
package test
allow = true
";
txn.UpsertPolicy("pol1", rawPolicy);
txn.Commit();
var policies = await opaClientEmbedded.GetPolicies();
var expected = new List<Policy>()
{
new Policy(
"pol1.rego",
rawPolicy,
new AstPolicy()
{
Package = new AstPolicyPackage()
{
Path = new List<AstTerm>()
{
new AstTermVar()
{
Value = "data"
},
new AstTermString()
{
Value = "test"
}
}
},
Rules = new List<AstPolicyRule>()
{
new AstPolicyRule()
{
Body = new AstBody()
{
Expressions = new List<AstExpression>()
{
new AstExpression()
{
Terms = new List<AstTerm>()
{
new AstTermBoolean(){ Value = true}
}
}
}
},
Head = new AstRuleHead()
{
Name = "allow",
Value = new AstTermBoolean()
{
Value = true
}
}
}
}
}
)
};
Assert.AreEqual(expected, policies);
}
[Test]
public void TestGetPolicyWithStatementDoNotThrow()
{
OpaClientEmbedded opaClientEmbedded = new OpaClientEmbedded();
var txn = opaClientEmbedded.OpaStore.NewTransaction(true);
var rawPolicy = @"
package test
allow = true
test_case {
allow with input as {
""test"": ""t1""
}
}
";
txn.UpsertPolicy("pol1", rawPolicy);
txn.Commit();
Assert.DoesNotThrowAsync(async () =>
{
var policies = await opaClientEmbedded.GetPolicies();
});
}
}
}