Skip to content

Commit

Permalink
feat: implement tests for new migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 27, 2020
1 parent d764435 commit e08ece9
Show file tree
Hide file tree
Showing 33 changed files with 376 additions and 148 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -125,6 +125,10 @@ migrations-render: .bin/cli
migrations-render-replace: .bin/cli
cli dev pop migration render -r persistence/sql/migrations/templates persistence/sql/migrations/sql

.PHONY: migratest-refresh
migratest-refresh:
cd persistence/sql/migratest; go test -tags sqlite,refresh -short .

.PHONY: pack
pack: .bin/pkger
pkger -exclude node_modules -exclude docs -exclude .bin -exclude test -exclude script -exclude contrib
2 changes: 1 addition & 1 deletion driver/registry_default.go
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/ory/kratos/selfservice/flow/settings"
"github.com/ory/kratos/selfservice/flow/verification"
"github.com/ory/kratos/selfservice/hook"
"github.com/ory/kratos/selfservice/strategy/profile"
"github.com/ory/kratos/selfservice/strategy/link"
"github.com/ory/kratos/selfservice/strategy/profile"
"github.com/ory/kratos/x"

"github.com/cenkalti/backoff"
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Expand Up @@ -27,7 +27,8 @@ require (
github.com/go-playground/locales v0.12.1 // indirect
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/go-swagger/go-swagger v0.25.0
github.com/gobuffalo/fizz v1.11.1-0.20200706214517-4e9fb9ced4ce
// see https://github.com/gobuffalo/fizz/pull/96
github.com/gobuffalo/fizz v1.11.1-0.20200827214106-ed1b75c3b6ff
github.com/gobuffalo/httptest v1.0.2
github.com/gobuffalo/packr/v2 v2.8.0 // indirect
github.com/gobuffalo/pop/v5 v5.2.4-0.20200706214017-1dd950510b30
Expand Down Expand Up @@ -56,7 +57,7 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
github.com/ory/analytics-go/v4 v4.0.0
github.com/ory/cli v0.0.24
github.com/ory/cli v0.0.25-0.20200827222409-9207e62c455a
github.com/ory/dockertest v3.3.5+incompatible
github.com/ory/dockertest/v3 v3.5.4
github.com/ory/go-acc v0.1.0
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Expand Up @@ -352,10 +352,8 @@ github.com/gobuffalo/events v1.4.1/go.mod h1:SjXgWKpeSuvQDvGhgMz5IXx3Czu+IbL+XPL
github.com/gobuffalo/fizz v1.0.12/go.mod h1:C0sltPxpYK8Ftvf64kbsQa2yiCZY4RZviurNxXdAKwc=
github.com/gobuffalo/fizz v1.9.8/go.mod h1:w1FEn1yKNVCc49KnADGyYGRPH7jFON3ak4Bj1yUudHo=
github.com/gobuffalo/fizz v1.10.0/go.mod h1:J2XGPO0AfJ1zKw7+2BA+6FEGAkyEsdCOLvN93WCT2WI=
github.com/gobuffalo/fizz v1.11.0 h1:kJ+9sSSZpolHz4ULV1sF76AGmo74kEi6IztIc4HmshU=
github.com/gobuffalo/fizz v1.11.0/go.mod h1:cXLjhE5p3iuIes6AGZ/9+dfyOkehlB2Vldj0Iw2Uu38=
github.com/gobuffalo/fizz v1.11.1-0.20200706214517-4e9fb9ced4ce h1:Y0QAYLDJp9VJUOefsaHZFEDSILz6nRKZxcToDhcSKZY=
github.com/gobuffalo/fizz v1.11.1-0.20200706214517-4e9fb9ced4ce/go.mod h1:cXLjhE5p3iuIes6AGZ/9+dfyOkehlB2Vldj0Iw2Uu38=
github.com/gobuffalo/fizz v1.11.1-0.20200827214106-ed1b75c3b6ff h1:YKQJAc2WkWJ0isE5VIwxcSZXNaS+2ngXinfbr+hZnzY=
github.com/gobuffalo/fizz v1.11.1-0.20200827214106-ed1b75c3b6ff/go.mod h1:cXLjhE5p3iuIes6AGZ/9+dfyOkehlB2Vldj0Iw2Uu38=
github.com/gobuffalo/flect v0.0.0-20180907193754-dc14d8acaf9f/go.mod h1:rCiQgmAE4axgBNl3jZWzS5rETRYTGOsrixTRaCPzNdA=
github.com/gobuffalo/flect v0.0.0-20181002182613-4571df4b1daf/go.mod h1:rCiQgmAE4axgBNl3jZWzS5rETRYTGOsrixTRaCPzNdA=
github.com/gobuffalo/flect v0.0.0-20181007231023-ae7ed6bfe683/go.mod h1:rCiQgmAE4axgBNl3jZWzS5rETRYTGOsrixTRaCPzNdA=
Expand Down Expand Up @@ -1043,8 +1041,8 @@ github.com/openzipkin/zipkin-go v0.2.2 h1:nY8Hti+WKaP0cRsSeQ026wU03QsM762XBeCXBb
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/ory/analytics-go/v4 v4.0.0 h1:KQ2P00j9dbj4lDC/Albw/zn/scK67041RhqeW5ptsbw=
github.com/ory/analytics-go/v4 v4.0.0/go.mod h1:FMx9cLRD9xN+XevPvZ5FDMfignpmcqPP6FUKnJ9/MmE=
github.com/ory/cli v0.0.24 h1:lPKxJIA45KcCRyt6H/B+gB64UsN/t40Wnte1VJR3WCE=
github.com/ory/cli v0.0.24/go.mod h1:xHQzktVXHdLzLHUZ36PQ0PU67OQgDYfenLQhbfU4KzM=
github.com/ory/cli v0.0.25-0.20200827222409-9207e62c455a h1:UZBzAFt103fILKINZoODh3j1Wmsumh6eoH4bMruFcok=
github.com/ory/cli v0.0.25-0.20200827222409-9207e62c455a/go.mod h1:9AA94/MP63p9v5fvOoaGucHaWMOejKhqYPHhUQwEHNE=
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/ory/dockertest/v3 v3.5.4 h1:rYijlJuraj8D4OgC1DpYpCV8SGXrkviT3RVrjFy7OFc=
Expand Down
@@ -0,0 +1,37 @@
{
"id": "b1fac7fb-d016-4a06-a7fe-e4eab2a0429f",
"type": "api",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/login",
"messages": [],
"methods": {
"password": {
"method": "password",
"config": {
"action": "http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/login/strategies/password?request=3a9ea34f-0f12-469b-9417-3ae5795a7baa",
"method": "POST",
"fields": [
{
"name": "identifier",
"type": "text",
"required": true,
"value": ""
},
{
"name": "password",
"type": "password",
"required": true
},
{
"name": "csrf_token",
"type": "hidden",
"required": true,
"value": "fpeVSZ9ZH7YvUkhXsOVEIssxbfauh5lcoQSYxTcN0XkMneg1L42h+HtvisjlNjBF4ElcD2jApCHoJYq2u9sVWg=="
}
]
}
}
},
"forced": false
}
@@ -0,0 +1,32 @@
{
"id": "0d14427f-e16d-43a5-8695-8278bf85d4eb",
"type": "api",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
"active": "link",
"messages": [],
"methods": {
"link": {
"method": "link",
"config": {
"action": "http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/settings/strategies/profile?request=21c5f714-3089-49d2-b387-f244d4dd9e00",
"method": "POST",
"fields": [
{
"name": "csrf_token",
"type": "hidden",
"required": true,
"value": "yDwSg0quCmc4kBl7lBqYwGh4W8awrc+TpeWiigZs3iemRCwqeDhGdrW3sIv8T7u742pN+Kryx/NrdRpEXcT9qA=="
},
{
"name": "traits.email",
"type": "text",
"value": "foo"
}
]
}
}
},
"state": "choose_method"
}
@@ -0,0 +1,36 @@
{
"id": "8ef215a9-e8d5-43b3-9aa3-cb4333562e36",
"type": "api",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/registration",
"active": "password",
"messages": [],
"methods": {
"password": {
"method": "password",
"config": {
"action": "http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/registration/strategies/password?request=87fa3f43-5155-42b4-a1ad-174c2595fdaf",
"method": "POST",
"fields": [
{
"name": "csrf_token",
"type": "hidden",
"required": true,
"value": "KeEp3OT+pHSXJpZAP+C1hR3yr4eIjUBDhg9tc/F1WI1b61SgVCoaOsMbVN9qM8HiNoqefk7KfT7PLn8AfaOcrg=="
},
{
"name": "password",
"type": "password",
"required": true
},
{
"name": "traits.email",
"type": "text",
"value": "foo@ory.sh"
}
]
}
}
}
}
@@ -0,0 +1,25 @@
{
"id": "8571e374-38f2-4f46-8ad3-b9d914e174d3",
"active": false,
"expires_at": "2013-10-07T08:23:19Z",
"authenticated_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"identity": {
"id": "5ff66179-c240-4703-b0d8-494592cefff5",
"schema_id": "default",
"schema_url": "https://www.ory.sh/schemas/default",
"traits": {
"email": "bazbar@ory.sh"
},
"verifiable_addresses": [
{
"id": "45e867e9-2745-4f16-8dd4-84334a252b61",
"value": "foo@ory.sh",
"verified": false,
"via": "email",
"verified_at": null,
"expires_at": "2013-10-07T08:23:19Z"
}
]
}
}
@@ -0,0 +1,25 @@
{
"id": "f38cdebe-e567-42c9-a562-1bd4dee40998",
"active": true,
"expires_at": "2013-10-07T08:23:19Z",
"authenticated_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"identity": {
"id": "5ff66179-c240-4703-b0d8-494592cefff5",
"schema_id": "default",
"schema_url": "https://www.ory.sh/schemas/default",
"traits": {
"email": "bazbar@ory.sh"
},
"verifiable_addresses": [
{
"id": "45e867e9-2745-4f16-8dd4-84334a252b61",
"value": "foo@ory.sh",
"verified": false,
"via": "email",
"verified_at": null,
"expires_at": "2013-10-07T08:23:19Z"
}
]
}
}
@@ -0,0 +1,40 @@
{
"id": "90b4f970-b9ae-42bc-a0a7-73ec750e0aa1",
"type": "browser",
"expires_at": "2013-10-07T08:23:19Z",
"issued_at": "2013-10-07T08:23:19Z",
"request_url": "http://kratos:4433/self-service/browser/flows/settings",
"active": "profile",
"messages": [],
"methods": {
"profile": {
"method": "profile",
"config": {
"action": "http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/settings/strategies/profile?request=21c5f714-3089-49d2-b387-f244d4dd9e00",
"method": "POST",
"fields": [
{
"name": "csrf_token",
"type": "hidden",
"required": true,
"value": "yDwSg0quCmc4kBl7lBqYwGh4W8awrc+TpeWiigZs3iemRCwqeDhGdrW3sIv8T7u742pN+Kryx/NrdRpEXcT9qA=="
},
{
"name": "traits.email",
"type": "text",
"value": "foo"
}
]
}
}
},
"identity": {
"id": "a251ebc2-880c-4f76-a8f3-38e6940eab0e",
"schema_id": "default",
"schema_url": "",
"traits": {
"email": "foobar@ory.sh"
}
},
"state": "show_form"
}
21 changes: 11 additions & 10 deletions persistence/sql/migratest/migration_test.go
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ory/kratos/selfservice/flow/recovery"
"github.com/ory/kratos/selfservice/flow/registration"
"github.com/ory/kratos/selfservice/flow/settings"
"github.com/ory/kratos/session"
"github.com/ory/kratos/x"
)

