Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI tests for reset password #31168

Merged
merged 1 commit into from
Apr 19, 2018
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
8 changes: 8 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pipeline:
- SKELETON_DIR=/drone/src/tests/acceptance/webUISkeleton
- SELENIUM_PORT=4444
- PLATFORM=Linux
- MAILHOG_HOST=email
commands:
- bash tests/travis/start_ui_tests.sh --remote
when:
Expand Down Expand Up @@ -324,6 +325,12 @@ services:
matrix:
FILES_EXTERNAL_TYPE: swift

email:
image: mailhog/mailhog
pull: true
when:
matrix:
USE_EMAIL: true
matrix:
include:

Expand Down Expand Up @@ -505,6 +512,7 @@ matrix:
INSTALL_SERVER: true
CHOWN_SERVER: true
OWNCLOUD_LOG: true
USE_EMAIL: true

- PHP_VERSION: 7.1
TEST_SUITE: selenium
Expand Down
23 changes: 23 additions & 0 deletions tests/TestHelpers/EmailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ public static function getEmails($mailhogUrl) {
$json = json_decode($response->getBody()->getContents());
return $json;
}
/**
*
* @param string $mailhogUrl
*
* @param string $address
*
* @throws \Exception
*
* @return mixed
*/
public static function getBodyOfLastEmail($mailhogUrl, $address) {
foreach (self::getEmails($mailhogUrl)->items as $item) {
$expectedEmail = $item->To[0]->Mailbox . "@" . $item->To[0]->Domain;
if ($expectedEmail === $address) {
$body = str_replace(
"\r\n", "\n",
quoted_printable_decode($item->Content->Body)
);
return $body;
}
}
throw new \Exception("Could not find the email to the address: " . $address);
}

/**
*
Expand Down
13 changes: 13 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ default:
- WebUILoginContext:
- WebUIFilesContext:
- WebUIPersonalGeneralSettingsContext:
- EmailContext:

webUIFiles:
paths:
Expand All @@ -84,6 +85,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUIMoveFilesFolders:
paths:
Expand All @@ -94,6 +96,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUIRenameFiles:
paths:
Expand All @@ -104,6 +107,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUIRenameFolders:
paths:
Expand All @@ -114,6 +118,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUITrashbin:
paths:
Expand All @@ -124,6 +129,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUISharingInternalGroups:
paths:
Expand All @@ -135,6 +141,7 @@ default:
- WebUILoginContext:
- WebUIFilesContext:
- WebUISharingContext:
- EmailContext:

webUISharingInternalUsers:
paths:
Expand All @@ -146,6 +153,7 @@ default:
- WebUILoginContext:
- WebUIFilesContext:
- WebUISharingContext:
- EmailContext:

webUISharingExternal:
paths:
Expand All @@ -158,6 +166,7 @@ default:
- WebUIFilesContext:
- WebUISharingContext:
- FederationContext:
- EmailContext:

webUIUpload:
paths:
Expand All @@ -168,6 +177,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUIRestrictSharing:
paths:
Expand All @@ -179,6 +189,7 @@ default:
- WebUILoginContext:
- WebUIFilesContext:
- WebUISharingContext:
- EmailContext:

webUIFavorites:
paths:
Expand All @@ -189,6 +200,7 @@ default:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIFilesContext:
- EmailContext:

webUIPersonalSettings:
paths:
Expand All @@ -201,6 +213,7 @@ default:
- WebUIFilesContext:
- WebUIPersonalSecuritySettingsContext:
- WebUIPersonalGeneralSettingsContext:
- EmailContext:

extensions:
jarnaiz\JUnitFormatter\JUnitFormatterExtension:
Expand Down
8 changes: 2 additions & 6 deletions tests/acceptance/features/bootstrap/EmailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ public function getMailhogUrl() {
* @return void
*/
public function assertThatEmailContains($address, PyStringNode $content) {
$emails = EmailHelper::getEmails($this->mailhogUrl);
$expectedContent = str_replace("\r\n", "\n", $content->getRaw());
$content = str_replace(
"\r\n", "\n",
quoted_printable_decode($emails->items[0]->Content->Body)
);
PHPUnit_Framework_Assert::assertContains(
$expectedContent, $content
$expectedContent,
EmailHelper::getBodyOfLastEmail($this->mailhogUrl, $address)
);
}

Expand Down
68 changes: 68 additions & 0 deletions tests/acceptance/features/bootstrap/WebUILoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\MinkExtension\Context\RawMinkContext;
use Page\LoginPage;
use TestHelpers\EmailHelper;

require_once 'bootstrap.php';

