diff --git a/condition.go b/condition.go index 9180e39..012c869 100644 --- a/condition.go +++ b/condition.go @@ -55,8 +55,10 @@ func (cs Conditions) UnmarshalJSON(data []byte) error { } for k, jc := range jcs { + var found bool for name, c := range ConditionFactories { if name == jc.Type { + found = true dc = c() if len(jc.Options) == 0 { @@ -72,6 +74,10 @@ func (cs Conditions) UnmarshalJSON(data []byte) error { break } } + + if !found { + return errors.Errorf("Could not find condition type %s", jc.Type) + } } return nil diff --git a/condition_test.go b/condition_test.go index 92fa021..389eb4f 100644 --- a/condition_test.go +++ b/condition_test.go @@ -54,3 +54,12 @@ func TestMarshalUnmarshal(t *testing.T) { assert.IsType(t, &EqualsSubjectCondition{}, cs["owner"]) assert.IsType(t, &CIDRCondition{}, cs["clientIP"]) } + +func TestUnmarshalFails(t *testing.T) { + cs := Conditions{} + require.NotNil(t, json.Unmarshal([]byte(`{ + "somefield": { + "type": "DoesntExist" + } +}`), &cs)) +}