Skip to content

Commit 63f68e3

Browse files
committed
Add generate_pkce e2e action and use SPA client in link_oauth tests
generate_pkce produces a code_verifier and code_challenge (S256) so tests can use the e2e SPA client, which is the realistic client type for settings action invocations from the SDK. ref DEV-3595
1 parent 74d62bf commit 63f68e3

5 files changed

Lines changed: 51 additions & 11 deletions

File tree

e2e/pkg/testrunner/models.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ var _ = TestCaseSchema.Add("Step", `
270270
"admin_api_user_import_create",
271271
"admin_api_user_import_get",
272272
"generate_app_session_token",
273-
"generate_refresh_token"
273+
"generate_refresh_token",
274+
"generate_pkce"
274275
]},
275276
"sleep_for": { "type": "string", "format": "x_duration_string" },
276277
"input": { "type": "string" },
@@ -632,6 +633,7 @@ const (
632633
StepActionAdminAPIUserImportGet StepAction = "admin_api_user_import_get"
633634
StepActionGenerateAppSessionToken StepAction = "generate_app_session_token"
634635
StepActionGenerateRefreshToken StepAction = "generate_refresh_token"
636+
StepActionGeneratePKCE StepAction = "generate_pkce"
635637
)
636638

637639
var _ = TestCaseSchema.Add("SessionCookie", `

e2e/pkg/testrunner/testcase.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
authflowclient "github.com/authgear/authgear-server/e2e/pkg/e2eclient"
2222
"github.com/authgear/authgear-server/pkg/graphqlgo/relay"
23+
"github.com/authgear/authgear-server/pkg/util/pkce"
2324
"github.com/authgear/authgear-server/pkg/util/secretcode"
2425
)
2526

@@ -711,6 +712,16 @@ func (tc *TestCase) executeStep(
711712
Error: nil,
712713
}
713714

715+
case StepActionGeneratePKCE:
716+
verifier := pkce.GenerateS256Verifier()
717+
result = &StepResult{
718+
Result: map[string]any{
719+
"code_verifier": verifier.CodeVerifier,
720+
"code_challenge": verifier.Challenge(),
721+
},
722+
Error: nil,
723+
}
724+
714725
default:
715726
t.Errorf("unknown action in '%s': %s", step.Name, step.Action)
716727
return nil, state, false

e2e/tests/settings_action/link_oauth/link_oauth.test.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ steps:
5151
action: generate_app_session_token
5252
generate_app_session_token_refresh_token: '{{ .steps.generate_refresh_token.result.refresh_token }}'
5353

54+
# ── Generate PKCE pair for the SPA client ──
55+
56+
- name: pkce
57+
action: generate_pkce
58+
5459
# ── Start link_oauth settings action ──
5560
# Server sets app_session_token cookie and redirects to settings page with x_ref
5661

@@ -60,9 +65,11 @@ steps:
6065
http_request_url: http://127.0.0.1:4000/oauth2/authorize
6166
http_request_query:
6267
response_type: "urn:authgear:params:oauth:response-type:settings-action"
63-
client_id: e2econfidential
64-
redirect_uri: http://localhost
68+
client_id: e2e
69+
redirect_uri: http://localhost:4000
6570
scope: openid
71+
code_challenge: "{{ .steps.pkce.result.code_challenge }}"
72+
code_challenge_method: S256
6673
x_settings_action: link_oauth
6774
x_oauth_provider_alias: google
6875
login_hint: 'https://authgear.com/login_hint?type=app_session_token&app_session_token={{ .steps.generate_app_session_token.result.app_session_token }}'

e2e/tests/settings_action/link_oauth/link_oauth_already_linked.test.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ steps:
4949
action: generate_app_session_token
5050
generate_app_session_token_refresh_token: '{{ .steps.generate_refresh_token_1.result.refresh_token }}'
5151

