Skip to content

Commit

Permalink
add behat tests from the expirychecker repo
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Apr 15, 2024
1 parent bffa321 commit 93fcfbe
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 48 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ENV SSP_PATH /data/vendor/simplesamlphp/simplesamlphp

# Copy modules into simplesamlphp
COPY modules/ $SSP_PATH/modules
COPY behat.yml .

# Copy in SSP override files
RUN mv $SSP_PATH/www/index.php $SSP_PATH/www/ssp-index.php
Expand Down
17 changes: 17 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
default:
suites:
dictionary_features:
paths: [ '%paths.base%//features//dictionary-overrides.feature' ]
contexts: [ 'FeatureContext' ]
expiry_features:
paths: [ '%paths.base%//features//expirychecker.feature' ]
contexts: [ 'ExpiryContext' ]
material_features:
paths: [ '%paths.base%//features//material.feature' ]
contexts: [ 'FeatureContext' ]
mfa_features:
paths: [ '%paths.base%//features//mfa.feature' ]
contexts: [ 'FeatureContext' ]
profilereview_features:
paths: [ '%paths.base%//features//profilereview.feature' ]
contexts: [ 'FeatureContext' ]
23 changes: 21 additions & 2 deletions development/idp-local/config/authsources.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
gmdate('YmdHis\Z', strtotime('+6 months')), // Distant future
],
],
'near_future:a' => [
'near_future:b' => [
'eduPersonPrincipalName' => ['[email protected]'],
'sn' => ['Future'],
'givenName' => ['Near'],
Expand All @@ -35,7 +35,7 @@
gmdate('YmdHis\Z', strtotime('+1 day')), // Very soon
],
],
'already_past:a' => [
'already_past:c' => [
'eduPersonPrincipalName' => ['[email protected]'],
'sn' => ['Past'],
'givenName' => ['Already'],
Expand All @@ -46,5 +46,24 @@
gmdate('YmdHis\Z', strtotime('-1 day')), // In the past
],
],
'missing_exp:d' => [
'eduPersonPrincipalName' => ['[email protected]'],
'sn' => ['Expiration'],
'givenName' => ['Missing'],
'mail' => ['[email protected]'],
'employeeNumber' => ['44444'],
'cn' => ['MISSING_EXP'],
],
'invalid_exp:e' => [
'eduPersonPrincipalName' => ['[email protected]'],
'sn' => ['Expiration'],
'givenName' => ['Invalid'],
'mail' => ['[email protected]'],
'employeeNumber' => ['55555'],
'cn' => ['INVALID_EXP'],
'schacExpiryDate' => [
'invalid'
],
],
],
];
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ services:
- ./dockerbuild/run-tests.sh:/data/run-tests.sh
- ./dockerbuild/apply-dictionaries-overrides.php:/data/apply-dictionaries-overrides.php
- ./features:/data/features
- ./behat.yml:/data/behat.yml
- ./tests:/data/tests
- ./modules/expirychecker:/data/vendor/simplesamlphp/simplesamlphp/modules/expirychecker
command: ["/data/run-tests.sh"]
Expand Down
5 changes: 1 addition & 4 deletions dockerbuild/run-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@ whenavail "ssp-idp1.local" 80 10 echo IDP 1 ready
whenavail "ssp-sp1.local" 80 10 echo SP 1 ready

./vendor/bin/behat \
--append-snippets \
--snippets-for=FeatureContext \
--no-interaction \
--stop-on-failure #\
#--strict
--stop-on-failure
46 changes: 13 additions & 33 deletions features/bootstrap/ExpiryContext.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<?php
namespace Sil\SspExpiryChecker\Behat\context;

use Behat\Behat\Context\Context;
use Behat\Mink\Driver\GoutteDriver;
use Behat\Mink\Element\DocumentElement;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Session;
Expand All @@ -11,32 +7,19 @@
/**
* Defines application features from the specific context.
*/
class ExpiryContext implements Context
class ExpiryContext extends FeatureContext
{
protected $username = null;
protected $password = null;

/**
* The browser session, used for interacting with the website.
*
* @var Session
*/
protected $session;

/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
$driver = new GoutteDriver();
$this->session = new Session($driver);
$this->session->start();
}



/**
* Assert that the given page has a form that contains the given text.
*
Expand All @@ -58,7 +41,7 @@ protected function assertFormContains($text, $page)
$page->getHtml()
));
}

/**
* Assert that the given page does NOT have a form that contains the given
* text.
Expand All @@ -80,7 +63,7 @@ protected function assertFormNotContains($text, $page)
}
}
}

/**
* Get the login button from the given page.
*
Expand Down Expand Up @@ -117,20 +100,17 @@ public function iProvideCredentialsThatWillExpireInTheDistantFuture()
*/
public function iLogin()
{
$this->session->visit('http://sp/module.php/core/authenticate.php?as=ssp-hub-idp');
$page = $this->session->getPage();
$page->fillField('username', $this->username);
$page->fillField('password', $this->password);
$this->submitLoginForm($page);
$this->fillField('username', $this->username);
$this->fillField('password', $this->password);
$this->pressButton('Login');
}

