Run fixer

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar
2020-11-03 20:50:09 +01:00
parent 84ea790885
commit 349832b380
13 changed files with 71 additions and 56 deletions

View File

@@ -35,8 +35,10 @@ const (
// Pagination URL patterns
// https://developer.github.com/v3/#pagination
var reNext = regexp.MustCompile("<([^>]+)>; rel=\"next\"")
var reLast = regexp.MustCompile("<([^>]+)>; rel=\"last\"")
var (
reNext = regexp.MustCompile("<([^>]+)>; rel=\"next\"")
reLast = regexp.MustCompile("<([^>]+)>; rel=\"last\"")
)
// Config holds configuration options for github logins.
type Config struct {
@@ -626,7 +628,6 @@ func (c *githubConnector) userInOrg(ctx context.Context, client *http.Client, us
apiURL := fmt.Sprintf("%s/orgs/%s/members/%s", c.apiURL, orgName, userName)
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return false, fmt.Errorf("github: new req: %v", err)
}

View File

@@ -115,7 +115,8 @@ func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error)
c.Host,
c.AdminUsername,
c.AdminPassword,
logger}, nil
logger,
}, nil
}
func (p *conn) Close() error { return nil }
@@ -137,7 +138,7 @@ func (p *conn) Login(ctx context.Context, scopes connector.Scopes, username, pas
return identity, false, err
}
defer resp.Body.Close()
var tokenResp = new(tokenResponse)
tokenResp := new(tokenResponse)
err = json.Unmarshal(data, &tokenResp)
if err != nil {
return identity, false, fmt.Errorf("keystone: invalid token response: %v", err)
@@ -295,7 +296,7 @@ func (p *conn) getUserGroups(ctx context.Context, userID string, token string) (
}
defer resp.Body.Close()
var groupsResp = new(groupsResponse)
groupsResp := new(groupsResponse)
err = json.Unmarshal(data, &groupsResp)
if err != nil {

View File

@@ -84,7 +84,7 @@ func getAdminToken(t *testing.T, adminName, adminPass string) (token, id string)
}
defer resp.Body.Close()
var tokenResp = new(tokenResponse)
tokenResp := new(tokenResponse)
err = json.Unmarshal(data, &tokenResp)
if err != nil {
t.Fatal(err)
@@ -128,7 +128,7 @@ func createUser(t *testing.T, token, userName, userEmail, userPass string) strin
}
defer resp.Body.Close()
var userResp = new(userResponse)
userResp := new(userResponse)
err = json.Unmarshal(data, &userResp)
if err != nil {
t.Fatal(err)
@@ -189,7 +189,7 @@ func createGroup(t *testing.T, token, description, name string) string {
}
defer resp.Body.Close()
var groupResp = new(groupResponse)
groupResp := new(groupResponse)
err = json.Unmarshal(data, &groupResp)
if err != nil {
t.Fatal(err)
@@ -219,8 +219,10 @@ func addUserToGroup(t *testing.T, token, groupID, userID string) error {
func TestIncorrectCredentialsLogin(t *testing.T) {
setupVariables(t)
c := conn{Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass}
c := conn{
Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass,
}
s := connector.Scopes{OfflineAccess: true, Groups: true}
_, validPW, err := c.Login(context.Background(), s, adminUser, invalidPass)
@@ -254,7 +256,7 @@ func TestValidUserLogin(t *testing.T) {
verifiedEmail bool
}
var tests = []struct {
tests := []struct {
name string
input tUser
expected expect
@@ -294,8 +296,10 @@ func TestValidUserLogin(t *testing.T) {
userID := createUser(t, token, tt.input.username, tt.input.email, tt.input.password)
defer deleteResource(t, token, userID, usersURL)
c := conn{Host: keystoneURL, Domain: tt.input.domain,
AdminUsername: adminUser, AdminPassword: adminPass}
c := conn{
Host: keystoneURL, Domain: tt.input.domain,
AdminUsername: adminUser, AdminPassword: adminPass,
}
s := connector.Scopes{OfflineAccess: true, Groups: true}
identity, validPW, err := c.Login(context.Background(), s, tt.input.username, tt.input.password)
if err != nil {
@@ -329,8 +333,10 @@ func TestUseRefreshToken(t *testing.T) {
addUserToGroup(t, token, groupID, adminID)
defer deleteResource(t, token, groupID, groupsURL)
c := conn{Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass}
c := conn{
Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass,
}
s := connector.Scopes{OfflineAccess: true, Groups: true}
identityLogin, _, err := c.Login(context.Background(), s, adminUser, adminPass)
@@ -352,8 +358,10 @@ func TestUseRefreshTokenUserDeleted(t *testing.T) {
token, _ := getAdminToken(t, adminUser, adminPass)
userID := createUser(t, token, testUser, testEmail, testPass)
c := conn{Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass}
c := conn{
Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass,
}
s := connector.Scopes{OfflineAccess: true, Groups: true}
identityLogin, _, err := c.Login(context.Background(), s, testUser, testPass)
@@ -380,8 +388,10 @@ func TestUseRefreshTokenGroupsChanged(t *testing.T) {
userID := createUser(t, token, testUser, testEmail, testPass)
defer deleteResource(t, token, userID, usersURL)
c := conn{Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass}
c := conn{
Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass,
}
s := connector.Scopes{OfflineAccess: true, Groups: true}
identityLogin, _, err := c.Login(context.Background(), s, testUser, testPass)
@@ -414,8 +424,10 @@ func TestNoGroupsInScope(t *testing.T) {
userID := createUser(t, token, testUser, testEmail, testPass)
defer deleteResource(t, token, userID, usersURL)
c := conn{Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass}
c := conn{
Host: keystoneURL, Domain: testDomain,
AdminUsername: adminUser, AdminPassword: adminPass,
}
s := connector.Scopes{OfflineAccess: true, Groups: false}
groupID := createGroup(t, token, "Test group", testGroup)

View File

@@ -12,13 +12,12 @@ import (
"strings"
"time"
"golang.org/x/oauth2"
"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/groups"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage/kubernetes/k8sapi"
"golang.org/x/oauth2"
)
// Config holds configuration options for OpenShift login
@@ -32,9 +31,7 @@ type Config struct {
RootCA string `json:"rootCA"`
}
var (
_ connector.CallbackConnector = (*openshiftConnector)(nil)
)
var _ connector.CallbackConnector = (*openshiftConnector)(nil)
type openshiftConnector struct {
apiURL string
@@ -89,7 +86,6 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
}
resp, err := openshiftConnector.httpClient.Do(req.WithContext(ctx))
if err != nil {
cancel()
return nil, fmt.Errorf("failed to query OpenShift endpoint %v", err)
@@ -160,7 +156,6 @@ func (c *openshiftConnector) HandleCallback(s connector.Scopes, r *http.Request)
client := c.oauth2Config.Client(ctx, token)
user, err := c.user(ctx, client)
if err != nil {
return identity, fmt.Errorf("openshift: get user: %v", err)
}

View File

@@ -10,12 +10,11 @@ import (
"reflect"
"testing"
"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/storage/kubernetes/k8sapi"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2"
"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/storage/kubernetes/k8sapi"
)
func TestOpen(t *testing.T) {