Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/packages/ci/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ parameters:
api.users.nameidlookup.password: secret
feature_api_users_nameid_lookup: true
feature_hide_bookmarkable_url: true
wayf.remember_choice: false
feature_enable_wayf_remember_choice_per_idp: true
auth.log.attributes:
uid: 'urn:mace:dir:attribute-def:uid'
encryption_keys:
Expand Down
4 changes: 4 additions & 0 deletions src/OpenConext/EngineBlock/Metadata/EmptyMduiElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class EmptyMduiElement implements MultilingualElement, JsonSerializable
{
private $name;

public $height = null;
public $width = null;
public $url = null;

public function __construct(string $name)
{
$this->name = $name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use DOMDocument;
use DOMElement;
use DOMXPath;
use OpenConext\EngineBlock\Service\Wayf\RememberedIdpCookie;
use OpenConext\EngineBlockBundle\Sbs\Msg;
use OpenConext\EngineBlockFunctionalTestingBundle\Fixtures\DataStore\AbstractDataStore;
use OpenConext\EngineBlockFunctionalTestingBundle\Fixtures\FunctionalTestingAttributeAggregationClient;
Expand All @@ -39,6 +40,7 @@
use RuntimeException;
use SAML2\Constants;
use SAML2\DOMDocumentFactory;
use Symfony\Component\BrowserKit\Cookie;

/**
* @SuppressWarnings(PHPMD.TooManyPublicMethods) Both set up and tasks can be a lot...
Expand Down Expand Up @@ -370,6 +372,19 @@ public function anIdpInitiatedSingleSignOnForSpIsInvalidParameterByIdP($spName,
* @Given /^I select "([^"]*)" on the WAYF$/
*/
public function iSelectOnTheWAYF($idpName)
{
$this->selectIdpOnTheWayf($idpName, false);
}

/**
* @Given /^I select "([^"]*)" on the WAYF and remember my choice$/
*/
public function iSelectOnTheWAYFAndRememberMyChoice($idpName)
{
$this->selectIdpOnTheWayf($idpName, true);
}

private function selectIdpOnTheWayf(string $idpName, bool $rememberChoice): void
{
/** @var MockIdentityProvider $mockIdp */
$mockIdp = $this->mockIdpRegistry->get($idpName);
Expand All @@ -380,13 +395,29 @@ public function iSelectOnTheWAYF($idpName)
);
}

$selector = '[data-entityid="' . $mockIdp->entityId() . '"] button.idp__submit';
$selector = '[data-entityid="' . $mockIdp->entityId() . '"]';
$idpContainer = $this->getMinkContext()->getSession()->getPage()->find('css', $selector);

$mink = $this->getMinkContext()->getSession()->getPage();
$button = $mink->find('css', $selector);
if (!$idpContainer) {
throw new RuntimeException(sprintf('Unable to find idp container with selector "%s"', $selector));
}

if ($rememberChoice) {
$rememberChoiceField = $idpContainer->find('css', 'input[name="rememberChoice"]');

if (!$rememberChoiceField) {
throw new RuntimeException(
sprintf('Unable to find hidden rememberChoice field within selector "%s"', $selector)
);
}

$rememberChoiceField->setValue('1');
}

$button = $idpContainer->find('css', 'button.idp__submit');

if (!$button) {
throw new RuntimeException(sprintf('Unable to find button with selector "%s"', $selector));
throw new RuntimeException(sprintf('Unable to find button with selector "%s button.idp__submit"', $selector));
}

$button->click();
Expand Down Expand Up @@ -510,6 +541,15 @@ public function iLoseMySession()
// set unknown session id to prevent session not found exception
$session->setCookie(session_name(), '000000');
}

/**
* @Given /^I start a new browser session$/
*/
public function iStartANewBrowserSession()
{
$this->getMinkContext()->getSession()->setCookie(session_name(), null);
}

/**
* @Given /^I lose my session and reload$/
*/
Expand Down Expand Up @@ -726,6 +766,91 @@ public function aLangCookieShouldBeSetWithValue($locale)
}
}

