Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/manager_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/ory/fosite"

"github.com/ory/hydra/internal/testhelpers/uuid"
"github.com/ory/hydra/x"
)

Expand All @@ -45,7 +46,11 @@ func TestHelperClientAutoGenerateKey(k string, m Storage) func(t *testing.T) {
TermsOfServiceURI: "foo",
}
assert.NoError(t, m.CreateClient(ctx, c))
// assert.NotEmpty(t, c.ID)
dbClient, err := m.GetClient(ctx, c.GetID())
assert.NoError(t, err)
dbClientConcrete, ok := dbClient.(*Client)
assert.True(t, ok)
uuid.AssertUUID(t, &dbClientConcrete.ID)
assert.NoError(t, m.DeleteClient(ctx, c.GetID()))
}
}
Expand Down
13 changes: 13 additions & 0 deletions internal/testhelpers/uuid/uuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uuid

import (
"testing"

"github.com/gofrs/uuid"
"github.com/stretchr/testify/require"
)

func AssertUUID(t *testing.T, id *uuid.UUID) {
require.Equal(t, id.Version(), uuid.V4)
require.Equal(t, id.Variant(), uuid.VariantRFC4122)
}
18 changes: 2 additions & 16 deletions persistence/sql/migratest/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"testing"

"github.com/gofrs/uuid"

"github.com/ory/x/configx"

"github.com/ory/hydra/internal/testhelpers/uuid"
"github.com/ory/hydra/persistence/sql"

"github.com/ory/x/popx"
Expand All @@ -28,11 +27,6 @@ import (
"github.com/ory/hydra/x"
)

func assertUUID(t *testing.T, id *uuid.UUID) {
require.Equal(t, id.Version(), uuid.V4)
require.Equal(t, id.Variant(), uuid.VariantRFC4122)
}

func TestMigrations(t *testing.T) {
if testing.Short() {
t.SkipNow()
Expand Down Expand Up @@ -82,7 +76,7 @@ func TestMigrations(t *testing.T) {
actual := &client.Client{}
outfacingID := fmt.Sprintf("client-%04d", i)
require.NoError(t, c.Where("id = ?", outfacingID).First(actual))
assertUUID(t, &actual.ID)
uuid.AssertUUID(t, &actual.ID)
expected := expectedClient(actual.ID, i)
assertEqualClients(t, expected, actual)
lastClient = actual
Expand Down Expand Up @@ -145,14 +139,6 @@ func TestMigrations(t *testing.T) {
})
}

t.Run("case=client migration 20211004/description=new client ID should be valid UUIDv4 variant 1", func(t *testing.T) {
outfacingID := "2021100400"
require.NoError(t, d.Persister().CreateClient(context.Background(), &client.Client{OutfacingID: outfacingID}))
actual := &client.Client{}
require.NoError(t, c.Where("id = ?", outfacingID).First(actual))
assertUUID(t, &actual.ID)
})

// TODO https://github.com/ory/hydra/issues/1815
// this is very stupid and should be replaced as soon the manager uses pop
// necessary because the manager does not provide any way to access the data
Expand Down