forked from GoogleCloudPlatform/k8s-config-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request GoogleCloudPlatform#2287 from jingyih/validate_gsa…
…_format Validate format of GoogleServiceAccount in CCC
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,3 +169,49 @@ func TestConfigConnectorContextChecker(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestValidateGSAFormat(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
gsa string | ||
err error | ||
}{ | ||
{ | ||
name: "empty", | ||
gsa: "", | ||
err: nil, | ||
}, | ||
{ | ||
name: "valid GSA format", | ||
gsa: "[email protected]", | ||
err: nil, | ||
}, | ||
{ | ||
name: "valid GSA format", | ||
gsa: "[email protected]", | ||
err: nil, | ||
}, | ||
{ | ||
name: "valid GSA format", | ||
gsa: "[email protected]", | ||
err: nil, | ||
}, | ||
{ | ||
name: "invalid GSA format", | ||
gsa: "abc", | ||
err: fmt.Errorf("invalid GoogleServiceAccount format for %q", "abc"), | ||
}, | ||
{ | ||
name: "invalid GSA format", | ||
gsa: "[email protected]", | ||
err: fmt.Errorf("invalid GoogleServiceAccount format for %q", "[email protected]"), | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := validateGSAFormat(tc.gsa) | ||
asserts.AssertErrorIsExpected(t, err, tc.err) | ||
}) | ||
} | ||
} |