/**
* @Then /^the "rememberedidps" cookie should be set$/
*/
public function theRememberedIdpsCookieShouldBeSet()
{
$cookie = $this->getMinkContext()->getSession()->getCookie(RememberedIdpCookie::NAME);

if ($cookie === null) {
throw new ExpectationException(
'The rememberedidps cookie has not been set',
$this->getMinkContext()->getSession()->getDriver()
);
}
}

/**
* @Then /^the "rememberedidps" cookie should not be set$/
*/
public function theRememberedIdpsCookieShouldNotBeSet()
{
$cookie = $this->getMinkContext()->getSession()->getCookie(RememberedIdpCookie::NAME);

if ($cookie !== null) {
throw new ExpectationException(
'The rememberedidps cookie should not be set, but it is',
$this->getMinkContext()->getSession()->getDriver()
);
}
}

/**
* @Then /^the "rememberedidps" cookie should remember "([^"]*)" for SP "([^"]*)"$/
*/
public function theRememberedIdpsCookieShouldRemember($idpName, $spName)
{
$cookie = $this->getMinkContext()->getSession()->getCookie(RememberedIdpCookie::NAME);
$entries = $cookie === null ? null : json_decode((string) gzinflate((string) base64_decode($cookie, true)), true);
$spEntityId = $this->mockSpRegistry->get($spName)->entityId();
$idpEntityId = $this->mockIdpRegistry->get($idpName)->entityId();

if (!is_array($entries) || ($entries[$spEntityId]['idp'] ?? null) !== $idpEntityId) {
throw new ExpectationException(
sprintf('The rememberedidps cookie does not remember "%s" for SP "%s"', $idpName, $spName),
$this->getMinkContext()->getSession()->getDriver()
);
}
}

/**
* @Given /^my browser has remembered IdP "([^"]*)" for SP "([^"]*)"$/
*/
public function myBrowserHasRememberedIdpForSp($idpName, $spName)
{
$this->setRememberedIdpsCookie($idpName, $spName, time() + 3600);
}

/**
* @Given /^my browser has remembered IdP "([^"]*)" for SP "([^"]*)" but that choice has expired$/
*/
public function myBrowserHasRememberedIdpForSpButItHasExpired($idpName, $spName)
{
$this->setRememberedIdpsCookie($idpName, $spName, time() - 3600);
}

private function setRememberedIdpsCookie(string $idpName, string $spName, int $expires): void
{
$entries = [
$this->mockSpRegistry->get($spName)->entityId() => [
'idp' => $this->mockIdpRegistry->get($idpName)->entityId(),
'expires' => $expires,
],
];

$cookie = new Cookie(
RememberedIdpCookie::NAME,
base64_encode(gzdeflate(json_encode($entries))),
null,
'/',
parse_url($this->engineBlockDomain, PHP_URL_HOST),
true
);

$this->getMinkContext()->getSession()->getDriver()->getClient()->getCookieJar()->set($cookie);
}

/**
* @Given /^I have a locale cookie containing "([^"]*)"$/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,19 @@ public function spIsConfiguredToDisplayOnlyConnectedIdps($spName)
->save();
}

/**
* @Given /^SP "([^"]*)" allows remembering the WAYF choice$/
* @param string $spName
*/
public function spAllowsRememberingTheWayfChoice($spName)
{
$sp = $this->anUnregisteredServiceProviderNamed($spName);

$this->serviceRegistryFixture
->allowWayfRememberChoiceForSp($sp->entityId())
->save();
}

