@@ -199,11 +199,13 @@ func TestStrategy(t *testing.T) {
199
199
return res , body
200
200
}
201
201
202
- makeAPICodeFlowRequest := func (t * testing.T , provider , action string ) (returnToURL * url.URL ) {
203
- res , err := testhelpers .NewDebugClient (t ).Post (action , "application/json" , strings .NewReader (fmt .Sprintf (`{
204
- "method": "oidc",
205
- "provider": %q
206
- }` , provider )))
202
+ makeAPICodeFlowRequest := func (t * testing.T , provider , action string , transientPayload string ) (returnToURL * url.URL ) {
203
+ res , err := testhelpers .NewDebugClient (t ).Post (action , "application/json" ,
204
+ strings .NewReader (fmt .Sprintf (`{
205
+ "method": "oidc",
206
+ "provider": %q,
207
+ "transient_payload": %q
208
+ }` , provider , transientPayload )))
207
209
require .NoError (t , err )
208
210
require .Equal (t , http .StatusUnprocessableEntity , res .StatusCode )
209
211
var changeLocation flow.BrowserLocationChangeRequiredError
@@ -834,14 +836,25 @@ func TestStrategy(t *testing.T) {
834
836
})
835
837
836
838
t .Run ("suite=API with session token exchange code" , func (t * testing.T ) {
839
+ postRegistrationWebhook := hooktest .NewServer ()
840
+ t .Cleanup (postRegistrationWebhook .Close )
841
+ postRegistrationWebhook .SetConfig (t , conf .GetProvider (ctx ),
842
+ config .HookStrategyKey (config .ViperKeySelfServiceRegistrationAfter , identity .CredentialsTypeOIDC .String ()))
843
+
844
+ postLoginWebhook := hooktest .NewServer ()
845
+ t .Cleanup (postLoginWebhook .Close )
846
+ postLoginWebhook .SetConfig (t , conf .GetProvider (ctx ),
847
+ config .HookStrategyKey (config .ViperKeySelfServiceLoginAfter , config .HookGlobal ))
848
+
837
849
scope = []string {"openid" }
850
+ transientPayload := `{"data": "registration"}`
838
851
839
852
loginOrRegister := func (t * testing.T , flowID uuid.UUID , code string ) {
840
853
_ , err := exchangeCodeForToken (t , sessiontokenexchange.Codes {InitCode : code })
841
854
require .Error (t , err )
842
855
843
856
action := assertFormValues (t , flowID , "valid" )
844
- returnToURL := makeAPICodeFlowRequest (t , "valid" , action )
857
+ returnToURL := makeAPICodeFlowRequest (t , "valid" , action , transientPayload )
845
858
returnToCode := returnToURL .Query ().Get ("code" )
846
859
assert .NotEmpty (t , code , "code query param was empty in the return_to URL" )
847
860
@@ -857,27 +870,39 @@ func TestStrategy(t *testing.T) {
857
870
performRegistration := func (t * testing.T ) {
858
871
f := newAPIRegistrationFlow (t , returnTS .URL + "?return_session_token_exchange_code=true&return_to=/app_code" , 1 * time .Minute )
859
872
loginOrRegister (t , f .ID , f .SessionTokenExchangeCode )
873
+ postRegistrationWebhook .AssertTransientPayload (t , transientPayload )
874
+ }
875
+ startRegistrationButLogin := func (t * testing.T ) {
876
+ f := newAPIRegistrationFlow (t , returnTS .URL + "?return_session_token_exchange_code=true&return_to=/app_code" , 1 * time .Minute )
877
+ loginOrRegister (t , f .ID , f .SessionTokenExchangeCode )
878
+ postLoginWebhook .AssertTransientPayload (t , transientPayload )
860
879
}
861
880
performLogin := func (t * testing.T ) {
862
881
f := newAPILoginFlow (t , returnTS .URL + "?return_session_token_exchange_code=true&return_to=/app_code" , 1 * time .Minute )
863
882
loginOrRegister (t , f .ID , f .SessionTokenExchangeCode )
883
+ postLoginWebhook .AssertTransientPayload (t , transientPayload )
884
+ }
885
+ startLoginButRegister := func (t * testing.T ) {
886
+ f := newAPILoginFlow (t , returnTS .URL + "?return_session_token_exchange_code=true&return_to=/app_code" , 1 * time .Minute )
887
+ loginOrRegister (t , f .ID , f .SessionTokenExchangeCode )
888
+ postRegistrationWebhook .AssertTransientPayload (t , transientPayload )
864
889
}
865
890
866
891
for _ , tc := range []struct {
867
892
name string
868
893
first , then func (* testing.T )
869
894
}{{
870
895
name : "login-twice" ,
871
- first : performLogin , then : performLogin ,
896
+ first : startLoginButRegister , then : performLogin ,
872
897
}, {
873
898
name : "login-then-register" ,
874
- first : performLogin , then : performRegistration ,
899
+ first : startLoginButRegister , then : startRegistrationButLogin ,
875
900
}, {
876
901
name : "register-then-login" ,
877
902
first : performRegistration , then : performLogin ,
878
903
}, {
879
904
name : "register-twice" ,
880
- first : performRegistration , then : performRegistration ,
905
+ first : performRegistration , then : startRegistrationButLogin ,
881
906
}} {
882
907
t .Run ("case=" + tc .name , func (t * testing.T ) {
883
908
subject = tc .
name + "[email protected] "
@@ -902,7 +927,7 @@ func TestStrategy(t *testing.T) {
902
927
require .Error (t , err )
903
928
904
929
action := assertFormValues (t , f .ID , "valid" )
905
- returnToURL := makeAPICodeFlowRequest (t , "valid" , action )
930
+ returnToURL := makeAPICodeFlowRequest (t , "valid" , action , "{}" )
906
931
returnedFlow := returnToURL .Query ().Get ("flow" )
907
932
908
933
require .NotEmpty (t , returnedFlow , "flow query param was empty in the return_to URL" )
0 commit comments