From 9ad72b1555654479fc64dbab35b15f1803f487e2 Mon Sep 17 00:00:00 2001 From: Imanol Date: Wed, 12 Dec 2018 17:13:05 +0000 Subject: [PATCH 1/3] OPENEUROPA-1485: Add drupal patch to prevent blocked users from logging in. --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 6522e72..3295be5 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,11 @@ "build/profiles/contrib/{$name}": ["type:drupal-profile"], "build/modules/contrib/{$name}": ["type:drupal-module"], "build/themes/contrib/{$name}": ["type:drupal-theme"] + }, + "patches": { + "drupal/cas": { + "https://www.drupal.org/project/cas/issues/3020014": "https://www.drupal.org/files/issues/2018-12-12/3020014-2.patch" + } } }, "config": { From 1e96920c2e0d019e30f142c8460dff5adc000670 Mon Sep 17 00:00:00 2001 From: Imanol Date: Mon, 17 Dec 2018 12:36:19 +0000 Subject: [PATCH 2/3] OPENEUROPA-1485: Added behat test. --- behat.yml.dist | 2 +- tests/Behat/DrupalContext.php | 34 +++++++++++++++++++++++++++++++ tests/features/ecas-login.feature | 27 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/Behat/DrupalContext.php diff --git a/behat.yml.dist b/behat.yml.dist index c4d070e..f5d392e 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -5,8 +5,8 @@ default: - %paths.base%/tests/features contexts: - Drupal\DrupalExtension\Context\MinkContext - - Drupal\DrupalExtension\Context\DrupalContext - Drupal\Tests\oe_authentication\Behat\AuthenticationContext + - Drupal\Tests\oe_authentication\Behat\DrupalContext extensions: Behat\MinkExtension: goutte: ~ diff --git a/tests/Behat/DrupalContext.php b/tests/Behat/DrupalContext.php new file mode 100644 index 0000000..9132680 --- /dev/null +++ b/tests/Behat/DrupalContext.php @@ -0,0 +1,34 @@ +block(); + $user->save(); + } + } + +} diff --git a/tests/features/ecas-login.feature b/tests/features/ecas-login.feature index 745c38c..de546a3 100644 --- a/tests/features/ecas-login.feature +++ b/tests/features/ecas-login.feature @@ -34,3 +34,30 @@ Feature: Login through OE Authentication And I should not see the link "My account" And I should not see the link "Log out" And I should see the link "Log in" + + Scenario: A blocked user should not be able to log in + When I am on the homepage + And I click "Log in" + And I click "European Commission" + + # Redirected to the mock server. + And I fill in "Username or e-mail address" with "texasranger@chuck_norris.com.eu" + And I fill in "Password" with "Qwerty098" + And I press the "Login!" button + + # Redirected back to Drupal. + Then I should see "You have been logged in." + And I should see the link "My account" + And I should see the link "Log out" + And I should not see the link "Log in" + + # After being blocked a user is logged out. + When the user "chucknorris" is blocked + And I reload the page + And I should see the link "Log in" + And I should not see the link "Log out" + + # When I try to log in again I will be denied access. + When I click "Log in" + And I press "Proceed" + Then I should see "There was a problem logging in, please contact a site administrator." From 065de085f8c1a1c48a6fe25e3d045142d65cdb9a Mon Sep 17 00:00:00 2001 From: Imanol Eguskiza Date: Tue, 18 Dec 2018 12:31:39 +0100 Subject: [PATCH 3/3] OPENEUROPA-1485: Fix code review comments. --- behat.yml.dist | 2 +- composer.json | 5 ---- tests/Behat/AuthenticationContext.php | 25 ++++++++++++++++++++ tests/Behat/DrupalContext.php | 34 --------------------------- tests/features/ecas-login.feature | 24 ++++--------------- tests/features/ecas-register.feature | 2 +- 6 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 tests/Behat/DrupalContext.php diff --git a/behat.yml.dist b/behat.yml.dist index f5d392e..c4d070e 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -5,8 +5,8 @@ default: - %paths.base%/tests/features contexts: - Drupal\DrupalExtension\Context\MinkContext + - Drupal\DrupalExtension\Context\DrupalContext - Drupal\Tests\oe_authentication\Behat\AuthenticationContext - - Drupal\Tests\oe_authentication\Behat\DrupalContext extensions: Behat\MinkExtension: goutte: ~ diff --git a/composer.json b/composer.json index 3295be5..6522e72 100644 --- a/composer.json +++ b/composer.json @@ -53,11 +53,6 @@ "build/profiles/contrib/{$name}": ["type:drupal-profile"], "build/modules/contrib/{$name}": ["type:drupal-module"], "build/themes/contrib/{$name}": ["type:drupal-theme"] - }, - "patches": { - "drupal/cas": { - "https://www.drupal.org/project/cas/issues/3020014": "https://www.drupal.org/files/issues/2018-12-12/3020014-2.patch" - } } }, "config": { diff --git a/tests/Behat/AuthenticationContext.php b/tests/Behat/AuthenticationContext.php index 4990e16..e485415 100644 --- a/tests/Behat/AuthenticationContext.php +++ b/tests/Behat/AuthenticationContext.php @@ -35,4 +35,29 @@ public function setConfigProxyInitialize(): void { $this->setConfig('cas.settings', 'proxy.initialize', TRUE); } + /** + * Blocks a user given its username. + * + * @var string $username + * The name of the user to be blocked. + * + * @When the user :username is blocked + * + * @throws \Exception + * Thrown when the user with the given name does not exist. + */ + public function blockUser(string $username): void { + $users = \Drupal::entityTypeManager() + ->getStorage('user') + ->loadByProperties([ + 'name' => $username, + ]); + /** @var \Drupal\user\Entity\User $user */ + $user = $users ? reset($users) : FALSE; + if ($user) { + $user->block(); + $user->save(); + } + } + } diff --git a/tests/Behat/DrupalContext.php b/tests/Behat/DrupalContext.php deleted file mode 100644 index 9132680..0000000 --- a/tests/Behat/DrupalContext.php +++ /dev/null @@ -1,34 +0,0 @@ -block(); - $user->save(); - } - } - -} diff --git a/tests/features/ecas-login.feature b/tests/features/ecas-login.feature index de546a3..69ba5e7 100644 --- a/tests/features/ecas-login.feature +++ b/tests/features/ecas-login.feature @@ -36,28 +36,14 @@ Feature: Login through OE Authentication And I should see the link "Log in" Scenario: A blocked user should not be able to log in + Given the user "chucknorris" is blocked When I am on the homepage - And I click "Log in" - And I click "European Commission" - - # Redirected to the mock server. - And I fill in "Username or e-mail address" with "texasranger@chuck_norris.com.eu" - And I fill in "Password" with "Qwerty098" - And I press the "Login!" button - - # Redirected back to Drupal. - Then I should see "You have been logged in." - And I should see the link "My account" - And I should see the link "Log out" - And I should not see the link "Log in" - - # After being blocked a user is logged out. - When the user "chucknorris" is blocked - And I reload the page - And I should see the link "Log in" + Then I should see the link "Log in" And I should not see the link "Log out" # When I try to log in again I will be denied access. When I click "Log in" - And I press "Proceed" + And I fill in "Username or e-mail address" with "texasranger@chuck_norris.com.eu" + And I fill in "Password" with "Qwerty098" + And I press the "Login!" button Then I should see "There was a problem logging in, please contact a site administrator." diff --git a/tests/features/ecas-register.feature b/tests/features/ecas-register.feature index d124947..4b0d1f5 100644 --- a/tests/features/ecas-register.feature +++ b/tests/features/ecas-register.feature @@ -9,4 +9,4 @@ Feature: Register through OE Authentication And I visit "/user/register" # Redirected to the Ecas mockup server. - Then I should see "Service Create an account" + Then I should see "Create an account"