Skip to content

Commit

Permalink
Merge pull request #1604 from dexidp/fix-linters
Browse files Browse the repository at this point in the history
Fix linters
  • Loading branch information
Nándor István Krácser authored Dec 20, 2019
2 parents ff4dee5 + 050d5af commit a901e2f
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 113 deletions.
10 changes: 0 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,11 @@ linters:
- wsl

# TODO: fix me
- unused
- structcheck
- stylecheck
- deadcode
- misspell
- unparam
- goimports
- golint
- whitespace
- goconst
- unconvert
- bodyclose
- staticcheck
- nakedret
- ineffassign
- errcheck
- gosec
- gochecknoinits
Expand Down
3 changes: 1 addition & 2 deletions cmd/dex/config_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"github.com/dexidp/dex/server"
"testing"

"github.com/ghodss/yaml"
"github.com/kylelemons/godebug/pretty"

"github.com/dexidp/dex/connector/mock"
"github.com/dexidp/dex/connector/oidc"
"github.com/dexidp/dex/server"
"github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/sql"
)
Expand Down Expand Up @@ -211,5 +211,4 @@ logger:
if diff := pretty.Compare(c, want); diff != "" {
t.Errorf("got!=want: %s", diff)
}

}
1 change: 0 additions & 1 deletion cmd/dex/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func serve(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to initialize storage connectors: %v", err)
}
storageConnectors[i] = conn

}

