Enable unparam, prealloc, sqlclosecheck linters
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
This commit is contained in:
@@ -128,10 +128,7 @@ func (c *crowdConnector) Login(ctx context.Context, s connector.Scopes, username
|
||||
return connector.Identity{}, false, err
|
||||
}
|
||||
|
||||
if ident, err = c.identityFromCrowdUser(user); err != nil {
|
||||
return connector.Identity{}, false, err
|
||||
}
|
||||
|
||||
ident = c.identityFromCrowdUser(user)
|
||||
if s.Groups {
|
||||
userGroups, err := c.getGroups(ctx, client, s.Groups, ident.Username)
|
||||
if err != nil {
|
||||
@@ -165,10 +162,7 @@ func (c *crowdConnector) Refresh(ctx context.Context, s connector.Scopes, ident
|
||||
return ident, fmt.Errorf("crowd: get user %q: %v", data.Username, err)
|
||||
}
|
||||
|
||||
newIdent, err := c.identityFromCrowdUser(user)
|
||||
if err != nil {
|
||||
return ident, err
|
||||
}
|
||||
newIdent := c.identityFromCrowdUser(user)
|
||||
newIdent.ConnectorData = ident.ConnectorData
|
||||
|
||||
// If user exists, authenticate it to prolong sso session.
|
||||
@@ -366,7 +360,7 @@ func (c *crowdConnector) groups(ctx context.Context, client *http.Client, userna
|
||||
}
|
||||
|
||||
// identityFromCrowdUser converts crowdUser to Identity
|
||||
func (c *crowdConnector) identityFromCrowdUser(user crowdUser) (connector.Identity, error) {
|
||||
func (c *crowdConnector) identityFromCrowdUser(user crowdUser) connector.Identity {
|
||||
identity := connector.Identity{
|
||||
Username: user.Name,
|
||||
UserID: user.Key,
|
||||
@@ -387,7 +381,7 @@ func (c *crowdConnector) identityFromCrowdUser(user crowdUser) (connector.Identi
|
||||
}
|
||||
}
|
||||
|
||||
return identity, nil
|
||||
return identity
|
||||
}
|
||||
|
||||
// getGroups retrieves a list of user's groups and filters it
|
||||
|
@@ -71,9 +71,6 @@ func TestUserLoginFlow(t *testing.T) {
|
||||
expectEquals(t, user.Name, "testuser")
|
||||
expectEquals(t, user.Email, "testuser@example.com")
|
||||
|
||||
_, err = c.identityFromCrowdUser(user)
|
||||
expectNil(t, err)
|
||||
|
||||
err = c.authenticateUser(context.Background(), newClient(), "testuser")
|
||||
expectNil(t, err)
|
||||
|
||||
@@ -119,8 +116,7 @@ func TestIdentityFromCrowdUser(t *testing.T) {
|
||||
expectEquals(t, user.Email, "testuser@example.com")
|
||||
|
||||
// Test unconfigured behaviour
|
||||
i, err := c.identityFromCrowdUser(user)
|
||||
expectNil(t, err)
|
||||
i := c.identityFromCrowdUser(user)
|
||||
expectEquals(t, i.UserID, "12345")
|
||||
expectEquals(t, i.Username, "testuser")
|
||||
expectEquals(t, i.Email, "testuser@example.com")
|
||||
@@ -131,23 +127,19 @@ func TestIdentityFromCrowdUser(t *testing.T) {
|
||||
expectEquals(t, i.PreferredUsername, "")
|
||||
|
||||
c.Config.PreferredUsernameField = "key"
|
||||
i, err = c.identityFromCrowdUser(user)
|
||||
expectNil(t, err)
|
||||
i = c.identityFromCrowdUser(user)
|
||||
expectEquals(t, i.PreferredUsername, "12345")
|
||||
|
||||
c.Config.PreferredUsernameField = "name"
|
||||
i, err = c.identityFromCrowdUser(user)
|
||||
expectNil(t, err)
|
||||
i = c.identityFromCrowdUser(user)
|
||||
expectEquals(t, i.PreferredUsername, "testuser")
|
||||
|
||||
c.Config.PreferredUsernameField = "email"
|
||||
i, err = c.identityFromCrowdUser(user)
|
||||
expectNil(t, err)
|
||||
i = c.identityFromCrowdUser(user)
|
||||
expectEquals(t, i.PreferredUsername, "testuser@example.com")
|
||||
|
||||
c.Config.PreferredUsernameField = "invalidstring"
|
||||
i, err = c.identityFromCrowdUser(user)
|
||||
expectNil(t, err)
|
||||
i = c.identityFromCrowdUser(user)
|
||||
expectEquals(t, i.PreferredUsername, "")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user