Skip to content

Commit

Permalink
Add BooleanCondition to condition factory (#139)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Anderson Slate <[email protected]>
  • Loading branch information
joshuaslate authored and aeneasr committed Nov 18, 2019
1 parent f045129 commit 4334cd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,7 @@ var ConditionFactories = map[string]func() Condition{
new(ResourceContainsCondition).GetName(): func() Condition {
return new(ResourceContainsCondition)
},
new(BooleanCondition).GetName(): func() Condition {
return new (BooleanCondition)
},
}
16 changes: 12 additions & 4 deletions condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ func TestMarshalUnmarshalNative(t *testing.T) {

func TestMarshalUnmarshal(t *testing.T) {
css := &Conditions{
"clientIP": &CIDRCondition{CIDR: "127.0.0.1/0"},
"owner": &EqualsSubjectCondition{},
"role": &StringMatchCondition{Matches: ".*"},
"clientIP": &CIDRCondition{CIDR: "127.0.0.1/0"},
"owner": &EqualsSubjectCondition{},
"role": &StringMatchCondition{Matches: ".*"},
"hasElevatedPrivileges": &BooleanCondition{BooleanValue: true},
}
out, err := json.Marshal(css)
require.Nil(t, err)
Expand All @@ -75,15 +76,22 @@ func TestMarshalUnmarshal(t *testing.T) {
"matches": ".*"
}
},
"hasElevatedPrivileges": {
"type": "BooleanCondition",
"options": {
"value": true
}
},
"resourceFilter": {
"type": "ResourceContainsCondition"
}
}`), &cs))

require.Len(t, cs, 4)
require.Len(t, cs, 5)
assert.IsType(t, &EqualsSubjectCondition{}, cs["owner"])
assert.IsType(t, &CIDRCondition{}, cs["clientIP"])
assert.IsType(t, &StringMatchCondition{}, cs["role"])
assert.IsType(t, &BooleanCondition{}, cs["hasElevatedPrivileges"])
assert.IsType(t, &ResourceContainsCondition{}, cs["resourceFilter"])
}

Expand Down

0 comments on commit 4334cd7

Please sign in to comment.