Skip to content

Commit

Permalink
config/notifiers.go: fix opsgenieValidTypesRe (#1910)
Browse files Browse the repository at this point in the history
`^apple|banana|cherry$` finds matches to either of `^apple`, `banana`, or `cherry$`, so strings like `apple0`, `1banana2`, `3cherry` are accepted; I believe this wasn't intentional.

Signed-off-by: NODA, Kai <nodakai@gmail.com>
  • Loading branch information
nodakai authored and simonpasquier committed Jun 17, 2019
1 parent f1664ac commit fe4760c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ type OpsGenieConfig struct {
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
}

const opsgenieValidTypesRe = `^team|user|escalation|schedule$`
const opsgenieValidTypesRe = `^(team|user|escalation|schedule)$`

var opsgenieTypeMatcher = regexp.MustCompile(opsgenieValidTypesRe)

Expand Down
15 changes: 15 additions & 0 deletions config/notifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ actions:
}
}

func TestOpsgenieTypeMatcher(t *testing.T) {
good := []string{"team", "user", "escalation", "schedule"}
for _, g := range good {
if !opsgenieTypeMatcher.MatchString(g) {
t.Fatalf("failed to match with %s", g)
}
}
bad := []string{"0user", "team1", "2escalation3", "sche4dule", "User", "TEAM"}
for _, b := range bad {
if opsgenieTypeMatcher.MatchString(b) {
t.Errorf("mistakenly match with %s", b)
}
}
}

func newBoolPointer(b bool) *bool {
return &b
}

0 comments on commit fe4760c

Please sign in to comment.