-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8537f71
commit 151f092
Showing
4 changed files
with
138 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,62 +15,120 @@ import ( | |
"github.com/ory/kratos/driver/config" | ||
"github.com/ory/kratos/internal" | ||
"github.com/ory/kratos/selfservice/flow" | ||
"github.com/ory/kratos/selfservice/flow/login" | ||
"github.com/ory/kratos/selfservice/flow/registration" | ||
"github.com/ory/kratos/selfservice/flow/verification" | ||
"github.com/ory/kratos/selfservice/hook" | ||
) | ||
|
||
func TestExecutePostRegistrationPostPersistHook(t *testing.T) { | ||
t.Run("case=no continue with items returns 200 OK", func(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
f := ®istration.Flow{} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, f, nil)) | ||
require.Equal(t, 200, rec.Code) | ||
}) | ||
t.Run("flow=registration", func(t *testing.T) { | ||
t.Run("case=no continue with items returns 200 OK", func(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
f := ®istration.Flow{} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, f, nil)) | ||
require.Equal(t, 200, rec.Code) | ||
}) | ||
|
||
t.Run("case=not a browser request returns 200 OK", func(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
browserRequest.Header.Add("Accept", "application/json") | ||
f := ®istration.Flow{} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, f, nil)) | ||
require.Equal(t, 200, rec.Code) | ||
}) | ||
t.Run("case=not a browser request returns 200 OK", func(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
browserRequest.Header.Add("Accept", "application/json") | ||
f := ®istration.Flow{} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, f, nil)) | ||
require.Equal(t, 200, rec.Code) | ||
}) | ||
|
||
t.Run("case=verification ui in continue with item returns redirect", func(t *testing.T) { | ||
conf, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
conf.Set(context.Background(), config.ViperKeySelfServiceVerificationUI, "/verification") | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
vf := &verification.Flow{ | ||
ID: uuid.Must(uuid.NewV4()), | ||
} | ||
rf := ®istration.Flow{} | ||
rf.ContinueWithItems = []flow.ContinueWith{ | ||
flow.NewContinueWithVerificationUI(vf, "[email protected]", ""), | ||
} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, rf, nil)) | ||
assert.Equal(t, 200, rec.Code) | ||
assert.Equal(t, "/verification?flow="+vf.ID.String(), rf.ReturnToVerification) | ||
}) | ||
|
||
t.Run("case=verification ui in continue with item returns redirect", func(t *testing.T) { | ||
conf, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
conf.Set(context.Background(), config.ViperKeySelfServiceVerificationUI, "/verification") | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
vf := &verification.Flow{ | ||
ID: uuid.Must(uuid.NewV4()), | ||
} | ||
rf := ®istration.Flow{} | ||
rf.ContinueWithItems = []flow.ContinueWith{ | ||
flow.NewContinueWithVerificationUI(vf, "[email protected]", ""), | ||
} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, rf, nil)) | ||
assert.Equal(t, 200, rec.Code) | ||
assert.Equal(t, "/verification?flow="+vf.ID.String(), rf.ReturnToVerification) | ||
t.Run("case=no verification ui in continue with item returns 200 OK", func(t *testing.T) { | ||
conf, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
conf.Set(context.Background(), config.ViperKeySelfServiceVerificationUI, "/verification") | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
rf := ®istration.Flow{} | ||
rf.ContinueWithItems = []flow.ContinueWith{ | ||
flow.NewContinueWithSetToken("token"), | ||
} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, rf, nil)) | ||
assert.Equal(t, 200, rec.Code) | ||
}) | ||
}) | ||
|
||
t.Run("case=no verification ui in continue with item returns 200 OK", func(t *testing.T) { | ||
conf, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
conf.Set(context.Background(), config.ViperKeySelfServiceVerificationUI, "/verification") | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
rf := ®istration.Flow{} | ||
rf.ContinueWithItems = []flow.ContinueWith{ | ||
flow.NewContinueWithSetToken("token"), | ||
} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecutePostRegistrationPostPersistHook(rec, browserRequest, rf, nil)) | ||
assert.Equal(t, 200, rec.Code) | ||
t.Run("flow=login", func(t *testing.T) { | ||
t.Run("case=no continue with items returns 200 OK", func(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
f := &login.Flow{} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecuteLoginPostHook(rec, browserRequest, "", f, nil)) | ||
require.Equal(t, 200, rec.Code) | ||
}) | ||
|
||
t.Run("case=not a browser request returns 200 OK", func(t *testing.T) { | ||
_, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
browserRequest.Header.Add("Accept", "application/json") | ||
f := &login.Flow{} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecuteLoginPostHook(rec, browserRequest, "", f, nil)) | ||
require.Equal(t, 200, rec.Code) | ||
}) | ||
|
||
t.Run("case=verification ui in continue with item returns redirect", func(t *testing.T) { | ||
conf, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
conf.Set(context.Background(), config.ViperKeySelfServiceVerificationUI, "/verification") | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
vf := &verification.Flow{ | ||
ID: uuid.Must(uuid.NewV4()), | ||
} | ||
rf := &login.Flow{} | ||
rf.ContinueWithItems = []flow.ContinueWith{ | ||
flow.NewContinueWithVerificationUI(vf, "[email protected]", ""), | ||
} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecuteLoginPostHook(rec, browserRequest, "", rf, nil)) | ||
assert.Equal(t, 200, rec.Code) | ||
assert.Equal(t, "/verification?flow="+vf.ID.String(), rf.ReturnToVerification) | ||
}) | ||
|
||
t.Run("case=no verification ui in continue with item returns 200 OK", func(t *testing.T) { | ||
conf, reg := internal.NewVeryFastRegistryWithoutDB(t) | ||
conf.Set(context.Background(), config.ViperKeySelfServiceVerificationUI, "/verification") | ||
h := hook.NewShowVerificationUIHook(reg) | ||
browserRequest := httptest.NewRequest("GET", "/", nil) | ||
rf := &login.Flow{} | ||
rf.ContinueWithItems = []flow.ContinueWith{ | ||
flow.NewContinueWithSetToken("token"), | ||
} | ||
rec := httptest.NewRecorder() | ||
require.NoError(t, h.ExecuteLoginPostHook(rec, browserRequest, "", rf, nil)) | ||
assert.Equal(t, 200, rec.Code) | ||
}) | ||
}) | ||
} |