Skip to content

Commit 31f6412

Browse files
authored
Merge pull request #95 from OpenConext/feature/gssp-service-name-fullflow-behat
Add full-flow behat for GSSP service name
2 parents be2faef + d86182b commit 31f6412

4 files changed

Lines changed: 187 additions & 6 deletions

File tree

‎stepup/seed-test-identity.sh‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Seeds a fully vetted Demo GSSP identity directly via Middleware's command API,
5+
# bypassing registration UI, RA app, e-mail, and any physical/virtual second factor
6+
# hardware entirely. Mirrors the "has a vetted demo-gssp" step in
7+
# tests/behat/features/bootstrap/FeatureContext.php (theUserHasAVettedWithIdentifier),
8+
# adapted from the smoketest DB to this environment's real dev DB/credentials.
9+
#
10+
# Usage: ./seed-test-identity.sh <slug> [institution] [gssf-id]
11+
#
12+
# After running, log in via the ssp test SP (https://ssp.dev.openconext.local/simplesaml/sp.php)
13+
# as <slug>/<slug>, request an LoA that Demo GSSP satisfies, and pick "Demo GSSP" as the
14+
# second factor -- no registration/vetting/hardware step needed.
15+
16+
SLUG="${1:?Usage: $0 <slug> [institution] [gssf-id]}"
17+
INSTITUTION="${2:-dev.openconext.local}"
18+
GSSF_ID="${3:-seed-$SLUG}"
19+
NAME_ID="urn:collab:person:${INSTITUTION}:${SLUG}"
20+
IDENTITY_ID=$(uuidgen | tr 'A-Z' 'a-z')
21+
SECOND_FACTOR_ID=$(uuidgen | tr 'A-Z' 'a-z')
22+
23+
# Real SRAA identity in this environment's dev DB (has RA authority everywhere).
24+
# Look it up fresh rather than hardcoding, in case the admin identity_id ever changes.
25+
ACTOR_ID=$(docker exec stepup-mariadb-1 mysql -uroot -psecret middleware -N -B \
26+
-e "SELECT id FROM identity WHERE name_id='urn:collab:person:dev.openconext.local:admin';")
27+
28+
if [ -z "$ACTOR_ID" ]; then
29+
echo "Could not find the admin/SRAA identity in the middleware DB -- is the environment bootstrapped?" >&2
30+
exit 1
31+
fi
32+
33+
MW=https://middleware.dev.openconext.local
34+
DB="docker exec stepup-mariadb-1 mysql -uroot -psecret -N -B middleware"
35+
36+
post() {
37+
local user=$1 pass=$2 body=$3
38+
curl -sk -u "$user:$pass" -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST "$MW/command" -d "$body"
39+
echo
40+
}
41+
42+
echo "== Creating identity $NAME_ID ($IDENTITY_ID) =="
43+
post ss sa_secret "$(printf '{"meta":{"actor_id":null,"actor_institution":null},"command":{"name":"Identity:CreateIdentity","uuid":"%s","payload":{"id":"%s","name_id":"%s","institution":"%s","email":"%s@dev.openconext.local","common_name":"%s","preferred_locale":"en_GB"}}}' \
44+
"$(uuidgen)" "$IDENTITY_ID" "$NAME_ID" "$INSTITUTION" "$SLUG" "$SLUG")"
45+
46+
echo "== Proving possession of Demo GSSP token (gssf_id=$GSSF_ID) =="
47+
post ss sa_secret "$(printf '{"meta":{"actor_id":"%s","actor_institution":"%s"},"command":{"name":"Identity:ProveGssfPossession","uuid":"%s","payload":{"identity_id":"%s","second_factor_id":"%s","stepup_provider":"demo_gssp","gssf_id":"%s"}}}' \
48+
"$IDENTITY_ID" "$INSTITUTION" "$(uuidgen)" "$IDENTITY_ID" "$SECOND_FACTOR_ID" "$GSSF_ID")"
49+
50+
# Unlike yubikey/sms, GSSF possession (Identity:ProveGssfPossession) is proven-and-verified
51+
# in a single event (GssfPossessionProvenAndVerifiedEvent) -- no separate e-mail/nonce step.
52+
REG_CODE=$($DB -e "SELECT registration_code FROM verified_second_factor WHERE identity_id='$IDENTITY_ID' ORDER BY registration_requested_at DESC LIMIT 1;")
53+
if [ -z "$REG_CODE" ]; then
54+
echo "No verified_second_factor row found for $IDENTITY_ID -- VerifyEmail likely failed, see output above." >&2
55+
exit 1
56+
fi
57+
58+
echo "== Vetting (registration code $REG_CODE, authority $ACTOR_ID) =="
59+
post ra ra_secret "$(printf '{"meta":{"actor_id":"%s","actor_institution":"%s"},"command":{"name":"Identity:VetSecondFactor","uuid":"%s","payload":{"authority_id":"%s","identity_id":"%s","second_factor_id":"%s","registration_code":"%s","second_factor_type":"demo_gssp","second_factor_identifier":"%s","document_number":"123456","identity_verified":true}}}' \
60+
"$ACTOR_ID" "$INSTITUTION" "$(uuidgen)" "$ACTOR_ID" "$IDENTITY_ID" "$SECOND_FACTOR_ID" "$REG_CODE" "$GSSF_ID")"
61+
62+
VETTED=$($DB -e "SELECT id FROM vetted_second_factor WHERE identity_id='$IDENTITY_ID';")
63+
echo
64+
if [ -n "$VETTED" ]; then
65+
echo "Done. $SLUG now has a vetted Demo GSSP token (second_factor_id=$VETTED)."
66+
echo "Log in at https://ssp.dev.openconext.local/simplesaml/sp.php as ${SLUG}/${SLUG}, pick a Request LOA Demo GSSP satisfies, and select Demo GSSP as the second factor."
67+
else
68+
echo "Vetting did not produce a vetted_second_factor row -- check the command output above for an error." >&2
69+
exit 1
70+
fi

