-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2911: adjust code after code review, add more test coverage
Signed-off-by: Viacheslav Sychov <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
5 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 |
---|---|---|
|
@@ -102,7 +102,7 @@ func TestOpen(t *testing.T) { | |
Scopes: []string{"openid", "groups"}, | ||
ServiceAccountFilePath: serviceAccountFilePath, | ||
}, | ||
expectedErr: "requires adminEmail", | ||
expectedErr: "requires the domainToAdminEmail", | ||
}, | ||
"service_account_key_not_found": { | ||
config: &Config{ | ||
|
@@ -236,3 +236,58 @@ func TestGetGroups(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestDomainToAdminEmailConfig(t *testing.T) { | ||
ts := testSetup() | ||
defer ts.Close() | ||
|
||
serviceAccountFilePath, err := tempServiceAccountKey() | ||
assert.Nil(t, err) | ||
|
||
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountFilePath) | ||
conn, err := newConnector(&Config{ | ||
ClientID: "testClient", | ||
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
DomainToAdminEmail: map[string]string{"dexidp.com": "[email protected]"}, | ||
}) | ||
assert.Nil(t, err) | ||
|
||
conn.adminSrv["dexidp.com"], err = admin.NewService(context.Background(), option.WithoutAuthentication(), option.WithEndpoint(ts.URL)) | ||
assert.Nil(t, err) | ||
type testCase struct { | ||
userKey string | ||
expectedErr string | ||
} | ||
|
||
for name, testCase := range map[string]testCase{ | ||
"correct_user_request": { | ||
userKey: "[email protected]", | ||
expectedErr: "", | ||
}, | ||
"wrong_user_request": { | ||
userKey: "[email protected]", | ||
expectedErr: "unable to find super admin email", | ||
}, | ||
"wrong_connector_response": { | ||
userKey: "user_1_foo.bar", | ||
expectedErr: "unable to find super admin email", | ||
}, | ||
} { | ||
testCase := testCase | ||
callCounter = map[string]int{} | ||
t.Run(name, func(t *testing.T) { | ||
assert := assert.New(t) | ||
lookup := make(map[string]struct{}) | ||
|
||
_, err := conn.getGroups(testCase.userKey, true, lookup) | ||
if testCase.expectedErr != "" { | ||
assert.ErrorContains(err, testCase.expectedErr) | ||
} else { | ||
assert.Nil(err) | ||
} | ||
t.Logf("[%s] Amount of API calls per userKey: %+v\n", t.Name(), callCounter) | ||
}) | ||
} | ||
} |