Merge pull request #100186 from yangjunmyfm192085/run-test28

test: fix the error case of TestAuthenticationValidate
This commit is contained in:
Kubernetes Prow Robot 2021-04-08 20:28:34 -07:00 committed by GitHub
commit 42a4953c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,19 @@ func TestAuthenticationValidate(t *testing.T) {
},
{
name: "test when OIDC and ServiceAccounts are valid",
testOIDC: &OIDCAuthenticationOptions{
UsernameClaim: "sub",
SigningAlgs: []string{"RS256"},
IssuerURL: "testIssuerURL",
ClientID: "testClientID",
},
testSA: &ServiceAccountAuthenticationOptions{
Issuer: "http://foo.bar.com",
KeyFiles: []string{"testkeyfile1", "testkeyfile2"},
},
},
{
name: "test when OIDC and ServiceAccounts are invalid",
testOIDC: &OIDCAuthenticationOptions{
UsernameClaim: "sub",
SigningAlgs: []string{"RS256"},
@ -52,6 +65,19 @@ func TestAuthenticationValidate(t *testing.T) {
testSA: &ServiceAccountAuthenticationOptions{
Issuer: "http://foo.bar.com",
},
expectErr: "oidc-issuer-url and oidc-client-id should be specified together",
},
{
name: "test when OIDC and ServiceAccounts are invalid",
testOIDC: &OIDCAuthenticationOptions{
UsernameClaim: "sub",
SigningAlgs: []string{"RS256"},
IssuerURL: "testIssuerURL",
},
testSA: &ServiceAccountAuthenticationOptions{
Issuer: "http://foo.bar.com",
},
expectErr: "service-account-key-file is a required flag",
},
{
name: "test when OIDC is invalid",
@ -61,7 +87,8 @@ func TestAuthenticationValidate(t *testing.T) {
IssuerURL: "testIssuerURL",
},
testSA: &ServiceAccountAuthenticationOptions{
Issuer: "http://foo.bar.com",
Issuer: "http://foo.bar.com",
KeyFiles: []string{"testkeyfile1", "testkeyfile2"},
},
expectErr: "oidc-issuer-url and oidc-client-id should be specified together",
},
@ -87,10 +114,9 @@ func TestAuthenticationValidate(t *testing.T) {
options.ServiceAccounts = testcase.testSA
errs := options.Validate()
if len(errs) > 0 && !strings.Contains(utilerrors.NewAggregate(errs).Error(), testcase.expectErr) {
if len(errs) > 0 && (!strings.Contains(utilerrors.NewAggregate(errs).Error(), testcase.expectErr) || testcase.expectErr == "") {
t.Errorf("Got err: %v, Expected err: %s", errs, testcase.expectErr)
}
if len(errs) == 0 && len(testcase.expectErr) != 0 {
t.Errorf("Got err nil, Expected err: %s", testcase.expectErr)
}