52+
- name: pkce_1
53+
action: generate_pkce
54+
5255
- name: settings_action_authorize_1
5356
action: http_request
5457
http_request_method: GET
5558
http_request_url: http://127.0.0.1:4000/oauth2/authorize
5659
http_request_query:
5760
response_type: "urn:authgear:params:oauth:response-type:settings-action"
58-
client_id: e2econfidential
59-
redirect_uri: http://localhost
61+
client_id: e2e
62+
redirect_uri: http://localhost:4000
6063
scope: openid
64+
code_challenge: "{{ .steps.pkce_1.result.code_challenge }}"
65+
code_challenge_method: S256
6166
x_settings_action: link_oauth
6267
x_oauth_provider_alias: google
6368
login_hint: 'https://authgear.com/login_hint?type=app_session_token&app_session_token={{ .steps.generate_app_session_token_1.result.app_session_token }}'
@@ -105,15 +110,20 @@ steps:
105110
action: generate_app_session_token
106111
generate_app_session_token_refresh_token: '{{ .steps.generate_refresh_token_2.result.refresh_token }}'
107112

113+
- name: pkce_2
114+
action: generate_pkce
115+
108116
- name: settings_action_authorize_2
109117
action: http_request
110118
http_request_method: GET
111119
http_request_url: http://127.0.0.1:4000/oauth2/authorize
112120
http_request_query:
113121
response_type: "urn:authgear:params:oauth:response-type:settings-action"
114-
client_id: e2econfidential
115-
redirect_uri: http://localhost
122+
client_id: e2e
123+
redirect_uri: http://localhost:4000
116124
scope: openid
125+
code_challenge: "{{ .steps.pkce_2.result.code_challenge }}"
126+
code_challenge_method: S256
117127
x_settings_action: link_oauth
118128
x_oauth_provider_alias: google
119129
login_hint: 'https://authgear.com/login_hint?type=app_session_token&app_session_token={{ .steps.generate_app_session_token_2.result.app_session_token }}'

e2e/tests/settings_action/link_oauth/link_oauth_conflict.test.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ steps:
5858
action: generate_app_session_token
5959
generate_app_session_token_refresh_token: '{{ .steps.generate_refresh_token_a.result.refresh_token }}'
6060

61+
- name: pkce_a
62+
action: generate_pkce
63+
6164
- name: settings_action_authorize_a
6265
action: http_request
6366
http_request_method: GET
6467
http_request_url: http://127.0.0.1:4000/oauth2/authorize
6568
http_request_query:
6669
response_type: "urn:authgear:params:oauth:response-type:settings-action"
67-
client_id: e2econfidential
68-
redirect_uri: http://localhost
70+
client_id: e2e
71+
redirect_uri: http://localhost:4000
6972
scope: openid
73+
code_challenge: "{{ .steps.pkce_a.result.code_challenge }}"
74+
code_challenge_method: S256
7075
x_settings_action: link_oauth
7176
x_oauth_provider_alias: google
7277
login_hint: 'https://authgear.com/login_hint?type=app_session_token&app_session_token={{ .steps.generate_app_session_token_a.result.app_session_token }}'
@@ -114,15 +119,20 @@ steps:
114119
action: generate_app_session_token
115120
generate_app_session_token_refresh_token: '{{ .steps.generate_refresh_token_b.result.refresh_token }}'
116121

122+
- name: pkce_b
123+
action: generate_pkce
124+
117125
- name: settings_action_authorize_b
118126
action: http_request
119127
http_request_method: GET
120128
http_request_url: http://127.0.0.1:4000/oauth2/authorize
121129
http_request_query:
122130
response_type: "urn:authgear:params:oauth:response-type:settings-action"
123-
client_id: e2econfidential
124-
redirect_uri: http://localhost
131+
client_id: e2e
132+
redirect_uri: http://localhost:4000
125133
scope: openid
134+
code_challenge: "{{ .steps.pkce_b.result.code_challenge }}"
135+
code_challenge_method: S256
126136
x_settings_action: link_oauth
127137
x_oauth_provider_alias: google
128138
login_hint: 'https://authgear.com/login_hint?type=app_session_token&app_session_token={{ .steps.generate_app_session_token_b.result.app_session_token }}'

0 commit comments

Comments
 (0)