Skip to content

Commit

Permalink
Merge pull request #40 from openeuropa/OPENEUROPA-1485
Browse files Browse the repository at this point in the history
OPENEUROPA-1485: Prevent blocked users from logging in through cas
  • Loading branch information
nagyad committed Jan 3, 2019
2 parents 675d3df + 065de08 commit 4e77412
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/Behat/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}
13 changes: 13 additions & 0 deletions tests/features/ecas-login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ 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
Given the user "chucknorris" is blocked
When I am on the homepage
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 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."
2 changes: 1 addition & 1 deletion tests/features/ecas-register.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 4e77412

Please sign in to comment.