Skip to content

Commit

Permalink
Fix broken tests and ci linter issues (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Nov 4, 2019
1 parent 063b767 commit 69760fe
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
format:
lint:
docker:
- image: circleci/golang:1.13
environment:
Expand All @@ -20,7 +20,7 @@ jobs:
key: go-mod-v1-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.20.1
- run: make lint

test:
Expand Down Expand Up @@ -70,7 +70,7 @@ workflows:
version: 2
"test":
jobs:
- format:
- lint:
filters:
tags:
only: /.*/
Expand Down
1 change: 0 additions & 1 deletion driver/registry_abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type RegistryAbstract struct {
identityHandler *identity.Handler
identityValidator *identity.Validator
sessionHandler *session.Handler
errorManager errorx.Manager
errorHandler *errorx.Handler
passwordHasher password2.Hasher
passwordValidator password2.Validator
Expand Down
1 change: 1 addition & 0 deletions driver/registry_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func init() {
type RegistryMemory struct {
*RegistryAbstract

errorManager errorx.Manager
identityPool identity.Pool
sessionManager session.Manager
selfserviceRequestManager selfservice.RequestManager
Expand Down
1 change: 1 addition & 0 deletions driver/registry_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func init() {
type RegistrySQL struct {
*RegistryAbstract

errorManager errorx.Manager
identityPool identity.Pool
sessionManager session.Manager
selfserviceRequestManager selfservice.RequestManager
Expand Down
5 changes: 5 additions & 0 deletions identity/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import (

"github.com/stretchr/testify/assert"

"github.com/ory/viper"

"github.com/ory/x/sqlcon/dockertest"

"github.com/ory/herodot"

"github.com/stretchr/testify/require"

"github.com/ory/hive/driver/configuration"
. "github.com/ory/hive/identity"
"github.com/ory/hive/internal"
)
Expand Down Expand Up @@ -52,6 +55,8 @@ func TestPool(t *testing.T) {
})
}

viper.Set(configuration.ViperKeyDefaultIdentityTraitsSchemaURL, "file://./stub/identity.schema.json")

var newid = func(schemaURL string, credentialsID string) *Identity {
i := NewIdentity(schemaURL)
i.SetCredentials(CredentialsTypePassword, Credentials{
Expand Down
4 changes: 2 additions & 2 deletions selfservice/oidc/provider_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

func TestConfig(t *testing.T) {
viper.Set(configuration.ViperKeySelfServiceStrategyConfig+"."+string(identity.CredentialsTypeOIDC), json.RawMessage(`{"config":{"providers": [{"provider": "generic"}]}}`))

conf, reg := internal.NewMemoryRegistry(t)

viper.Set(configuration.ViperKeySelfServiceStrategyConfig+"."+string(identity.CredentialsTypeOIDC), json.RawMessage(`{"config":{"providers": [{"provider": "generic"}]}}`))
s := NewStrategy(reg, conf)

collection, err := s.Config()
Expand Down
31 changes: 15 additions & 16 deletions selfservice/oidc/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"strings"

"github.com/coreos/go-oidc"
"github.com/google/uuid"
"github.com/julienschmidt/httprouter"
"github.com/justinas/nosurf"
Expand Down Expand Up @@ -403,21 +402,21 @@ func (s *Strategy) processRegistration(w http.ResponseWriter, r *http.Request, a
return nil
}

func (s *Strategy) verifyIdentity(i *identity.Identity, c identity.Credentials, token oidc.IDToken, pid string) error {
var o CredentialsConfig

if err := json.NewDecoder(bytes.NewBuffer(c.Config)).Decode(&o); err != nil {
return errors.WithStack(herodot.ErrInternalServerError.WithReason("The password credentials could not be decoded properly").WithDebug(err.Error()))
}

if o.Subject != token.Subject {
return errors.WithStack(herodot.ErrInternalServerError.WithReason("The subjects do not match").WithDebugf("Expected credential subject to match subject from RequestID Token but values are not equal: %s != %s", o.Subject, token.Subject))
} else if o.Provider != pid {
return errors.WithStack(herodot.ErrInternalServerError.WithReason("The providers do not match").WithDebugf("Expected credential provider to match provider from path but values are not equal: %s != %s", o.Subject, pid))
}

return nil
}
// func (s *Strategy) verifyIdentity(i *identity.Identity, c identity.Credentials, token oidc.IDToken, pid string) error {
// var o CredentialsConfig
//
// if err := json.NewDecoder(bytes.NewBuffer(c.Config)).Decode(&o); err != nil {
// return errors.WithStack(herodot.ErrInternalServerError.WithReason("The password credentials could not be decoded properly").WithDebug(err.Error()))
// }
//
// if o.Subject != token.Subject {
// return errors.WithStack(herodot.ErrInternalServerError.WithReason("The subjects do not match").WithDebugf("Expected credential subject to match subject from RequestID Token but values are not equal: %s != %s", o.Subject, token.Subject))
// } else if o.Provider != pid {
// return errors.WithStack(herodot.ErrInternalServerError.WithReason("The providers do not match").WithDebugf("Expected credential provider to match provider from path but values are not equal: %s != %s", o.Subject, pid))
// }
//
// return nil
// }

func (s *Strategy) populateMethod(r *http.Request, request string) (*RequestMethodConfig, error) {
conf, err := s.Config()
Expand Down
8 changes: 4 additions & 4 deletions selfservice/password/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ func TestLogin(t *testing.T) {
return "anti-rf-token"
})

if tc.prep != nil {
tc.prep(t, reg)
}

router := x.NewRouterPublic()
s.SetRoutes(router)
ts := httptest.NewServer(router)
Expand All @@ -377,6 +373,10 @@ func TestLogin(t *testing.T) {
viper.Set(configuration.ViperKeySelfServiceLoginAfterConfig+"."+string(identity.CredentialsTypePassword), hookConfig(returnTs.URL+"/return-ts"))
viper.Set(configuration.ViperKeyDefaultIdentityTraitsSchemaURL, "file://./stub/login.schema.json")

if tc.prep != nil {
tc.prep(t, reg)
}

tc.ar.RequestURL = ts.URL
require.NoError(t, reg.LoginRequestManager().CreateLoginRequest(context.TODO(), tc.ar))

Expand Down

0 comments on commit 69760fe

Please sign in to comment.