Skip to content

Commit 4334cd7

Browse files
joshuaslateaeneasr
authored andcommitted
Add BooleanCondition to condition factory (#139)
Signed-off-by: Joshua Anderson Slate <[email protected]>
1 parent f045129 commit 4334cd7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

condition.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,7 @@ var ConditionFactories = map[string]func() Condition{
128128
new(ResourceContainsCondition).GetName(): func() Condition {
129129
return new(ResourceContainsCondition)
130130
},
131+
new(BooleanCondition).GetName(): func() Condition {
132+
return new (BooleanCondition)
133+
},
131134
}

condition_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ func TestMarshalUnmarshalNative(t *testing.T) {
5050

5151
func TestMarshalUnmarshal(t *testing.T) {
5252
css := &Conditions{
53-
"clientIP": &CIDRCondition{CIDR: "127.0.0.1/0"},
54-
"owner": &EqualsSubjectCondition{},
55-
"role": &StringMatchCondition{Matches: ".*"},
53+
"clientIP": &CIDRCondition{CIDR: "127.0.0.1/0"},
54+
"owner": &EqualsSubjectCondition{},
55+
"role": &StringMatchCondition{Matches: ".*"},
56+
"hasElevatedPrivileges": &BooleanCondition{BooleanValue: true},
5657
}
5758
out, err := json.Marshal(css)
5859
require.Nil(t, err)
@@ -75,15 +76,22 @@ func TestMarshalUnmarshal(t *testing.T) {
7576
"matches": ".*"
7677
}
7778
},
79+
"hasElevatedPrivileges": {
80+
"type": "BooleanCondition",
81+
"options": {
82+
"value": true
83+
}
84+
},
7885
"resourceFilter": {
7986
"type": "ResourceContainsCondition"
8087
}
8188
}`), &cs))
8289

83-
require.Len(t, cs, 4)
90+
require.Len(t, cs, 5)
8491
assert.IsType(t, &EqualsSubjectCondition{}, cs["owner"])
8592
assert.IsType(t, &CIDRCondition{}, cs["clientIP"])
8693
assert.IsType(t, &StringMatchCondition{}, cs["role"])
94+
assert.IsType(t, &BooleanCondition{}, cs["hasElevatedPrivileges"])
8795
assert.IsType(t, &ResourceContainsCondition{}, cs["resourceFilter"])
8896
}
8997

0 commit comments

Comments
 (0)