Expand Down Expand Up @@ -88,18 +89,8 @@ func TestMigrations(t *testing.T) {
}
t.Logf("URL: %s", url)

var isSQLite = c.Dialect.Name() == "sqlite3"

tm := popx.NewTestMigrator(t, c, "../migrations/sql", "./testdata")

if isSQLite {
require.NoError(t, c.RawQuery(`PRAGMA legacy_alter_table=on; PRAGMA foreign_keys=off;`).Exec())
}
require.NoError(t, tm.Up())
if isSQLite {
require.NoError(t, c.RawQuery(`PRAGMA legacy_alter_table=off; PRAGMA foreign_keys=on;`).Exec())
}

viper.Set(configuration.ViperKeyPublicBaseURL, "https://www.ory.sh/")
viper.Set(configuration.ViperKeyDefaultIdentitySchemaURL, "file://stub/default.schema.json")
viper.Set(configuration.ViperKeyDSN, url)
Expand All @@ -118,6 +109,16 @@ func TestMigrations(t *testing.T) {
compareWithFixture(t, actual, "identity", id.ID.String())
}
})
t.Run("case=session", func(t *testing.T) {
var ids []session.Session
require.NoError(t, c.Select("id").All(&ids))

for _, id := range ids {
actual, err := d.Registry().SessionPersister().GetSession(context.Background(), id.ID)
require.NoError(t, err)
compareWithFixture(t, actual, "session", id.ID.String())
}
})