‎stepup/tests/behat/features/bootstrap/SecondFactorAuthContext.php‎

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ public function visitServiceProvider()
120120
}
121121
}
122122

123+
/**
124+
* @When I visit the service provider with service name :arg1
125+
*/
126+
public function visitServiceProviderWithServiceName(string $serviceName)
127+
{
128+
$this->minkContext->visit($this->spTestUrl);
129+
130+
$this->minkContext->fillField('idp', $this->activeIdp);
131+
$this->minkContext->fillField('sp', $this->activeSp);
132+
$this->minkContext->fillField('loa', $this->requiredLoa);
133+
$this->minkContext->fillField('mdui_displayname', $serviceName);
134+
135+
if ($this->activeIdp === self::SFO_IDP) {
136+
$this->minkContext->fillField('subject', self::TEST_NAMEID);
137+
}
138+
$this->minkContext->pressButton('Login');
139+
}
140+
123141
/**
124142
* @When I start an SFO authentication for :arg1 with GSSP extension subject :arg2 and institution :arg3
125143
*/
@@ -137,6 +155,38 @@ public function startASfoAuthenticationWithGsspExtension(string $userIdentifier,
137155
$this->minkContext->pressButton('Login');
138156
}
139157

158+
/**
159+
* @When I start an SFO authentication for :arg1 with service name :arg2
160+
*/
161+
public function startASfoAuthenticationWithServiceName(string $userIdentifier, string $serviceName)
162+
{
163+
$this->minkContext->visit($this->spTestUrl);
164+
$this->minkContext->fillField('idp', $this->activeIdp);
165+
$this->minkContext->fillField('sp', $this->activeSp);
166+
$this->minkContext->fillField('loa', $this->requiredLoa);
167+
$this->minkContext->fillField('subject', $userIdentifier);
168+
$this->minkContext->fillField('mdui_displayname', $serviceName);
169+
$this->minkContext->pressButton('Login');
170+
}
171+
172+
/**
173+
* @Then I see service name :arg1 on the GSSP authentication page
174+
*/
175+
public function iSeeServiceNameOnTheGsspAuthenticationPage(string $serviceName)
176+
{
177+
$this->minkContext->assertPageAddress('https://demogssp.dev.openconext.local/authentication');
178+
$this->minkContext->assertPageContainsText($serviceName);
179+
}
180+
181+
/**
182+
* @Then I see service name :arg1 on the GSSP registration page
183+
*/
184+
public function iSeeServiceNameOnTheGsspRegistrationPage(string $serviceName)
185+
{
186+
$this->minkContext->assertPageAddress('https://demogssp.dev.openconext.local/registration');
187+
$this->minkContext->assertPageContainsText($serviceName);
188+
}
189+
140190
/**
141191
* @When I start an SFO authentication for :arg1
142192
*/
@@ -342,13 +392,13 @@ public function authenticateUserYubikeyInGateway()
342392
$this->minkContext->assertPageAddress('https://gateway.dev.openconext.local/verify-second-factor/sfo/yubikey');
343393
}
344394
// Give an OTP
345-
$this->minkContext->fillField('gateway_verify_yubikey_otp_otp', 'ccccccdhgrbtucnfhrhltvfkchlnnrndcbnfnnljjdgf');
395+
$this->minkContext->fillField('gateway_verify_yubikey_yubikeyInput', 'ccccccdhgrbtucnfhrhltvfkchlnnrndcbnfnnljjdgf');
346396
// Simulate the enter press the yubikey otp generator
347-
$form = $this->minkContext->getSession()->getPage()->find('css', '[id="gateway_verify_yubikey_otp_otp"]');
397+
$form = $this->minkContext->getSession()->getPage()->find('css', '[id="gateway_verify_yubikey_yubikeyInput"]');
348398
if (!$form) {
349399
throw new ElementNotFoundException('Yubikey OTP Submit form could not be found on the page');
350400
}
351-
$this->minkContext->pressButton('gateway_verify_yubikey_otp_submit');
401+
$this->minkContext->pressButton('gateway_verify_yubikey_submit');
352402
// Pass through the 'return to sp' redirection page.
353403
$this->minkContext->pressButton('Submit');
354404
}
@@ -489,8 +539,20 @@ public function authenticateWithIdentityProviderFor($userName)
489539
$this->minkContext->fillField('password', $userName);
490540

