Skip to content

Commit

Permalink
identity: Resolve wrong column reference in sql (#90)
Browse files Browse the repository at this point in the history
Reference ic.method instead of ici.method.

Added regression tests against this particular issue.
  • Loading branch information
aeneasr committed Nov 4, 2019
1 parent 292702d commit 0c0eb87
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 2
jobs:
format:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.13
environment:
- GO111MODULE=on
working_directory: /go/src/github.com/ory/hive
Expand All @@ -25,7 +25,7 @@ jobs:

test:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.13
environment:
- GO111MODULE=on
- TEST_SELFSERVICE_OIDC_HYDRA_ADMIN=http://127.0.0.1:4445
Expand Down
2 changes: 1 addition & 1 deletion identity/pool_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewPoolSQL(c configuration.Provider, d ValidationProvider, db *sqlx.DB) *Po

// FindByCredentialsIdentifier returns an identity by querying for it's credential identifiers.
func (p *PoolSQL) FindByCredentialsIdentifier(ctx context.Context, ct CredentialsType, match string) (*Identity, *Credentials, error) {
i, err := p.get(ctx, "WHERE ici.identifier = ? AND ici.method = ?", []interface{}{match, string(ct)})
i, err := p.get(ctx, "WHERE ici.identifier = ? AND ic.method = ?", []interface{}{match, string(ct)})
if err != nil {
if errors.Cause(err).Error() == herodot.ErrNotFound.Error() {
return nil, nil, herodot.ErrNotFound.WithTrace(err).WithReasonf(`No identity matching credentials identifier "%s" could be found.`, match)
Expand Down
19 changes: 19 additions & 0 deletions identity/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ func TestPool(t *testing.T) {
assert.Equal(t, "id-2", is[1].ID)
})

t.Run("case=find identity by its credentials identifier", func(t *testing.T) {
expected := newid("file://./stub/identity.schema.json", "id-5")
expected.Traits = json.RawMessage(`{"email": "email-id-5"}`)
ct := expected.Credentials[CredentialsTypePassword]
ct.Identifiers = []string{"email-id-5"}
expected.Credentials[CredentialsTypePassword] = ct

_, err := pool.Create(context.Background(), expected)
require.NoError(t, err)

actual, creds, err := pool.FindByCredentialsIdentifier(context.Background(), CredentialsTypePassword, "email-id-5")
require.NoError(t, err)

assert.EqualValues(t, ct, *creds)

expected.Credentials = nil
assertEqual(t, expected, actual)
})

t.Run("case=delete an identity", func(t *testing.T) {
err := pool.Delete(context.Background(), "id-1")
require.NoError(t, err)
Expand Down

0 comments on commit 0c0eb87

Please sign in to comment.