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

[Tests-Only] Fix add users in provisioning api when testing on ocis #37874

Merged
merged 2 commits into from
Sep 2, 2020
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@api @provisioning_api-app-required @skipOnLDAP
@api @provisioning_api-app-required @skipOnLDAP @toImplementOnOCIS
Feature: create a subadmin
As an admin
I want to be able to make a user the subadmin of a group
Expand All @@ -7,7 +7,7 @@ Feature: create a subadmin
Background:
Given using OCS API version "1"

@smokeTest @notToImplementOnOCIS
@smokeTest
Scenario: admin creates a subadmin
Given user "brand-new-user" has been created with default attributes and skeleton files
And group "brand-new-group" has been created
Expand All @@ -16,7 +16,6 @@ Feature: create a subadmin
And the HTTP status code should be "200"
And user "brand-new-user" should be a subadmin of group "brand-new-group"

@notToImplementOnOCIS
Scenario: admin tries to create a subadmin using a user which does not exist
Given user "nonexistentuser" has been deleted
And group "brand-new-group" has been created
Expand All @@ -33,7 +32,6 @@ Feature: create a subadmin
And the HTTP status code should be "200"
And the API should not return any data

@notToImplementOnOCIS
Scenario: subadmin of a group tries to make another user subadmin of their group
Given these users have been created with default attributes and skeleton files:
| username |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@api @provisioning_api-app-required @skipOnLDAP
@api @provisioning_api-app-required @skipOnLDAP @toImplementOnOCIS
Feature: create a subadmin
As an admin
I want to be able to make a user the subadmin of a group
Expand All @@ -7,7 +7,7 @@ Feature: create a subadmin
Background:
Given using OCS API version "2"

@smokeTest @notToImplementOnOCIS
@smokeTest
Scenario: admin creates a subadmin
Given user "brand-new-user" has been created with default attributes and skeleton files
And group "brand-new-group" has been created
Expand All @@ -16,7 +16,6 @@ Feature: create a subadmin
And the HTTP status code should be "200"
And user "brand-new-user" should be a subadmin of group "brand-new-group"

@notToImplementOnOCIS
Scenario: admin tries to create a subadmin using a user which does not exist
Given user "nonexistentuser" has been deleted
And group "brand-new-group" has been created
Expand All @@ -32,7 +31,7 @@ Feature: create a subadmin
Then the OCS status code should be "400"
And the HTTP status code should be "400"

@issue-31276 @notToImplementOnOCIS
@issue-31276
Scenario: subadmin of a group tries to make another user subadmin of their group
Given these users have been created with default attributes and skeleton files:
| username |
Expand Down
125 changes: 93 additions & 32 deletions tests/acceptance/features/bootstrap/Provisioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,60 @@ public function resetOldLdapConfig() {
}
}

/**
* Manually add skeleton files for a single user on OCIS and reva systems
*
* @param string $user
* @param string $password
*
* @return void
* @throws Exception
*/
public function manuallyAddSkeletonFilesForUser($user, $password) {
$settings = [];
$setting["userid"] = $user;
$setting["password"] = $password;
\array_push($settings, $setting);
$this->manuallyAddSkeletonFiles($settings);
}

/**
* Manually add skeleton files on OCIS and reva systems
*
* @param array $usersAttributes
*
* @return void
* @throws Exception
*/
public function manuallyAddSkeletonFiles($usersAttributes) {
phil-davis marked this conversation as resolved.
Show resolved Hide resolved
$skeletonDir = \getenv("SKELETON_DIR");
$revaRoot = \getenv("OCIS_REVA_DATA_ROOT");
if (!$skeletonDir) {
throw new Exception('Missing SKELETON_DIR environment variable, cannot copy skeleton files for OCIS');
}
if (!$revaRoot && OcisHelper::getDeleteUserDataCommand() !== false) {
foreach ($usersAttributes as $userAttributes) {
OcisHelper::recurseUpload(
$this->getBaseUrl(),
$skeletonDir,
$userAttributes['userid'],
$userAttributes['password']
);
}
} elseif (!$revaRoot) {
throw new Exception('Missing OCIS_REVA_DATA_ROOT environment variable, cannot copy skeleton files for OCIS');
} else {
foreach ($usersAttributes as $userAttributes) {
$user = $userAttributes['userid'];
$dataDir = $revaRoot . "data/$user/files";
if (!\file_exists($dataDir)) {
\mkdir($dataDir, 0777, true);
}
OcisHelper::recurseCopy($skeletonDir, $dataDir);
}
}
}

