Skip to content

Commit

Permalink
Fixup bad tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Apr 18, 2024
1 parent e94a3ed commit 9c7109a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func ParseToken(token *jwt.Token) (interface{}, error) {
jwksUri := os.Getenv("JWKS_URI")
jwksSet, err := jwk.Fetch(ctx, jwksUri)
if err != nil {
return nil, fmt.Errorf("Unable to fetch JWK set from %s: %v", jwksUri, err)
return nil, fmt.Errorf("unable to fetch JWK set from %s: %v", jwksUri, err)
}
// Find the appropriate key in JWKS
key, ok := jwksSet.LookupKeyID(kid)
Expand Down
58 changes: 23 additions & 35 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,46 +404,34 @@ func TestBadRolloutCmdArgs(t *testing.T) {
t.Fatalf("Unable to create a JWT with our test key: %v", err)
}

payloads := map[string]string{
"rollout-arg1": "bad1;",
"rollout-arg2": "bad2&",
"rollout-arg3": "bad3|",
"bad4": "bad4$",
"bad5": "any`thing",
"bad6": `any"thing`,
"bad7": "any\thing",
"bad8": "any*thing",
"bad9": "any?thing",
"bad10": "any[thing",
"bad11": "any]thing",
"bad12": "any{thing",
"bad13": "any}thing",
"bad14": "any(thing",
"bad15": "any)thing",
"bad16": "any<thing",
"bad17": "any>thing",
"bad18": "anything!",
payloads := []string{
`{"rollout-arg1": "bad1;"}`,
`{"rollout-arg1": "bad2&"}`,
`{"rollout-arg1": "bad3|"}`,
`{"rollout-arg1": "bad4$"}`,
"{\"rollout-arg1\": \"any`thing\"}",
`{"rollout-arg1": "any\"thing"}`,
`{"rollout-arg1": "any\thing"}`,
`{"rollout-arg1": "any*thing"}`,
`{"rollout-arg1": "any?thing"}`,
`{"rollout-arg1": "any[thing"}`,
`{"rollout-arg1": "any]thing"}`,
`{"rollout-arg1": "any{thing"}`,
`{"rollout-arg1": "any}thing"}`,
`{"rollout-arg1": "any(thing"}`,
`{"rollout-arg1": "any)thing"}`,
`{"rollout-arg1": "any<thing"}`,
`{"rollout-arg1": "any>thing"}`,
`{"rollout-arg1": "anything!"}`,
}
for k, v := range payloads {
var e string
switch k {
case "rollout-arg1":
e = "ROLLOUT_ARG1"
case "rollout-arg2":
e = "ROLLOUT_ARG2"
case "rollout-arg3":
e = "ROLLOUT_ARG3"
default:
k = "rollout-arg1"
e = "ROLLOUT_ARG1"
}
for _, payload := range payloads {
tt := Test{
name: fmt.Sprintf("%s custom arg doesn't pass to rollout.sh", k),
name: "Bad custom arg doesn't pass to rollout.sh",
authHeader: "Bearer " + jwtToken,
expectedStatus: http.StatusBadRequest,
cmdArgs: fmt.Sprintf(`-c "touch /tmp/$%s"`, e),
cmdArgs: `-c "touch /tmp/$ROLLOUT_ARG1"`,
method: "POST",
payload: fmt.Sprintf(`{"%s": "%s"}`, k, v),
payload: payload,
expectedBody: "Bad request\n",
}
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 9c7109a

Please sign in to comment.