Expand All @@ -37,6 +39,12 @@ class WebUILoginContext extends RawMinkContext implements Context {
private $loginPage;
private $filesPage;
private $expectedPage;

/**
*
* @var EmailContext
*/
private $emailContext;

/**
*
Expand Down Expand Up @@ -208,7 +216,66 @@ public function itShouldBePossibleToLogin($shouldOrNot, $username, $password) {
}

}

/**
* @When the user requests the password reset link using the webUI
*
* @return void
*/
public function theUserRequestsThePasswordResetLinkUsingTheWebui() {
$this->loginPage->requestPasswordReset($this->getSession());
}

/**
* @Then a message with this text should be displayed on the webUI:
*
* @param PyStringNode $string
*
* @return void
*/
public function thisMessageShouldBeDisplayed(PyStringNode $string) {
$expectedString = $string->getRaw();
$passwordRecoveryMessage = $this->loginPage->getLostPasswordMessage();
PHPUnit_Framework_Assert::assertEquals(
$expectedString, $passwordRecoveryMessage
);
}

/**
* @When the user follows the password reset link from email address :emailAddress
*
* @param string $emailAddress
*
* @return void
*/
public function theUserFollowsThePasswordResetLinkFromTheirEmail($emailAddress) {
$content = EmailHelper::getBodyOfLastEmail(
$this->emailContext->getMailhogUrl(), $emailAddress
);
preg_match(
'/Use the following link to reset your password: (http.*user1)/',
$content, $matches
);
PHPUnit_Framework_Assert::assertArrayHasKey(
1, $matches,
"Couldn't find password reset link in the email"
);
$this->visitPath($matches[1]);
}

/**
* @When the user resets the password to :newPassword using the webUI
*
* @param string $newPassword
*
* @return void
*/
public function theUserResetsThePasswordToUsingTheWebui($newPassword) {
$this->loginPage->resetThePassword($newPassword, $this->getSession());
}



/**
* This will run before EVERY scenario.
* It will set the properties for this object.
Expand All @@ -225,5 +292,6 @@ public function before(BeforeScenarioScope $scope) {
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
$this->webUIGeneralContext = $environment->getContext('WebUIGeneralContext');
$this->emailContext = $environment->getContext('EmailContext');
}
}
52 changes: 52 additions & 0 deletions tests/acceptance/features/lib/LoginPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class LoginPage extends OwncloudPage {
protected $userInputId = "user";
protected $passwordInputId = "password";
protected $submitLoginId = "submit";
protected $lostPasswordId = "lost-password";

/**
* @param string $username
Expand Down Expand Up @@ -99,4 +100,55 @@ public function waitTillPageIsLoaded(

$this->waitForOutstandingAjaxCalls($session);
}

/**
*
* @throws ElementNotFoundException
*
* @return Page
*/
private function lostPasswordField() {
$lostPasswordField = $this->findById($this->lostPasswordId);
if ($lostPasswordField === null) {
throw new ElementNotFoundException(
__METHOD__ .
" id $this->lostPasswordId " .
"could not find reset password field "
);
}
return $lostPasswordField;
}

/**
* @param Session $session
*
* @return void
*/
public function requestPasswordReset(Session $session) {
$this->lostPasswordField()->click();
$this->waitForAjaxCallsToStartAndFinish($session);
}

/**
*
* @return string
*/
public function getLostPasswordMessage() {
$passwordRecoveryMessage = $this->lostPasswordField()->getText();
return $passwordRecoveryMessage;
}
/**
*
* @param string $newPassword
*
* @param Session $session
*
* @return void
*/
public function resetThePassword($newPassword, Session $session) {
$this->fillField($this->passwordInputId, $newPassword);
$this->findById($this->submitLoginId)->click();
$this->waitForAjaxCallsToStartAndFinish($session);

}
}
37 changes: 37 additions & 0 deletions tests/acceptance/features/webUILogin/resetPassword.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@webUI @insulated @disablePreviews

Feature: reset the password
As a user
I want to reset my password
So that I can login to my account again after forgetting the password

Background:
Given these users have been created but not initialized:
|username|password|displayname|email |
|user1 |1234 |User One |u1@oc.com.np|
And the user has browsed to the login page
And the user logs in with username "user1" and invalid password "invalidpassword" using the webUI


Scenario: send password reset email
When the user requests the password reset link using the webUI
Then a message with this text should be displayed on the webUI:
"""
The link to reset your password has been sent to your email. If you do not receive it within a reasonable amount of time, check your spam/junk folders. If it is not there ask your local administrator.
"""
And the email address "u1@oc.com.np" should have received an email with the body containing
"""
Use the following link to reset your password: <a href=
"""

Scenario: reset password
When the user requests the password reset link using the webUI
And the user follows the password reset link from email address "u1@oc.com.np"
Then the user should be redirected to a webUI page with the title "ownCloud"
When the user resets the password to "newpassword" using the webUI
Then the email address "u1@oc.com.np" should have received an email with the body containing
"""
Password changed successfully
"""
When the user logs in with username "user1" and password "newpassword" using the webUI
Then the user should be redirected to a webUI page with the title "Files - ownCloud"
Loading