/**
* This function will allow us to send user creation requests in parallel.
* This will be faster in comparison to waiting for each request to complete before sending another request.
Expand Down Expand Up @@ -921,32 +975,7 @@ public function usersHaveBeenCreated(
// When testing on ownCloud 10 the user is already getting whatever
// skeleton dir is defined in the server-under-test.
if ($skeleton && OcisHelper::isTestingOnOcis()) {
$skeletonDir = \getenv("SKELETON_DIR");
$revaRoot = \getenv("OCIS_REVA_DATA_ROOT");
if (!$skeletonDir) {
throw new Exception('Missing SKELETON_DIR environment variable, cannot copy skeleton files for OCIS');
}
if (!$revaRoot && OcisHelper::getDeleteUserDataCommand() !== false) {
foreach ($usersAttributes as $userAttributes) {
OcisHelper::recurseUpload(
$this->getBaseUrl(),
$skeletonDir,
$userAttributes['userid'],
$userAttributes['password']
);
}
} elseif (!$revaRoot) {
throw new Exception('Missing OCIS_REVA_DATA_ROOT environment variable, cannot copy skeleton files for OCIS');
} else {
foreach ($usersAttributes as $userAttributes) {
$user = $userAttributes['userid'];
$dataDir = $revaRoot . "data/$user/files";
if (!\file_exists($dataDir)) {
\mkdir($dataDir, 0777, true);
}
OcisHelper::recurseCopy($skeletonDir, $dataDir);
}
}
$this->manuallyAddSkeletonFiles($usersAttributes);
}

if ($initialize) {
Expand Down Expand Up @@ -1155,6 +1184,15 @@ public function adminSendsUserCreationRequestWithFollowingAttributesUsingTheProv
"displayname" => $displayname,
"email" => $email
];

if (OcisHelper::isTestingOnOcis()) {
if ($email === null) {
$email = $username . '@owncloud.org';
}
$userAttributes["username"] = $username;
$userAttributes["email"] = $email;
}

$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->getAdminUsername(),
"POST",
Expand All @@ -1164,6 +1202,9 @@ public function adminSendsUserCreationRequestWithFollowingAttributesUsingTheProv
$this->addUserToCreatedUsersList(
$username, $password, $displayname, $email
);
if (OcisHelper::isTestingOnOcis()) {
$this->manuallyAddSkeletonFilesForUser($username, $password);
}
}

/**
Expand All @@ -1173,18 +1214,28 @@ public function adminSendsUserCreationRequestWithFollowingAttributesUsingTheProv
* @param string $password
*
* @return void
* @throws Exception
*/
public function adminSendsUserCreationRequestUsingTheProvisioningApi($user, $password) {
$user = $this->getActualUsername($user);
$password = $this->getActualPassword($password);
$bodyTable = new TableNode([['userid', $user], ['password', $password]]);
if (OcisHelper::isTestingOnOcis()) {
$email = $user . '@owncloud.org';
$bodyTable = new TableNode([['userid', $user], ['password', $password], ['username', $user], ['email', $email]]);
} else {
$email = null;
$bodyTable = new TableNode([['userid', $user], ['password', $password]]);
}
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->getAdminUsername(),
"POST",
"/cloud/users",
$bodyTable
);
$this->addUserToCreatedUsersList($user, $password);
$this->addUserToCreatedUsersList($user, $password, null, $email);
if (OcisHelper::isTestingOnOcis()) {
$this->manuallyAddSkeletonFilesForUser($user, $password);
}
}

/**
Expand All @@ -1195,22 +1246,32 @@ public function adminSendsUserCreationRequestUsingTheProvisioningApi($user, $pas
* @param string $group
*
* @return void
* @throws Exception
*/
public function theAdministratorCreatesUserPasswordGroupUsingTheProvisioningApi(
$user, $password, $group
) {
$user = $this->getActualUsername($user);
$password = $this->getActualPassword($password);
$bodyTable = new TableNode(
[['userid', $user], ['password', $password], ['groups[]', $group]]
);
if (OcisHelper::isTestingOnOcis()) {
$email = $user . '@owncloud.org';
$bodyTable = new TableNode([['userid', $user], ['password', $password], ['username', $user], ['email', $email], ['groups[]', $group]]);
} else {
$email = null;
$bodyTable = new TableNode(
[['userid', $user], ['password', $password], ['groups[]', $group]]
);
}
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->getAdminUsername(),
"POST",
"/cloud/users",
$bodyTable
);
$this->addUserToCreatedUsersList($user, $password);
$this->addUserToCreatedUsersList($user, $password, null, $email);
if (OcisHelper::isTestingOnOcis()) {
$this->manuallyAddSkeletonFilesForUser($user, $password);
}
}

/**
Expand Down