Skip to content

Commit 3d936d3

Browse files
committed
add authn state assertions to sso tests
1 parent 25fbacc commit 3d936d3

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

features/api/v1/tokens/generate.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ Feature: Generate authentication token
25332533
"header": "Authorization"
25342534
},
25352535
"links": {
2536-
"redirect": "https://api.workos.test/sso/authorize?domain_hint=keygen.example&[email protected]"
2536+
"redirect": "https://api.workos.test/sso/authorize?domain_hint=keygen.example&[email protected]&state=eyJlbWFpbCI6Inpla2VAa2V5Z2VuLmV4YW1wbGUiLCJlbnZpcm9ubWVudF9pZCI6bnVsbH0"
25372537
}
25382538
}
25392539
"""

features/auth/sso.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ Feature: SSO
974974
And time is frozen at "2552-02-28T00:00:00.000Z"
975975
When I send a GET request to "//auth.keygen.sh/sso?code=test_123"
976976
Then the response status should be "303"
977-
And the response headers should contain "Location" with "https://api.workos.test/sso/authorize?domain_hint=lumon.example&[email protected]"
977+
And the response headers should contain "Location" with "https://api.workos.test/sso/authorize?domain_hint=lumon.example&[email protected]&state=eyJlbWFpbCI6Im1hcmtAbHVtb24uZXhhbXBsZSIsImVudmlyb25tZW50X2lkIjpudWxsfQ"
978978
And the response headers should not contain "Set-Cookie"
979979
And there should be 0 "sessions"
980980
And time is unfrozen

features/step_definitions/resource_steps.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@
160160
end
161161

162162
Given /^the current account has SSO (?:configured|stubbed) for "([^\"]*)"$/ do |domain|
163-
allow(WorkOS::SSO).to receive(:authorization_url).and_wrap_original do |*, domain_hint:, login_hint:, **|
164-
"https://api.workos.test/sso/authorize?domain_hint=#{domain_hint}&login_hint=#{login_hint}"
163+
allow(WorkOS::SSO).to receive(:authorization_url).and_wrap_original do |*, domain_hint:, login_hint:, state:, **|
164+
dec = Keygen::EE::SSO.decrypt_state(state, secret_key: @account.secret_key)
165+
enc = Base64.urlsafe_encode64(dec.to_json, padding: false)
166+
167+
"https://api.workos.test/sso/authorize?domain_hint=#{domain_hint}&login_hint=#{login_hint}&state=#{enc}"
165168
end
166169

167170
@account.update!(
@@ -171,12 +174,15 @@
171174
end
172175

173176
Given /^the account "([^\"]*)" has SSO (?:configured|stubbed) for "([^\"]*)"$/ do |id, domain|
174-
allow(WorkOS::SSO).to receive(:authorization_url).and_wrap_original do |*, domain_hint:, login_hint:, **|
175-
"https://api.workos.test/sso/authorize?domain_hint=#{domain_hint}&login_hint=#{login_hint}"
176-
end
177-
178177
account = FindByAliasService.call(Account, id:, aliases: :slug)
179178

179+
allow(WorkOS::SSO).to receive(:authorization_url).and_wrap_original do |*, domain_hint:, login_hint:, state:, **|
180+
dec = Keygen::EE::SSO.decrypt_state(state, secret_key: account.secret_key)
181+
enc = Base64.urlsafe_encode64(dec.to_json, padding: false)
182+
183+
"https://api.workos.test/sso/authorize?domain_hint=#{domain_hint}&login_hint=#{login_hint}&state=#{enc}"
184+
end
185+
180186
account.update!(
181187
sso_organization_id: account.sso_organization_id.presence || "test_org_#{SecureRandom.hex}",
182188
sso_organization_domains: account.sso_organization_domains.presence || [domain],

0 commit comments

Comments
 (0)