491541
$this->minkContext->pressButton('Login');
492-
$this->minkContext->pressButton('Yes, continue');
542+
$this->pressConsentIfShown();
543+
}
493544

545+
/**
546+
* SimpleSAMLphp's consent module remembers a given SP+attribute-set combination for the
547+
* browser session, so a consent screen may or may not appear depending on what earlier
548+
* scenarios in the same feature already consented to.
549+
*/
550+
private function pressConsentIfShown(): void
551+
{
552+
try {
553+
$this->minkContext->pressButton('Yes, continue');
554+
} catch (ElementNotFoundException $e) {
555+
}
494556
}
495557

496558
public function authenticateWithIdentityProviderForWithStepup($userName)

‎stepup/tests/behat/features/bootstrap/SelfServiceContext.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ public function removeRecoveryToken(string $recoveryTokenType)
491491

492492
private function performYubikeyAuthentication()
493493
{
494-
$this->minkContext->fillField('gateway_verify_yubikey_otp_otp', 'ccccccdhgrbtfddefpkffhkkukbgfcdilhiltrrncmig');
494+
$this->minkContext->fillField('gateway_verify_yubikey_yubikeyInput', 'ccccccdhgrbtfddefpkffhkkukbgfcdilhiltrrncmig');
495495
$page = $this->minkContext->getSession()->getPage();
496-
$form = $page->find('css', 'form[name="gateway_verify_yubikey_otp"]');
496+
$form = $page->find('css', 'form[name="gateway_verify_yubikey"]');
497497
$form->submit();
498498
$this->minkContext->pressButton('Submit');
499499
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Tagged SKIP until Stepup-Gateway PR #624 (append_service_name_to_authnrequest) is merged
2+
# and released in the test image. (OpenConext-devssp's mdui_displayname field already merged
3+
# and is in the stock devssp image, so no local sp.php override is needed anymore.)
4+
# Until then, run locally with:
5+
# ./start-dev-env.sh gateway:<Stepup-Gateway checkout> demogssp:<Stepup-gssp-example checkout>
6+
# docker compose exec behat ./vendor/bin/behat --config config/behat.yml --tags='~@wip' features/gssp_service_name.feature
7+
@SKIP
8+
Feature: The GSSP shows the name of the service the user is authenticating for
9+
In order to know which service I am authenticating for
10+
As a user
11+
I want the GSSP authentication page to show the service name from the AuthnRequest
12+
13+
# Covers the cross-repo flow of the mdui:UIInfo service name:
14+
# the SP sends an AuthnRequest with an mdui:UIInfo/mdui:DisplayName extension,
15+
# the Stepup-Gateway (feature flag append_service_name_to_authnrequest)
16+
# reads it and forwards it in the proxy AuthnRequest to the GSSP, where the
17+
# GSSP (Stepup-gssp-example via Stepup-gssp-bundle and Stepup-saml-bundle)
18+
# displays it on the authentication page.
19+
Scenario: Service name from the AuthnRequest mdui:UIInfo is shown on the GSSP authentication page
20+
Given a service provider configured for second-factor-only
21+
And a user "jane-a-ra" identified by "urn:collab:person:institution-a.example.com:jane-a-ra" from institution "institution-a.example.com" with UUID "00000000-0000-4000-8000-000000000001"
22+
And the user "urn:collab:person:institution-a.example.com:jane-a-ra" has a vetted "demo-gssp" with identifier "gssp-identifier123"
23+
When I start an SFO authentication for "urn:collab:person:institution-a.example.com:jane-a-ra" with service name "Behat Test Service"
24+
Then I see service name "Behat Test Service" on the GSSP authentication page
25+
When I verify the "demo-gssp" second factor
26+
Then I am logged on the service provider
27+
28+
# Reuses the identity vetted in the previous scenario, like sfo.feature does.
29+
Scenario: No service name is shown when the AuthnRequest carries no mdui:UIInfo
30+
Given a service provider configured for second-factor-only
31+
When I start an SFO authentication for "urn:collab:person:institution-a.example.com:jane-a-ra"
32+
Then I should not see "Behat Test Service"
33+
When I verify the "demo-gssp" second factor
34+
Then I am logged on the service provider
35+
36+
# Gateway has three independent LoginService::singleSignOn implementations that each
37+
# read the mdui:UIInfo extension behind the same feature flag: GatewayBundle (plain
38+
# SSO, exercised here), SecondFactorOnlyBundle, and SamlStepupProviderBundle (both
39+
# exercised by the SFO scenarios above). Without this scenario, a regression in the
40+
# SSO copy specifically would go undetected even with the SFO scenarios passing.
41+
Scenario: Service name from the AuthnRequest mdui:UIInfo is shown on the GSSP authentication page via the plain SSO flow
42+
Given a service provider configured for single-signon
43+
And a user "Jane Toppan" identified by "urn:collab:person:institution-a.example.com:jane-a2" from institution "institution-a.example.com"
44+
And the user "urn:collab:person:institution-a.example.com:jane-a2" has a vetted "demo-gssp" with identifier "gssp-identifier-sso1"
45+
When I visit the service provider with service name "SSO Flow Service Name"
46+
And I authenticate as "jane-a2" with the identity provider
47+
Then I see service name "SSO Flow Service Name" on the GSSP authentication page
48+
When I verify the "demo-gssp" second factor
49+
Then I am logged on the service provider

0 commit comments

Comments
 (0)