t.Run("case=login", func(t *testing.T) {
var ids []login.Flow
Expand Down
22 changes: 22 additions & 0 deletions persistence/sql/migratest/testdata/20200810161022_testdata.sql
@@ -0,0 +1,22 @@
INSERT INTO selfservice_login_flows (id, request_url, issued_at, expires_at, active_method, csrf_token, created_at, updated_at, forced, messages, type)
VALUES ('b1fac7fb-d016-4a06-a7fe-e4eab2a0429f', 'http://kratos:4433/self-service/browser/flows/login', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '', 'fpeVSZ9ZH7YvUkhXsOVEIssxbfauh5lcoQSYxTcN0XkMneg1L42h+HtvisjlNjBF4ElcD2jApCHoJYq2u9sVWg==', '2013-10-07 08:23:19', '2013-10-07 08:23:19', false, '[]', 'api');
INSERT INTO selfservice_login_flow_methods (id, method, selfservice_login_request_id, config, created_at, updated_at)
VALUES ('8ca78d66-772a-4408-804e-f5d3d9fe696e', 'password', 'b1fac7fb-d016-4a06-a7fe-e4eab2a0429f', '{"action":"http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/login/strategies/password?request=3a9ea34f-0f12-469b-9417-3ae5795a7baa","method":"POST","fields":[{"name":"identifier","type":"text","required":true,"value":""},{"name":"password","type":"password","required":true},{"name":"csrf_token","type":"hidden","required":true,"value":"fpeVSZ9ZH7YvUkhXsOVEIssxbfauh5lcoQSYxTcN0XkMneg1L42h+HtvisjlNjBF4ElcD2jApCHoJYq2u9sVWg=="}]}', '2013-10-07 08:23:19', '2013-10-07 08:23:19');

INSERT INTO selfservice_registration_flows (id, request_url, issued_at, expires_at, active_method, csrf_token, created_at, updated_at, messages, type)
VALUES ('8ef215a9-e8d5-43b3-9aa3-cb4333562e36', 'http://kratos:4433/self-service/browser/flows/registration', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'password', 'vYYuhWXBfXKzBC+BlnbDmXfBKsUWY6SU/v04gHF9GYzPjFP51RXDPOc57R7Dpbf+XLkbPNAkmem33Crz/avdrw==', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '[]', 'api');
INSERT INTO selfservice_registration_flow_methods (id, method, selfservice_registration_request_id, config, created_at, updated_at)
VALUES ('356019d1-900e-4c6d-b3f1-564c86930979', 'password', '8ef215a9-e8d5-43b3-9aa3-cb4333562e36', '{"action":"http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/registration/strategies/password?request=87fa3f43-5155-42b4-a1ad-174c2595fdaf","method":"POST","fields":[{"name":"csrf_token","type":"hidden","required":true,"value":"KeEp3OT+pHSXJpZAP+C1hR3yr4eIjUBDhg9tc/F1WI1b61SgVCoaOsMbVN9qM8HiNoqefk7KfT7PLn8AfaOcrg=="},{"name":"password","type":"password","required":true,"errors":[{"message":"the password does not fulfill the password policy because: the password has been found in at least 23547453 data breaches and must no longer be used."}]},{"name":"traits.email","type":"text","value":"foo@ory.sh"}]}', '2013-10-07 08:23:19', '2013-10-07 08:23:19');

INSERT INTO selfservice_settings_flows (id, request_url, issued_at, expires_at, state, identity_id, created_at, updated_at, active_method, messages)
VALUES ('90b4f970-b9ae-42bc-a0a7-73ec750e0aa1', 'http://kratos:4433/self-service/browser/flows/settings', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'show_form', 'a251ebc2-880c-4f76-a8f3-38e6940eab0e', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'profile', '[]');
INSERT INTO selfservice_settings_flow_methods (id, method, selfservice_settings_request_id, config, created_at, updated_at)
VALUES ('547e8444-b3b0-4de7-9fdf-b80d6a8de15f', 'profile', '90b4f970-b9ae-42bc-a0a7-73ec750e0aa1', '{"action":"http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/settings/strategies/profile?request=21c5f714-3089-49d2-b387-f244d4dd9e00","method":"POST","fields":[{"name":"csrf_token","type":"hidden","required":true,"value":"yDwSg0quCmc4kBl7lBqYwGh4W8awrc+TpeWiigZs3iemRCwqeDhGdrW3sIv8T7u742pN+Kryx/NrdRpEXcT9qA=="},{"name":"traits.email","type":"text","value":"foo","errors":[{"message":"validation failed"},{"message":"foo is not valid email"},{"message":"foo is not valid email"}]}]}', '2013-10-07 08:23:19', '2013-10-07 08:23:19');

INSERT INTO selfservice_verification_flows (id, request_url, issued_at, expires_at, form, via, csrf_token, success, created_at, updated_at, messages, type)
VALUES ('42f31e47-65e1-4be9-80ea-e5d8ed64b236', 'http://kratos:4433/self-service/browser/flows/verification/email', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'null', 'email', '8xoIMa1+UkDqTt+tIHmIEHztQkk0AWk2PJhWWYDmB6dSE+RtJinnxtwH5lNNCnYyQuCF2ugy7rWjCgiwYPJNOw==', true, '2013-10-07 08:23:19', '2013-10-07 08:23:19', '[]', 'api');

INSERT INTO selfservice_recovery_flows (id, request_url, issued_at, expires_at, messages, active_method, csrf_token, state, recovered_identity_id, created_at, updated_at, type)
VALUES ('0d14427f-e16d-43a5-8695-8278bf85d4eb', 'http://kratos:4433/self-service/browser/flows/registration', '2013-10-07 08:23:19', '2013-10-07 08:23:19', '[]', 'link', 'vYYuhWXBfXKzBC+BlnbDmXfBKsUWY6SU/v04gHF9GYzPjFP51RXDPOc57R7Dpbf+XLkbPNAkmem33Crz/avdrw==', 'choose_method', 'a251ebc2-880c-4f76-a8f3-38e6940eab0e', '2013-10-07 08:23:19', '2013-10-07 08:23:19', 'api');
INSERT INTO selfservice_recovery_flow_methods (id, method, selfservice_recovery_request_id, config, created_at, updated_at)
VALUES ('1a45ce9b-b527-4535-ad31-b808e481d280', 'link', '0d14427f-e16d-43a5-8695-8278bf85d4eb', '{"action":"http://127.0.0.1:4455/.ory/kratos/public/self-service/browser/flows/settings/strategies/profile?request=21c5f714-3089-49d2-b387-f244d4dd9e00","method":"POST","fields":[{"name":"csrf_token","type":"hidden","required":true,"value":"yDwSg0quCmc4kBl7lBqYwGh4W8awrc+TpeWiigZs3iemRCwqeDhGdrW3sIv8T7u742pN+Kryx/NrdRpEXcT9qA=="},{"name":"traits.email","type":"text","value":"foo","errors":[{"message":"validation failed"},{"message":"foo is not valid email"},{"message":"foo is not valid email"}]}]}', '2013-10-07 08:23:19', '2013-10-07 08:23:19');

0 comments on commit e08ece9

Please sign in to comment.