Skip to content

Commit

Permalink
Add tests for getUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
paurakhsharma committed Oct 11, 2018
1 parent ca99950 commit e79beb4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
34 changes: 32 additions & 2 deletions tests/acceptance/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ trait BasicStructure {
use CommandLine;

/**
* @var array
* @var string
*/
private $adminUsername = '';

/**
* @var array
* @var string
*/
private $adminPassword = '';

/**
* @var string
*/
private $originalAdminPassword = '';

/**
* @var string
*/
Expand Down Expand Up @@ -303,6 +308,7 @@ public function __construct(
if ($publicLinkSharePasswordFromEnvironment !== false) {
$this->publicLinkSharePassword = $publicLinkSharePasswordFromEnvironment;
}
$this->originalAdminPassword = $this->adminPassword;
}

/**
Expand Down Expand Up @@ -1381,6 +1387,15 @@ public function getAdminPassword() {
return (string) $this->adminPassword;
}

/**
* @param string $password
*
* @return void
*/
public function rememberNewAdminPassword($password) {
$this->adminPassword = (string) $password;
}

/**
* @param string $userName
*
Expand Down Expand Up @@ -1900,6 +1915,21 @@ public function setupLocalStorageBefore() {
);
}

/**
* @AfterScenario
*
* @return void
*/
public function restoreAdminPassword() {
if ($this->adminPassword !== $this->originalAdminPassword) {
$this->adminResetsPasswordOfUserUsingTheProvisioningApi(
$this->getAdminUsername(),
$this->originalAdminPassword
);
$this->adminPassword = $this->originalAdminPassword;
}
}

/**
* @AfterScenario @local_storage
*
Expand Down
7 changes: 6 additions & 1 deletion tests/acceptance/features/bootstrap/OccContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,16 @@ public function theAdministratorSendsAUserCreationRequestForUserPasswordGroupUsi
* @throws Exception
*/
public function resetUserPasswordUsingTheOccCommand($username, $password) {
$actualUsername = $this->featureContext->getActualUsername($username);
$password = $this->featureContext->getActualPassword($password);
$this->featureContext->invokingTheCommandWithEnvVariable(
"user:resetpassword $username --password-from-env",
"user:resetpassword $actualUsername --password-from-env",
'OC_PASS',
$password
);
if ($username === "%admin%") {
$this->featureContext->rememberNewAdminPassword($password);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ public function shouldBeAbleToDownloadFileInsidePublicSharedFolder(
public function userUsingPasswordShouldNotBeAbleToDownloadFile(
$user, $password, $fileName
) {
$user = $this->getActualUsername($user);
$password = $this->getActualPassword($password);
$this->downloadFileAsUserUsingPassword($user, $fileName, $password);
PHPUnit_Framework_Assert::assertGreaterThanOrEqual(
400, $this->getResponse()->getStatusCode(), 'download must fail'
Expand Down Expand Up @@ -654,6 +656,8 @@ public function contentOfFileForUserShouldBe($fileName, $user, $content) {
public function contentOfFileForUserUsingPasswordShouldBe(
$fileName, $user, $password, $content
) {
$user = $this->getActualUsername($user);
$password = $this->getActualPassword($password);
$this->downloadFileAsUserUsingPassword($user, $fileName, $password);
$this->downloadedContentShouldBe($content);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@cli @skipOnLDAP
Feature: reset user password
As an admin
I want to be able to reset a user's password
So that I can secure individual access to resources on the ownCloud server

Scenario: reset user password
Given these users have been created:
| username | password | displayname | email |
| brand-new-user | %regular% | New user | brand.new.user@oc.com.np |
When the administrator resets the password of user "brand-new-user" to "%alt1%" using the occ command
Then the command should have been successful
And the command output should contain the text "Successfully reset password for brand-new-user"
And the content of file "textfile0.txt" for user "brand-new-user" using password "%alt1%" should be "ownCloud test text file 0" plus end-of-line
But user "brand-new-user" using password "%regular%" should not be able to download file "textfile0.txt"

Scenario: admin tries to reset the password of a user that does not exist
Given user "not-a-user" has been deleted
When the administrator resets the password of user "not-a-user" to "%alt1%" using the occ command
Then the command should have failed with exit code 1
And the command output should contain the text 'User does not exist'

Scenario: admin should be able to reset their own password
Given user "brand-new-user" has been created
When the administrator resets the password of user "%admin%" to "%alt1%" using the occ command
Then the command should have been successful
And the command output should contain the text "Successfully reset password for admin"
When user "%admin%" retrieves the information of user "brand-new-user" using the provisioning API
Then the display name returned by the API should be "brand-new-user"

0 comments on commit e79beb4

Please sign in to comment.