Skip to content

Commit

Permalink
feat(validation) add validation for mtls-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Raines committed Mar 4, 2021
1 parent 038c811 commit 60c106a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/admission/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var (
basicAuthFields = []string{"username", "password"}
hmacAuthFields = []string{"username", "secret"}
jwtAuthFields = []string{"algorithm", "rsa_public_key", "key", "secret"}
mtlsAuthFields = []string{"subject_name"}

// TODO dynamically fetch these from Kong
credTypeToFields = map[string][]string{
Expand All @@ -121,6 +122,7 @@ var (
"jwt_secret": jwtAuthFields,
"oauth2": {"name", "client_id", "client_secret", "redirect_uris"},
"acl": {"group"},
"mtls-auth": mtlsAuthFields,
}
)

Expand Down
27 changes: 27 additions & 0 deletions internal/admission/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,33 @@ func TestKongHTTPValidator_ValidateCredential(t *testing.T) {
wantMessage: "missing required field(s): key",
wantErr: false,
},
{
name: "valid mtls-auth credential",
args: args{
secret: corev1.Secret{
Data: map[string][]byte{
"subject_name": []byte("foo"),
"kongCredType": []byte("mtls-auth"),
},
},
},
wantOK: true,
wantMessage: "",
wantErr: false,
},
{
name: "invalid mtls-auth credential",
args: args{
secret: corev1.Secret{
Data: map[string][]byte{
"kongCredType": []byte("mtls-auth"),
},
},
},
wantOK: false,
wantMessage: "missing required field(s): subject_name",
wantErr: false,
},
{
name: "invalid credential type",
args: args{
Expand Down

0 comments on commit 60c106a

Please sign in to comment.