-
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.
Browse files
Browse the repository at this point in the history
…2911) Signed-off-by: Viacheslav Sychov <[email protected]>
- Loading branch information
Showing
2 changed files
with
141 additions
and
37 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,15 +102,15 @@ 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{ | ||
ClientID: "testClient", | ||
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
AdminEmail: "[email protected]", | ||
DomainToAdminEmail: map[string]string{"*": "[email protected]"}, | ||
ServiceAccountFilePath: "not_found.json", | ||
}, | ||
expectedErr: "error reading credentials", | ||
|
@@ -121,18 +121,18 @@ func TestOpen(t *testing.T) { | |
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
AdminEmail: "[email protected]", | ||
DomainToAdminEmail: map[string]string{"bar.com": "[email protected]"}, | ||
ServiceAccountFilePath: serviceAccountFilePath, | ||
}, | ||
expectedErr: "", | ||
}, | ||
"adc": { | ||
config: &Config{ | ||
ClientID: "testClient", | ||
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
AdminEmail: "[email protected]", | ||
ClientID: "testClient", | ||
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
DomainToAdminEmail: map[string]string{"*": "[email protected]"}, | ||
}, | ||
adc: serviceAccountFilePath, | ||
expectedErr: "", | ||
|
@@ -143,7 +143,7 @@ func TestOpen(t *testing.T) { | |
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
AdminEmail: "[email protected]", | ||
DomainToAdminEmail: map[string]string{"*": "[email protected]"}, | ||
ServiceAccountFilePath: serviceAccountFilePath, | ||
}, | ||
adc: "/dev/null", | ||
|
@@ -176,15 +176,15 @@ func TestGetGroups(t *testing.T) { | |
|
||
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountFilePath) | ||
conn, err := newConnector(&Config{ | ||
ClientID: "testClient", | ||
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
AdminEmail: "[email protected]", | ||
ClientID: "testClient", | ||
ClientSecret: "testSecret", | ||
RedirectURI: ts.URL + "/callback", | ||
Scopes: []string{"openid", "groups"}, | ||
DomainToAdminEmail: map[string]string{"*": "[email protected]"}, | ||
}) | ||
assert.Nil(t, err) | ||
|
||
conn.adminSrv, err = admin.NewService(context.Background(), option.WithoutAuthentication(), option.WithEndpoint(ts.URL)) | ||
conn.adminSrv[wildcardDomainToAdminEmail], err = admin.NewService(context.Background(), option.WithoutAuthentication(), option.WithEndpoint(ts.URL)) | ||
assert.Nil(t, err) | ||
type testCase struct { | ||
userKey string | ||
|
@@ -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) | ||
}) | ||
} | ||
} |