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, "")
|
||||
}
|
||||
|
||||
|
@@ -421,7 +421,6 @@ type group struct {
|
||||
}
|
||||
|
||||
func (b *bitbucketConnector) userTeamGroups(ctx context.Context, client *http.Client, teamName string) ([]string, error) {
|
||||
var teamGroups []string
|
||||
apiURL := b.legacyAPIURL + "/groups/" + teamName
|
||||
|
||||
var response []group
|
||||
@@ -429,6 +428,7 @@ func (b *bitbucketConnector) userTeamGroups(ctx context.Context, client *http.Cl
|
||||
return nil, fmt.Errorf("get user team %q groups: %v", teamName, err)
|
||||
}
|
||||
|
||||
teamGroups := make([]string, 0, len(response))
|
||||
for _, group := range response {
|
||||
teamGroups = append(teamGroups, teamName+"/"+group.Slug)
|
||||
}
|
||||
|
@@ -72,7 +72,7 @@ type giteaConnector struct {
|
||||
useLoginAsID bool
|
||||
}
|
||||
|
||||
func (c *giteaConnector) oauth2Config(scopes connector.Scopes) *oauth2.Config {
|
||||
func (c *giteaConnector) oauth2Config(_ connector.Scopes) *oauth2.Config {
|
||||
giteaEndpoint := oauth2.Endpoint{AuthURL: c.baseURL + "/login/oauth/authorize", TokenURL: c.baseURL + "/login/oauth/access_token"}
|
||||
return &oauth2.Config{
|
||||
ClientID: c.clientID,
|
||||
|
@@ -609,7 +609,7 @@ func (c *ldapConnector) groups(ctx context.Context, user ldap.Entry) ([]string,
|
||||
}
|
||||
}
|
||||
|
||||
var groupNames []string
|
||||
groupNames := make([]string, 0, len(groups))
|
||||
for _, group := range groups {
|
||||
name := getAttr(*group, c.GroupSearch.NameAttr)
|
||||
if name == "" {
|
||||
|
@@ -488,7 +488,7 @@ func (p *provider) validateSubject(subject *subject, inResponseTo string) error
|
||||
return fmt.Errorf("subject contained no SubjectConfirmations")
|
||||
}
|
||||
|
||||
var errs []error
|
||||
errs := make([]error, 0, len(subject.SubjectConfirmations))
|
||||
// One of these must match our assumptions, not all.
|
||||
for _, c := range subject.SubjectConfirmations {
|
||||
err := func() error {
|
||||
|
Reference in New Issue
Block a user