Skip to content

Commit

Permalink
Merge pull request #114 from signalsciences/update-known-rules-fields
Browse files Browse the repository at this point in the history
add "requestCookie" and "value" as known rule condition fields
  • Loading branch information
shawnps authored Feb 20, 2023
2 parents ad6702e + 6ac9505 commit 7dc7db4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 9 additions & 2 deletions provider/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,17 @@ var siteImporter = schema.ResourceImporter{
}

func validateConditionField(val interface{}, key string) ([]string, []error) {
if existsInString(val.(string), "scheme", "method", "path", "useragent", "domain", "ip", "responseCode", "agentname", "paramname", "paramvalue", "country", "name", "valueString", "valueIp", "signalType", "signal", "requestHeader", "queryParameter", "postParameter") {
knownFields := []string{
"scheme", "method", "path", "useragent", "domain", "ip", "responseCode", "agentname",
"paramname", "paramvalue", "country", "name", "valueString", "valueIp", "signalType",
"signal", "requestHeader", "queryParameter", "postParameter", "requestCookie", "value",
}

if existsInString(val.(string), knownFields...) {
return nil, nil
}
return []string{fmt.Sprintf("received '%s' for conditions.field. This is not necessairly an error, but we only know about the following values. If this is a new value, please open a PR to get it added.\n(scheme, method, path, useragent, domain, ip, responseCode, agentname, paramname, paramvalue, country, name, valueString, valueIp, signalType, signal, requestHeader, queryParameter, postParameter)", val.(string))}, nil

return []string{fmt.Sprintf("received %q for conditions.field. This is not necessarily an error, but we only know about the following values. If this is a new value, please open a PR to get it added.\n(%s)", val.(string), strings.Join(knownFields, ", "))}, nil
}

func validateActionResponseCode(val interface{}, key string) ([]string, []error) {
Expand Down
28 changes: 28 additions & 0 deletions provider/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,31 @@ func testInspect() resource.TestCheckFunc {
}
}
*/

func TestValidateConditionField(t *testing.T) {
cases := []struct {
in string
wantErr bool
}{
{in: "scheme"},
{in: "queryParameter"},
{in: "value"},

{in: "unknownconditionfield", wantErr: true},
}

for _, tt := range cases {
got, err := validateConditionField(tt.in, "key")
if err != nil {
t.Fatal(err)
}

if got != nil && !tt.wantErr {
t.Errorf("validateConditionField(%q) returned invalid, want valid", tt.in)
}

if got == nil && tt.wantErr {
t.Errorf("validateConditionField(%q) returned valid, want invalid", tt.in)
}
}
}

0 comments on commit 7dc7db4

Please sign in to comment.