/**
* @Then I should end up at my intended destination
*/
public function iShouldEndUpAtMyIntendedDestination()
{
$page = $this->session->getPage();
Assert::assertContains('Your attributes', $page->getHtml());
$this->assertPageBodyContainsText('Your attributes');
}

/**
Expand All @@ -151,7 +131,7 @@ public function iShouldSeeAWarningThatMyPasswordWillExpireSoon()
$page = $this->session->getPage();
Assert::assertContains('will expire', $page->getHtml());
}

/**
* Submit the login form, including the secondary page's form (if
* simpleSAMLphp shows another page because JavaScript isn't supported).
Expand All @@ -162,13 +142,13 @@ protected function submitLoginForm($page)
{
$loginButton = $this->getLoginButton($page);
$loginButton->click();

// SimpleSAMLphp 1.15 markup for secondary page:
$postLoginSubmitButton = $page->findButton('postLoginSubmitButton');
if ($postLoginSubmitButton instanceof NodeElement) {
$postLoginSubmitButton->click();
} else {

// SimpleSAMLphp 1.14 markup for secondary page:
$body = $page->find('css', 'body');
if ($body instanceof NodeElement) {
Expand Down
14 changes: 7 additions & 7 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class FeatureContext extends MinkContext
private const HUB_BAD_AUTH_SOURCE_URL = 'http://ssp-hub.local/module.php/core/authenticate.php?as=wrong';
private const HUB_DISCO_URL = 'http://ssp-hub.local/module.php/core/authenticate.php?as=hub-discovery';
private const HUB_HOME_URL = 'http://ssp-hub.local';
private const SP1_LOGIN_PAGE = 'http://ssp-sp1.local/module.php/core/authenticate.php?as=ssp-hub';
protected const SP1_LOGIN_PAGE = 'http://ssp-sp1.local/module.php/core/authenticate.php?as=ssp-hub';

/** @var Session */
private $session;
protected $session;

public function __construct()
{
Expand Down Expand Up @@ -161,19 +161,19 @@ public function iShouldSeeAPageIndicatingThatISuccessfullyLoggedIn()
$this->assertPageBodyContainsText('Your attributes');
}

private function assertPageBodyContainsText(string $expectedText)
protected function assertPageBodyContainsText(string $expectedText)
{
$page = $this->session->getPage();
$body = $page->find('css', 'body');
Assert::contains($body->getText(), $expectedText);
}

/**
* @When I log in as a user who's password is about to expire
* @When I log in as a user whose password is about to expire
*/
public function iLogInAsAUserWhosPasswordIsAboutToExpire()
{
$this->logInAs('near_future', 'a');
$this->logInAs('near_future', 'b');
}

/**
Expand All @@ -185,11 +185,11 @@ public function iShouldSeeAPageWarningMeThatMyPasswordIsAboutToExpire()
}

/**
* @When I log in as a user who's password has expired
* @When I log in as a user whose password has expired
*/
public function iLogInAsAUserWhosPasswordHasExpired()
{
$this->logInAs('already_past', 'a');
$this->logInAs('already_past', 'c');
}

/**
Expand Down
33 changes: 31 additions & 2 deletions features/expirychecker.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,38 @@ Feature: Expiry Checker module
Then I should see a page indicating that I successfully logged in

Scenario: Password is about to expire
When I log in as a user who's password is about to expire
When I log in as a user whose password is about to expire
Then I should see a page warning me that my password is about to expire

Scenario: Password has expired
When I log in as a user who's password has expired
When I log in as a user whose password has expired
Then I should see a page telling me that my password has expired

Scenario: Password will expire in the distant future
Given I provide credentials that will expire in the distant future
When I login
Then I should end up at my intended destination

Scenario: Password will expire tomorrow
Given I provide credentials that will expire very soon
When I login
Then I should see a warning that my password will expire soon
And there should be a way to go change my password now
And there should be a way to continue without changing my password

Scenario: Password has expired
Given I provide credentials that have expired
When I login
Then I should see a message that my password has expired
And there should be a way to go change my password now
But there should NOT be a way to continue without changing my password

Scenario: Reject missing expiration date
Given I provide credentials that have no password expiration date
When I login
Then I should see an error message

Scenario: Reject invalid expiration date
Given I provide credentials that have an invalid password expiration date
When I login
Then I should see an error message

0 comments on commit 93fcfbe

Please sign in to comment.