/**
* @Given /^SP "([^"]*)" scopes its request to IDP "([^"]*)"$/
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Feature: Per-SP remembered WAYF choice
In order to not have to pick my IdP every time I log in to the same SP
As a user
I want EngineBlock to remember my previous IdP choice for that SP

# This is the per-SP remember-choice feature (feature_enable_wayf_remember_choice_per_idp),
# not the older, session-based "wayf.remember_choice" feature: the two are mutually
# exclusive and cannot both be enabled.
#
# The choice is stored in the "rememberedidps" cookie, so it must survive the loss of the
# EngineBlock session. The second login in every scenario therefore starts without an
# existing EB session: "I start a new browser session" clears only the PHP session
# cookie and leaves "rememberedidps" in place. Without that step the legacy session
# based mechanism could skip the WAYF and the scenario would prove nothing.

Background:
Given an EngineBlock instance on "dev.openconext.local"
And no registered SPs
And no registered Idps
And an Identity Provider named "Dummy-IdP"
And an Identity Provider named "Second-IdP"
And a Service Provider named "Remembering-SP"
And SP "Remembering-SP" allows remembering the WAYF choice
And a Service Provider named "Non-Remembering-SP"

Scenario: Remembering a choice skips the WAYF on a subsequent login
Comment thread
johanib marked this conversation as resolved.
Resolved
When I log in at "Remembering-SP"
And I select "Dummy-IdP" on the WAYF and remember my choice
And I pass through EngineBlock
And I pass through the IdP
Then the "rememberedidps" cookie should remember "Dummy-IdP" for SP "Remembering-SP"
When I give my consent
And I pass through EngineBlock
Then the url should match "functional-testing/Remembering-SP/acs"
When I start a new browser session
And I log in at "Remembering-SP"
And I pass through EngineBlock
Then the url should not match "authentication/proxy/wayf"
And the url should match "Dummy-IdP/sso"
When I pass through the IdP
And I pass through EngineBlock
Then the url should match "functional-testing/Remembering-SP/acs"

Scenario: The remembered choice is scoped per SP
Given a Service Provider named "Other-Remembering-SP"
And SP "Other-Remembering-SP" allows remembering the WAYF choice
And my browser has remembered IdP "Dummy-IdP" for SP "Remembering-SP"
When I log in at "Other-Remembering-SP"
Then I should see "Select an account to login to"
When I log in at "Remembering-SP"
And I pass through EngineBlock
Then the url should match "Dummy-IdP/sso"

Scenario: An SP without the coin never gets the choice remembered
When I log in at "Non-Remembering-SP"
And I select "Dummy-IdP" on the WAYF and remember my choice
And I pass through EngineBlock
And I pass through the IdP
Then the "rememberedidps" cookie should not be set
When I give my consent
And I pass through EngineBlock
Then the url should match "functional-testing/Non-Remembering-SP/acs"
When I start a new browser session
And I log in at "Non-Remembering-SP"
Then I should see "Select an account to login to"

Scenario: A remembered IdP that is no longer connected to the SP is ignored
Given an Identity Provider named "Third-IdP"
And my browser has remembered IdP "Dummy-IdP" for SP "Remembering-SP"
And SP "Remembering-SP" is not connected to IdP "Dummy-IdP"
When I log in at "Remembering-SP"
Then I should see "Select an account to login to"

Scenario: An expired remembered choice is ignored
Given my browser has remembered IdP "Dummy-IdP" for SP "Remembering-SP" but that choice has expired
When I log in at "Remembering-SP"
Then I should see "Select an account to login to"

Scenario: The reset endpoint clears a remembered choice
Given my browser has remembered IdP "Dummy-IdP" for SP "Remembering-SP"
When I go to Engineblock URL "/reset-remember-wayf"
Then the "rememberedidps" cookie should not be set
When I log in at "Remembering-SP"
Then I should see "Select an account to login to"

Scenario: The cookie removal page lists and removes the remembered choice
Given my browser has remembered IdP "Dummy-IdP" for SP "Remembering-SP"
When I go to Engineblock URL "/authentication/idp/remove-cookies"
Then the response should contain 'rememberedidps'
When I press "remove_rememberedidps"
Then the "rememberedidps" cookie should not be set
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ public function displayUnconnectedIdpsForSp($entityId, $displayUnconnected = tru
return $this;
}

public function allowWayfRememberChoiceForSp($entityId)
{
$this->setCoin($this->getServiceProvider($entityId), 'wayfRememberChoice', true);

return $this;
}

public function disconnectSp($spEntityId, $idpEntityId)
{
$sp = $this->getServiceProvider($spEntityId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This doesn't run in CI, which is why it's skipped. You can run it locally by setting the wayf.remember_choice flag to true in parameters.yaml.
* This doesn't run in CI, which is why it's skipped. You can run it locally by setting either the wayf.remember_choice flag or the feature_enable_wayf_remember_choice_per_idp flag to true in parameters.yaml.
*/
context.skip('Cookie removal page verify a11y', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
idpSelector,
rememberChoiceId,
rememberChoicePerIdpClass,
rememberChoiceTooltipToggleSelector,
rememberChoiceTooltipValueSelector
Expand All @@ -15,6 +17,12 @@ context('WAYF per-SP remember my choice', () => {
cy.get(rememberChoiceTooltipToggleSelector).should('exist');
});

it('Renders the per-SP checkbox when only rememberChoicePerIdp is passed', () => {
cy.visit('https://engine.dev.openconext.local/functional-testing/wayf?connectedIdps=5&rememberChoicePerIdp=true');
cy.get(`.${rememberChoicePerIdpClass}`).should('exist');
cy.onPage('Remember my choice');
});

it('Hides the tooltip content until the toggle is activated', () => {
cy.visit('https://engine.dev.openconext.local/functional-testing/wayf?connectedIdps=5&rememberChoiceFeature=true&rememberChoicePerIdp=true');
cy.get(rememberChoiceTooltipValueSelector).should('not.be.visible');
Expand Down Expand Up @@ -50,5 +58,38 @@ context('WAYF per-SP remember my choice', () => {
cy.get(rememberChoiceTooltipToggleSelector).should('not.exist');
cy.onPage('Remember my choice');
});

it('Sets the hidden rememberChoice field to 1 on the submitted IdP form when the checkbox is checked', () => {
cy.visit('https://engine.dev.openconext.local/functional-testing/wayf?connectedIdps=1&addDiscoveries=0&rememberChoiceFeature=true&rememberChoicePerIdp=true');
cy.window().then((win) => {
cy.stub(win.HTMLFormElement.prototype, 'submit').as('formSubmit');
});
cy.get(`#${rememberChoiceId}`).check();
cy.get(idpSelector).first().click({force: true});
cy.get('@formSubmit').should('have.been.calledOnce');
cy.get(idpSelector).first().find('input[name="rememberChoice"]').should('have.value', '1');
});

it('Leaves the hidden rememberChoice field at 0 on the submitted IdP form when the checkbox is left unchecked', () => {
cy.visit('https://engine.dev.openconext.local/functional-testing/wayf?connectedIdps=1&addDiscoveries=0&rememberChoiceFeature=true&rememberChoicePerIdp=true');
cy.window().then((win) => {
cy.stub(win.HTMLFormElement.prototype, 'submit').as('formSubmit');
});
cy.get(idpSelector).first().click({force: true});
cy.get('@formSubmit').should('have.been.calledOnce');
cy.get(idpSelector).first().find('input[name="rememberChoice"]').should('have.value', '0');
});

it('Sets the legacy rememberchoice cookie when the checkbox is checked for the global variant', () => {
cy.clearCookie('rememberchoice');
cy.visit('https://engine.dev.openconext.local/functional-testing/wayf?connectedIdps=1&addDiscoveries=0&rememberChoiceFeature=true&rememberChoicePerIdp=false');
cy.window().then((win) => {
cy.stub(win.HTMLFormElement.prototype, 'submit').as('formSubmit');
});
cy.get(`#${rememberChoiceId}`).check();
cy.get(idpSelector).first().click({force: true});
cy.get('@formSubmit').should('have.been.calledOnce');
cy.getCookie('rememberchoice').should('exist');
});
});
});
Loading