Skip to content

Commit

Permalink
[Behat] Add scenarios for securing access to account and dashboard af…
Browse files Browse the repository at this point in the history
…ter logging out
  • Loading branch information
GSadee committed Mar 7, 2022
1 parent 94366fd commit 5dee3dc
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@customer_account
Feature: Securing access to the account after using the back button after logging out
In order to have my personal information secured
As a Customer
I want to be unable to access to the account by using the back button after logging out

Background:
Given the store operates on a single channel in "United States"
And I am a logged in customer
And I am browsing my orders

@ui @javascript @no-api
Scenario: Securing access to the account after using the back button after logging out
When I log out
And I go back one page in the browser
Then I should not see my orders
And I should be on the login page
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@admin_dashboard
Feature: Securing access to the administration panel after using the back button after logging out
In order to have administration panel secured
As an Administrator
I want to be unable to access to the administration panel by using the back button after logging out

Background:
Given the store operates on a single channel in "United States"
And I am logged in as an administrator
And I am on the administration dashboard

@ui @javascript @no-api
Scenario: Securing access to administration dashboard after using the back button after logging out
When I log out
And I go back one page in the browser
Then I should not see the administration dashboard
And I should be on the login page
27 changes: 26 additions & 1 deletion src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public function __construct(DashboardPageInterface $dashboardPage)
}

/**
* @Given I am on the administration dashboard
* @When I (try to )open administration dashboard
*/
public function iOpenAdministrationDashboard()
public function iOpenAdministrationDashboard(): void
{
try {
$this->dashboardPage->open();
Expand All @@ -56,6 +57,22 @@ public function iChooseChannel($channelName)
$this->dashboardPage->chooseChannel($channelName);
}

/**
* @When I log out
*/
public function iLogOut(): void
{
$this->dashboardPage->logOut();
}

/**
* @When I go back one page in the browser
*/
public function iGoBackOnePageInTheBrowser(): void
{
$this->dashboardPage->goBackInTheBrowser();
}

/**
* @Then I should see :number new orders
*/
Expand Down Expand Up @@ -103,4 +120,12 @@ public function iShouldSeeNewOrdersInTheList($number)
{
Assert::same($this->dashboardPage->getNumberOfNewOrdersInTheList(), (int) $number);
}

/**
* @Then I should not see the administration dashboard
*/
public function iShouldNotSeeTheAdministrationDashboard(): void
{
Assert::false($this->dashboardPage->isOpen());
}
}
8 changes: 8 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/LoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,12 @@ private function logInAgain($username, $password)
$this->loginPage->specifyPassword($password);
$this->loginPage->logIn();
}

/**
* @Then I should be on the login page
*/
public function iShouldBeOnTheLoginPage(): void
{
Assert::true($this->loginPage->isOpen());
}
}
19 changes: 18 additions & 1 deletion src/Sylius/Behat/Context/Ui/Shop/AccountContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong()
}

/**
* @Given I am browsing my orders
* @When I browse my orders
*/
public function iBrowseMyOrders()
public function iBrowseMyOrders(): void
{
$this->orderIndexPage->open();
}
Expand Down Expand Up @@ -531,4 +532,20 @@ public function iShouldNotBeLoggedIn(): void

throw new \InvalidArgumentException('Dashboard has been openned, but it shouldn\'t as customer should not be logged in');
}

/**
* @Then I should not see my orders
*/
public function iShouldNotSeeMyOrders(): void
{
Assert::false($this->orderIndexPage->isOpen());
}

/**
* @Then I should be on the login page
*/
public function iShouldBeOnTheLoginPage(): void
{
Assert::true($this->loginPage->isOpen());
}
}
8 changes: 8 additions & 0 deletions src/Sylius/Behat/Context/Ui/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public function iDeleteAccount($email)
$this->customerShowPage->deleteAccount();
}

/**
* @When I go back one page in the browser
*/
public function iGoBackOnePageInTheBrowser(): void
{
$this->homePage->goBackInTheBrowser();
}

/**
* @Then the user account should be deleted
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Page/Admin/DashboardPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function chooseChannel(string $channelName): void
$this->getElement('channel_choosing_link', ['%channelName%' => $channelName])->click();
}

public function goBackInTheBrowser(): void
{
$this->getDriver()->back();
}

public function getRouteName(): string
{
return 'sylius_admin_dashboard';
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Page/Admin/DashboardPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public function isSectionWithLabelVisible(string $name): bool;
public function logOut(): void;

public function chooseChannel(string $channelName): void;

public function goBackInTheBrowser(): void;
}
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Page/Shop/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ function (NodeElement $element) {
);
}

public function goBackInTheBrowser(): void
{
$this->getDriver()->back();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Page/Shop/HomePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public function getAvailableLocales(): array;
public function switchLocale(string $localeCode): void;

public function getLatestProductsNames(): array;

public function goBackInTheBrowser(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ default:
- sylius.behat.context.ui.shop.checkout.shipping
- sylius.behat.context.ui.shop.currency
- sylius.behat.context.ui.shop.homepage
- sylius.behat.context.ui.user

filters:
tags: "@customer_account&&@ui"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ default:
- sylius.behat.context.transform.shared_storage

- sylius.behat.context.ui.admin.dashboard
- sylius.behat.context.ui.admin.login
- sylius.behat.context.ui.admin.notification

filters:
Expand Down

0 comments on commit 5dee3dc

Please sign in to comment.