fix: check for no serviceAccountFilePath and no email (#2679)
Signed-off-by: Bob Callaway <bcallaway@google.com>
This commit is contained in:
parent
45b6f49674
commit
49477729ce
@ -71,11 +71,14 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
|
|||||||
scopes = append(scopes, "profile", "email")
|
scopes = append(scopes, "profile", "email")
|
||||||
}
|
}
|
||||||
|
|
||||||
srv, err := createDirectoryService(c.ServiceAccountFilePath, c.AdminEmail, logger)
|
var srv *admin.Service
|
||||||
|
if len(c.Groups) > 0 {
|
||||||
|
srv, err = createDirectoryService(c.ServiceAccountFilePath, c.AdminEmail, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return nil, fmt.Errorf("could not create directory service: %v", err)
|
return nil, fmt.Errorf("could not create directory service: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clientID := c.ClientID
|
clientID := c.ClientID
|
||||||
return &googleConnector{
|
return &googleConnector{
|
||||||
|
@ -72,12 +72,22 @@ func TestOpen(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
for name, reference := range map[string]testCase{
|
for name, reference := range map[string]testCase{
|
||||||
|
"not_requesting_groups": {
|
||||||
|
config: &Config{
|
||||||
|
ClientID: "testClient",
|
||||||
|
ClientSecret: "testSecret",
|
||||||
|
RedirectURI: ts.URL + "/callback",
|
||||||
|
Scopes: []string{"openid"},
|
||||||
|
},
|
||||||
|
expectedErr: "",
|
||||||
|
},
|
||||||
"missing_admin_email": {
|
"missing_admin_email": {
|
||||||
config: &Config{
|
config: &Config{
|
||||||
ClientID: "testClient",
|
ClientID: "testClient",
|
||||||
ClientSecret: "testSecret",
|
ClientSecret: "testSecret",
|
||||||
RedirectURI: ts.URL + "/callback",
|
RedirectURI: ts.URL + "/callback",
|
||||||
Scopes: []string{"openid", "groups"},
|
Scopes: []string{"openid", "groups"},
|
||||||
|
Groups: []string{"someGroup"},
|
||||||
},
|
},
|
||||||
expectedErr: "requires adminEmail",
|
expectedErr: "requires adminEmail",
|
||||||
},
|
},
|
||||||
@ -89,6 +99,7 @@ func TestOpen(t *testing.T) {
|
|||||||
Scopes: []string{"openid", "groups"},
|
Scopes: []string{"openid", "groups"},
|
||||||
AdminEmail: "foo@bar.com",
|
AdminEmail: "foo@bar.com",
|
||||||
ServiceAccountFilePath: "not_found.json",
|
ServiceAccountFilePath: "not_found.json",
|
||||||
|
Groups: []string{"someGroup"},
|
||||||
},
|
},
|
||||||
expectedErr: "error reading credentials",
|
expectedErr: "error reading credentials",
|
||||||
},
|
},
|
||||||
@ -100,6 +111,7 @@ func TestOpen(t *testing.T) {
|
|||||||
Scopes: []string{"openid", "groups"},
|
Scopes: []string{"openid", "groups"},
|
||||||
AdminEmail: "foo@bar.com",
|
AdminEmail: "foo@bar.com",
|
||||||
ServiceAccountFilePath: serviceAccountFilePath,
|
ServiceAccountFilePath: serviceAccountFilePath,
|
||||||
|
Groups: []string{"someGroup"},
|
||||||
},
|
},
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
@ -110,6 +122,7 @@ func TestOpen(t *testing.T) {
|
|||||||
RedirectURI: ts.URL + "/callback",
|
RedirectURI: ts.URL + "/callback",
|
||||||
Scopes: []string{"openid", "groups"},
|
Scopes: []string{"openid", "groups"},
|
||||||
AdminEmail: "foo@bar.com",
|
AdminEmail: "foo@bar.com",
|
||||||
|
Groups: []string{"someGroup"},
|
||||||
},
|
},
|
||||||
adc: serviceAccountFilePath,
|
adc: serviceAccountFilePath,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
@ -122,6 +135,7 @@ func TestOpen(t *testing.T) {
|
|||||||
Scopes: []string{"openid", "groups"},
|
Scopes: []string{"openid", "groups"},
|
||||||
AdminEmail: "foo@bar.com",
|
AdminEmail: "foo@bar.com",
|
||||||
ServiceAccountFilePath: serviceAccountFilePath,
|
ServiceAccountFilePath: serviceAccountFilePath,
|
||||||
|
Groups: []string{"someGroup"},
|
||||||
},
|
},
|
||||||
adc: "/dev/null",
|
adc: "/dev/null",
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
|
Reference in New Issue
Block a user