if c.EnablePasswordDB {
Expand Down
4 changes: 2 additions & 2 deletions cmd/example-app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func cmd() *cobra.Command {
ctx := oidc.ClientContext(context.Background(), a.client)
provider, err := oidc.NewProvider(ctx, issuerURL)
if err != nil {
return fmt.Errorf("Failed to query provider %q: %v", issuerURL, err)
return fmt.Errorf("failed to query provider %q: %v", issuerURL, err)
}

var s struct {
Expand All @@ -153,7 +153,7 @@ func cmd() *cobra.Command {
ScopesSupported []string `json:"scopes_supported"`
}
if err := provider.Claims(&s); err != nil {
return fmt.Errorf("Failed to parse provider scopes_supported: %v", err)
return fmt.Errorf("failed to parse provider scopes_supported: %v", err)
}

if len(s.ScopesSupported) == 0 {
Expand Down
2 changes: 0 additions & 2 deletions connector/bitbucketcloud/bitbucketcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Config struct {

// Open returns a strategy for logging in through Bitbucket.
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {

b := bitbucketConnector{
redirectURI: c.RedirectURI,
teams: c.Teams,
Expand Down Expand Up @@ -373,7 +372,6 @@ type userTeamsResponse struct {
}

func (b *bitbucketConnector) userTeams(ctx context.Context, client *http.Client) ([]string, error) {

var teams []string
apiURL := b.apiURL + "/teams?role=member"

Expand Down
3 changes: 0 additions & 3 deletions connector/bitbucketcloud/bitbucketcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func TestUserGroups(t *testing.T) {

teamsResponse := userTeamsResponse{
pagedResponse: pagedResponse{
Size: 3,
Expand Down Expand Up @@ -46,7 +45,6 @@ func TestUserGroups(t *testing.T) {
}

func TestUserWithoutTeams(t *testing.T) {

s := newTestServer(map[string]interface{}{
"/teams?role=member": userTeamsResponse{},
})
Expand All @@ -61,7 +59,6 @@ func TestUserWithoutTeams(t *testing.T) {
}

func TestUsernameIncludedInFederatedIdentity(t *testing.T) {

s := newTestServer(map[string]interface{}{
"/user": user{Username: "some-login"},
"/user/emails": userEmailResponse{
Expand Down
6 changes: 2 additions & 4 deletions connector/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type Org struct {

// Open returns a strategy for logging in through GitHub.
func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {

if c.Org != "" {
// Return error if both 'org' and 'orgs' fields are used.
if len(c.Orgs) > 0 {
Expand Down Expand Up @@ -107,7 +106,6 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
if g.httpClient, err = newHTTPClient(g.rootCA); err != nil {
return nil, fmt.Errorf("failed to create HTTP client: %v", err)
}

}
g.loadAllGroups = c.LoadAllGroups

Expand Down Expand Up @@ -144,7 +142,7 @@ type githubConnector struct {
hostName string
// Used to support untrusted/self-signed CA certs.
rootCA string
// HTTP Client that trusts the custom delcared rootCA cert.
// HTTP Client that trusts the custom declared rootCA cert.
httpClient *http.Client
// optional choice between 'name' (default) or 'slug'
teamNameField string
Expand Down Expand Up @@ -206,7 +204,7 @@ func (e *oauth2Error) Error() string {
return e.error + ": " + e.errorDescription
}

// newHTTPClient returns a new HTTP client that trusts the custom delcared rootCA cert.
// newHTTPClient returns a new HTTP client that trusts the custom declared rootCA cert.
func newHTTPClient(rootCA string) (*http.Client, error) {
tlsConfig := tls.Config{RootCAs: x509.NewCertPool()}
rootCABytes, err := ioutil.ReadFile(rootCA)
Expand Down
2 changes: 0 additions & 2 deletions connector/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func TestUserGroupsWithTeamNameAndSlugFieldConfig(t *testing.T) {

// tests that the users login is used as their username when they have no username set
func TestUsernameIncludedInFederatedIdentity(t *testing.T) {

s := newTestServer(map[string]testResponse{
"/user": {data: user{Login: "some-login", ID: 12345678}},
"/user/emails": {data: []userEmail{{
Expand Down Expand Up @@ -168,7 +167,6 @@ func TestUsernameIncludedInFederatedIdentity(t *testing.T) {
}

func TestLoginUsedAsIDWhenConfigured(t *testing.T) {

s := newTestServer(map[string]testResponse{
"/user": {data: user{Login: "some-login", ID: 12345678, Name: "Joe Bloggs"}},
"/user/emails": {data: []userEmail{{
Expand Down
4 changes: 0 additions & 4 deletions connector/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestUserGroupsWithoutOrgs(t *testing.T) {

// tests that the email is used as their username when they have no username set
func TestUsernameIncludedInFederatedIdentity(t *testing.T) {

s := newTestServer(map[string]interface{}{
"/api/v4/user": gitlabUser{Email: "[email protected]", ID: 12345678},
"/oauth/token": map[string]interface{}{
Expand Down Expand Up @@ -102,7 +101,6 @@ func TestUsernameIncludedInFederatedIdentity(t *testing.T) {
}

func TestLoginUsedAsIDWhenConfigured(t *testing.T) {

s := newTestServer(map[string]interface{}{
"/api/v4/user": gitlabUser{Email: "[email protected]", ID: 12345678, Name: "Joe Bloggs", Username: "joebloggs"},
"/oauth/token": map[string]interface{}{
Expand Down Expand Up @@ -130,7 +128,6 @@ func TestLoginUsedAsIDWhenConfigured(t *testing.T) {
}

func TestLoginWithTeamWhitelisted(t *testing.T) {

s := newTestServer(map[string]interface{}{
"/api/v4/user": gitlabUser{Email: "[email protected]", ID: 12345678, Name: "Joe Bloggs"},
"/oauth/token": map[string]interface{}{
Expand Down Expand Up @@ -158,7 +155,6 @@ func TestLoginWithTeamWhitelisted(t *testing.T) {
}

func TestLoginWithTeamNonWhitelisted(t *testing.T) {

s := newTestServer(map[string]interface{}{
"/api/v4/user": gitlabUser{Email: "[email protected]", ID: 12345678, Name: "Joe Bloggs", Username: "joebloggs"},
"/oauth/token": map[string]interface{}{
Expand Down
5 changes: 2 additions & 3 deletions connector/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

"github.com/coreos/go-oidc"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
admin "google.golang.org/api/admin/directory/v1"

"github.com/dexidp/dex/connector"
pkg_groups "github.com/dexidp/dex/pkg/groups"
"github.com/dexidp/dex/pkg/log"
"golang.org/x/oauth2/google"
admin "google.golang.org/api/admin/directory/v1"
)

const (
Expand Down Expand Up @@ -105,7 +105,6 @@ type googleConnector struct {
redirectURI string
oauth2Config *oauth2.Config
verifier *oidc.IDTokenVerifier
ctx context.Context
cancel context.CancelFunc
logger log.Logger
hostedDomains []string
Expand Down
4 changes: 3 additions & 1 deletion connector/keystone/keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func (p *conn) Prompt() string { return "username" }

func (p *conn) Refresh(
ctx context.Context, scopes connector.Scopes, identity connector.Identity) (connector.Identity, error) {

token, err := p.getAdminToken(ctx)
if err != nil {
return identity, fmt.Errorf("keystone: failed to obtain admin token: %v", err)
Expand Down Expand Up @@ -210,6 +209,8 @@ func (p *conn) getAdminToken(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()

token := resp.Header.Get("X-Subject-Token")
return token, nil
}
Expand All @@ -229,6 +230,7 @@ func (p *conn) checkIfUserExists(ctx context.Context, userID string, token strin
if err != nil {
return false, err
}
defer resp.Body.Close()

if resp.StatusCode == 200 {
return true, nil
Expand Down
17 changes: 14 additions & 3 deletions connector/keystone/keystone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ func delete(t *testing.T, token, id, uri string) {
t.Fatalf("error: %v", err)
}
req.Header.Set("X-Auth-Token", token)
client.Do(req)

resp, err := client.Do(req)
if err != nil {
t.Fatalf("error: %v", err)
}
defer resp.Body.Close()
}

func createGroup(t *testing.T, token, description, name string) string {
Expand Down Expand Up @@ -208,7 +213,13 @@ func addUserToGroup(t *testing.T, token, groupID, userID string) error {
return err
}
req.Header.Set("X-Auth-Token", token)
client.Do(req)

resp, err := client.Do(req)
if err != nil {
t.Fatalf("error: %v", err)
}
defer resp.Body.Close()

return nil
}

Expand Down Expand Up @@ -274,7 +285,7 @@ func TestUseRefreshToken(t *testing.T) {
delete(t, token, groupID, groupsURL)

expectEquals(t, 1, len(identityRefresh.Groups))
expectEquals(t, testGroup, string(identityRefresh.Groups[0]))
expectEquals(t, testGroup, identityRefresh.Groups[0])
}

func TestUseRefreshTokenUserDeleted(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions connector/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func (c *Config) OpenConnector(logger log.Logger) (interface {
}

func (c *Config) openConnector(logger log.Logger) (*ldapConnector, error) {

requiredFields := []struct {
name string
val string
Expand Down Expand Up @@ -365,7 +364,6 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
}

func (c *ldapConnector) userEntry(conn *ldap.Conn, username string) (user ldap.Entry, found bool, err error) {

filter := fmt.Sprintf("(%s=%s)", c.UserSearch.Username, ldap.EscapeFilter(username))
if c.UserSearch.Filter != "" {
filter = fmt.Sprintf("(&%s%s)", c.UserSearch.Filter, filter)
Expand Down
3 changes: 2 additions & 1 deletion connector/oidc/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
"testing"
"time"

"github.com/dexidp/dex/connector"
"github.com/sirupsen/logrus"
"gopkg.in/square/go-jose.v2"

"github.com/dexidp/dex/connector"
)

func TestKnownBrokenAuthHeaderProvider(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions connector/saml/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"time"

"github.com/beevik/etree"
dsig "github.com/russellhaering/goxmldsig"
"github.com/russellhaering/goxmldsig/etreeutils"

"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/groups"
"github.com/dexidp/dex/pkg/log"
dsig "github.com/russellhaering/goxmldsig"
"github.com/russellhaering/goxmldsig/etreeutils"
)

// nolint
Expand Down Expand Up @@ -248,7 +249,6 @@ type provider struct {
}

func (p *provider) POSTData(s connector.Scopes, id string) (action, value string, err error) {

r := &authnRequest{
ProtocolBinding: bindingPOST,
ID: id,
Expand Down Expand Up @@ -325,7 +325,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str

// Status is a required element.
if resp.Status == nil {
return ident, fmt.Errorf("Response did not contain a Status element")
return ident, fmt.Errorf("response did not contain a Status element")
}

if err = p.validateStatus(resp.Status); err != nil {
Expand Down Expand Up @@ -398,7 +398,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str

if len(p.allowedGroups) > 0 && (!s.Groups || p.groupsAttr == "") {
// allowedGroups set but no groups or groupsAttr. Disallowing.
return ident, fmt.Errorf("User not a member of allowed groups")
return ident, fmt.Errorf("user not a member of allowed groups")
}

// Grab the groups.
Expand Down Expand Up @@ -427,7 +427,7 @@ func (p *provider) HandlePOST(s connector.Scopes, samlResponse, inResponseTo str

if len(groupMatches) == 0 {
// No group membership matches found, disallowing
return ident, fmt.Errorf("User not a member of allowed groups")
return ident, fmt.Errorf("user not a member of allowed groups")
}

// Otherwise, we're good
Expand Down Expand Up @@ -468,7 +468,7 @@ func (p *provider) validateStatus(status *status) error {
func (p *provider) validateSubject(subject *subject, inResponseTo string) error {
// Optional according to the spec, but again, we're going to be strict here.
if len(subject.SubjectConfirmations) == 0 {
return fmt.Errorf("Subject contained no SubjectConfirmations")
return fmt.Errorf("subject contained no SubjectConfirmations")
}

var errs []error
Expand Down
2 changes: 0 additions & 2 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func (d dexAPI) DeletePassword(ctx context.Context, req *api.DeletePasswordReq)
return nil, fmt.Errorf("delete password: %v", err)
}
return &api.DeletePasswordResp{}, nil

}

func (d dexAPI) GetVersion(ctx context.Context, req *api.VersionReq) (*api.VersionResp, error) {
Expand Down Expand Up @@ -248,7 +247,6 @@ func (d dexAPI) ListPasswords(ctx context.Context, req *api.ListPasswordReq) (*a
return &api.ListPasswordResp{
Passwords: passwords,
}, nil

}

func (d dexAPI) VerifyPassword(ctx context.Context, req *api.VerifyPasswordReq) (*api.VerifyPasswordResp, error) {
Expand Down
2 changes: 0 additions & 2 deletions server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func TestPassword(t *testing.T) {
if _, err := client.DeletePassword(ctx, &deleteReq); err != nil {
t.Fatalf("Unable to delete password: %v", err)
}

}

// Ensures checkCost returns expected values
Expand Down Expand Up @@ -495,7 +494,6 @@ func TestUpdateClient(t *testing.T) {
if tc.cleanup != nil {
tc.cleanup(t, tc.req.Id)
}

})
}
}
Expand Down
Loading

0 comments on commit a901e2f

Please sign in to comment.