[tests-only][full-ci] refactoring user creation Given steps from provisioning into GraphContext (#7019)

* refactored the user creation given statement from provisioning to graph api

added getUser steps that covers the steps for user with user light role

* added userlight step tests to check drive information and updated expected failure files

* added usercreation initiation code

* deleted seperate tests for user light role

* remove unnecesary changes

* add user not initialize step

* corrected the testcode

* moved the steps from graph to provisioning file

* fix creating single ldap user

* fix: user check method

* initialize user via graph

* addressing reviews

---------

Co-authored-by: Saw-jan <saw.jan.grg3e@gmail.com>
This commit is contained in:
Sabin Panta
2023-09-06 09:22:38 +05:45
committed by GitHub
parent 64bfdf24b5
commit 5efc3c51a1
11 changed files with 213 additions and 493 deletions

View File

@@ -71,7 +71,6 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiGraph/getUser.feature:91](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L91)
- [apiGraph/getUser.feature:92](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L92)
- [apiGraph/getUser.feature:93](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L93)
- [apiGraph/getUser.feature:606](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L606)
- [apiGraph/getUser.feature:607](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L607)
- [apiGraph/getUser.feature:608](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L608)
- [apiGraph/getUser.feature:609](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L609)
@@ -83,6 +82,7 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiGraph/getUser.feature:615](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L615)
- [apiGraph/getUser.feature:616](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L616)
- [apiGraph/getUser.feature:617](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L617)
- [apiGraph/getUser.feature:618](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getUser.feature#L618)
#### [Normal user can get expanded members information of a group](https://github.com/owncloud/ocis/issues/5604)
@@ -90,7 +90,7 @@ The expected failures in this file are from features in the owncloud/ocis repo.
- [apiGraph/getGroup.feature:382](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L382)
- [apiGraph/getGroup.feature:383](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/getGroup.feature#L383)
#### [Changing user with an uppercase name gives 404 error](https://github.com/owncloud/ocis/issues/5763)
#### [Changing user with an uppercase name gives 404 error](https://github.com/owncloud/ocis/issues/7044)
- [apiGraph/editUser.feature:67](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiGraph/editUser.feature#L67)

View File

@@ -42,7 +42,7 @@ Feature: edit user
| empty mail | | 400 | brian@example.com |
| change to a invalid email | invalidEmail | 400 | brian@example.com |
@issue-5763
@issue-7044
Scenario Outline: admin user can edit another user's name
Given user "Carol" has been created with default attributes and without skeleton files
When the user "Alice" changes the user name of user "Carol" to "<userName>" using the Graph API

View File

@@ -381,7 +381,7 @@ Feature: get users
"""
Scenario Outline: non-admin user gets his/her own drive information
Scenario Outline: user gets his/her own information along with drive information
Given the administrator has assigned the role "<userRole>" to user "Brian" using the Graph API
When the user "Brian" gets his drive information using Graph API
Then the HTTP status code should be "200"
@@ -504,6 +504,7 @@ Feature: get users
"""
Examples:
| userRole |
| Admin |
| Space Admin |
| User |
| User Light |
@@ -750,7 +751,6 @@ Feature: get users
And the JSON data of the response should not contain the user "Alice Hansen" in the item 'value'
Scenario: admin user gets all users of two groups
Given the administrator has assigned the role "Admin" to user "Alice" using the Graph API
And user "Carol" has been created with default attributes and without skeleton files

View File

@@ -179,7 +179,7 @@ class AppConfigurationContext implements Context {
/**
* @return string
* @throws Exception
* @throws Exception|GuzzleException
*/
public function getAdminUsernameForCapabilitiesCheck():string {
if (\TestHelpers\OcisHelper::isTestingOnReva()) {
@@ -190,7 +190,7 @@ class AppConfigurationContext implements Context {
$adminUsername = "PseudoAdminForRevaTest";
$createdUsers = $this->featureContext->getCreatedUsers();
if (!\array_key_exists($adminUsername, $createdUsers)) {
$this->featureContext->createUser($adminUsername);
$this->featureContext->userHasBeenCreated(["userName" => $adminUsername]);
}
} else {
$adminUsername = $this->featureContext->getAdminUsername();

View File

@@ -724,41 +724,6 @@ class GraphContext implements Context {
return $this->getArrayOfUsersResponded($this->listGroupMembers($group));
}
/**
* creates a user with provided data
* actor: the administrator
*
* @param string $user
* @param string $password
* @param string $email
* @param string $displayName
*
* @return void
* @throws Exception|GuzzleException
*/
public function theAdminHasCreatedUser(
string $user,
string $password,
string $email,
string $displayName
): void {
$response = GraphHelper::createUser(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$user,
$password,
$email,
$displayName
);
if ($response->getStatusCode() !== 200) {
$this->throwHttpException($response, "Could not create user $user");
} else {
$this->featureContext->setResponse($response);
}
}
/**
* @When /^the user "([^"]*)" creates a new user using GraphAPI with the following settings:$/
*
@@ -795,28 +760,6 @@ class GraphContext implements Context {
$this->featureContext->setResponse($response);
}
/**
* @Given /^the user "([^"]*)" has created a new user using the Graph API with the following settings:$/
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theUserHasCreatedANewUserUsingGraphapiWithTheFollowingSettings(string $user, TableNode $table): void {
$this->theUserCreatesNewUser(
$user,
$table
);
$rows = $table->getRowsHash();
$response = $this->featureContext->getResponse();
if ($response->getStatusCode() !== 200) {
$this->throwHttpException($response, "Could not create user '$rows[userName]'");
}
}
/**
* adds a user to a group
*

View File

@@ -29,6 +29,7 @@ use TestHelpers\UserHelper;
use TestHelpers\HttpRequestHelper;
use TestHelpers\OcisHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\GraphHelper;
use Laminas\Ldap\Exception\LdapException;
use Laminas\Ldap\Ldap;
@@ -361,6 +362,65 @@ trait Provisioning {
);
}
/**
* @Given user :user has been created with default attributes and without skeleton files
*
* @param string $user
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasBeenCreatedWithDefaultAttributes(
string $user
):void {
$this->userHasBeenCreated(["userName" => $user]);
}
/**
* @Given these users have been created without skeleton files and not initialized:
*
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function userHasBeenCreatedWithDefaultAttributesAndNotInitialized(
TableNode $table
):void {
$this->usersHaveBeenCreated($table, true, false);
}
/**
* @Given these users have been created with default attributes and without skeleton files:
* expects a table of users with the heading
* "|username|"
*
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theseUsersHaveBeenCreatedWithDefaultAttributesAndWithoutSkeletonFiles(TableNode $table):void {
$this->usersHaveBeenCreated($table);
}
/**
* @Given the user :byUser has created a new user using the Graph API with the following settings:
*
* @param string $byUser
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theAdministratorHasCreatedANewUserWithFollowingSettings(string $byUser, TableNode $table): void {
$rows = $table->getRowsHash();
$this->userHasBeenCreated(
$rows,
$byUser
);
}
/**
*
* @param string $groupname
@@ -383,125 +443,6 @@ trait Provisioning {
);
}
/**
* @When /^the administrator creates user "([^"]*)" using the provisioning API$/
*
* @param string|null $user
*
* @return void
* @throws Exception
*/
public function adminCreatesUserUsingTheProvisioningApi(?string $user):void {
$this->createUser(
$user,
null,
null,
null,
true,
'api'
);
$this->pushToLastStatusCodesArrays();
}
/**
* @Given /^user "([^"]*)" has been created with default attributes in the database user backend$/
*
* @param string|null $user
*
* @return void
* @throws Exception
*/
public function userHasBeenCreatedOnDatabaseBackend(?string $user):void {
$this->adminCreatesUserUsingTheProvisioningApi($user);
$this->userShouldExist($user);
}
/**
* @Given /^user "([^"]*)" has been created with default attributes and (tiny|small|large)\s?skeleton files$/
*
* @param string $user
* @param string $skeletonType
* @param boolean $skeleton
*
* @return void
* @throws Exception
*/
public function userHasBeenCreatedWithDefaultAttributes(
string $user,
string $skeletonType = "",
bool $skeleton = true
):void {
if ($skeletonType === "") {
$skeletonType = $this->getSmallestSkeletonDirName();
}
$originalSkeletonPath = $this->setSkeletonDirByType($skeletonType);
try {
$this->createUser(
$user,
null,
null,
null,
true,
null,
true,
$skeleton
);
$this->userShouldExist($user);
} finally {
$this->setSkeletonDir($originalSkeletonPath);
}
}
/**
* @Given /^user "([^"]*)" has been created with default attributes and without skeleton files$/
*
* @param string $user
*
* @return void
* @throws Exception
*/
public function userHasBeenCreatedWithDefaultAttributesAndWithoutSkeletonFiles(string $user):void {
$this->userHasBeenCreatedWithDefaultAttributes($user);
}
/**
* @Given these users have been created with default attributes and without skeleton files:
* expects a table of users with the heading
* "|username|"
*
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theseUsersHaveBeenCreatedWithDefaultAttributesAndWithoutSkeletonFiles(TableNode $table):void {
$originalSkeletonPath = $this->setSkeletonDirByType($this->getSmallestSkeletonDirName());
try {
$this->createTheseUsers(true, true, true, $table);
} finally {
// restore skeleton directory even if user creation failed
$this->setSkeletonDir($originalSkeletonPath);
}
}
/**
* @Given /^these users have been created without skeleton files ?(and not initialized|):$/
* expects a table of users with the heading
* "|username|password|displayname|email|"
* password, displayname & email are optional
*
* @param TableNode $table
* @param string $doNotInitialize
*
* @return void
* @throws Exception
*/
public function theseUsersHaveBeenCreatedWithoutSkeletonFiles(TableNode $table, string $doNotInitialize):void {
$this->theseUsersHaveBeenCreated("", "", $doNotInitialize, $table);
}
/**
*
* @param string $path
@@ -837,43 +778,36 @@ trait Provisioning {
}
/**
* Creates multiple users
*
* 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.
*
* @param boolean $initialize
* @param array|null $usersAttributes
* @param string|null $method create the user with "ldap" or "api"
* @param boolean $skeleton
* @param TableNode $table
* @param bool $useDefault
* @param bool $initialize
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function usersHaveBeenCreated(
bool $initialize,
?array $usersAttributes,
?string $method = null,
?bool $skeleton = true
TableNode $table,
bool $useDefault=true,
bool $initialize=true
) {
$this->verifyTableNodeColumns($table, ['username'], ['displayname', 'email', 'password']);
$table = $table->getColumnsHash();
$users = $this->buildUsersAttributesArray($useDefault, $table);
$requests = [];
$client = HttpRequestHelper::createClient(
$this->getAdminUsername(),
$this->getAdminPassword()
);
$useLdap = false;
$useGraph = false;
if ($method === null) {
$useLdap = $this->isTestingWithLdap();
$useGraph = OcisHelper::isTestingWithGraphApi();
} elseif ($method === "ldap") {
$useLdap = true;
} elseif ($method === "graph") {
$useGraph = true;
}
foreach ($usersAttributes as $userAttributes) {
if ($useLdap) {
foreach ($users as $userAttributes) {
if ($this->isTestingWithLdap()) {
$this->createLdapUser($userAttributes);
} else {
$attributesToCreateUser['userid'] = $userAttributes['userid'];
@@ -890,75 +824,50 @@ trait Provisioning {
} else {
$attributesToCreateUser['email'] = $userAttributes['email'];
}
if ($useGraph) {
$body = \TestHelpers\GraphHelper::prepareCreateUserPayload(
$attributesToCreateUser['userid'],
$attributesToCreateUser['password'],
$attributesToCreateUser['email'],
$attributesToCreateUser['displayname']
);
$request = \TestHelpers\GraphHelper::createRequest(
$this->getBaseUrl(),
$this->getStepLineRef(),
"POST",
'users',
$body,
);
} else {
// Create an OCS request for creating the user. The request is not sent to the server yet.
$request = OcsApiHelper::createOcsRequest(
$this->getBaseUrl(),
'POST',
"/cloud/users",
$this->stepLineRef,
$attributesToCreateUser
);
}
$body = GraphHelper::prepareCreateUserPayload(
$attributesToCreateUser['userid'],
$attributesToCreateUser['password'],
$attributesToCreateUser['email'],
$attributesToCreateUser['displayname']
);
$request = GraphHelper::createRequest(
$this->getBaseUrl(),
$this->getStepLineRef(),
"POST",
'users',
$body,
);
// Add the request to the $requests array so that they can be sent in parallel.
$requests[] = $request;
}
}
$exceptionToThrow = null;
if (!$useLdap) {
if (!$this->isTestingWithLdap()) {
$results = HttpRequestHelper::sendBatchRequest($requests, $client);
// Check all requests to inspect failures.
foreach ($results as $key => $e) {
if ($e instanceof ClientException) {
if ($useGraph) {
$responseBody = $this->getJsonDecodedResponse($e->getResponse());
$httpStatusCode = $e->getResponse()->getStatusCode();
$graphStatusCode = $responseBody['error']['code'];
$messageText = $responseBody['error']['message'];
$exceptionToThrow = new Exception(
__METHOD__ .
" Unexpected failure when creating the user '" .
$usersAttributes[$key]['userid'] . "'" .
"\nHTTP status $httpStatusCode " .
"\nGraph status $graphStatusCode " .
"\nError message $messageText"
);
} else {
$responseXml = $this->getResponseXml($e->getResponse(), __METHOD__);
$messageText = (string) $responseXml->xpath("/ocs/meta/message")[0];
$ocsStatusCode = (string) $responseXml->xpath("/ocs/meta/statuscode")[0];
$httpStatusCode = $e->getResponse()->getStatusCode();
$reasonPhrase = $e->getResponse()->getReasonPhrase();
$exceptionToThrow = new Exception(
__METHOD__ . " Unexpected failure when creating the user '" .
$usersAttributes[$key]['userid'] . "': HTTP status $httpStatusCode " .
"HTTP reason $reasonPhrase OCS status $ocsStatusCode " .
"OCS message $messageText"
);
}
$responseBody = $this->getJsonDecodedResponse($e->getResponse());
$httpStatusCode = $e->getResponse()->getStatusCode();
$graphStatusCode = $responseBody['error']['code'];
$messageText = $responseBody['error']['message'];
$exceptionToThrow = new Exception(
__METHOD__ .
" Unexpected failure when creating the user '" .
$users[$key]['userid'] . "'" .
"\nHTTP status $httpStatusCode " .
"\nGraph status $graphStatusCode " .
"\nError message $messageText"
);
}
}
}
// Create requests for setting displayname and email for the newly created users.
// These values cannot be set while creating the user, so we have to edit the newly created user to set these values.
foreach ($usersAttributes as $userAttributes) {
if ($useGraph) {
foreach ($users as $userAttributes) {
if (!$this->isTestingWithLdap()) {
// for graph api, we need to save the user id to be able to add it in some group
// can be fetched with the "onPremisesSamAccountName" i.e. userid
$this->graphContext->adminHasRetrievedUserUsingTheGraphApi($userAttributes['userid']);
@@ -973,125 +882,22 @@ trait Provisioning {
$userAttributes['email'],
$userAttributes['id']
);
OcisHelper::createEOSStorageHome(
$this->getBaseUrl(),
$userAttributes['userid'],
$userAttributes['password'],
$this->getStepLineRef()
);
}
if (isset($exceptionToThrow)) {
throw $exceptionToThrow;
}
// If the user should have skeleton files, and we are testing on OCIS
// then do some work to "manually" put the skeleton files in place.
// When testing on ownCloud 10 the user is already getting whatever
// skeleton dir is defined in the server-under-test.
if ($skeleton) {
$this->manuallyAddSkeletonFiles($usersAttributes);
}
}
/**
* @When /^the administrator creates these users with ?(default attributes and|) skeleton files ?(but not initialized|):$/
*
* expects a table of users with the heading
* "|username|password|displayname|email|"
* password, displayname & email are optional
*
* @param string $setDefaultAttributes
* @param string $doNotInitialize
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theAdministratorCreatesTheseUsers(
string $setDefaultAttributes,
string $doNotInitialize,
TableNode $table
): void {
$this->verifyTableNodeColumns($table, ['username'], ['displayname', 'email', 'password']);
$table = $table->getColumnsHash();
$setDefaultAttributes = $setDefaultAttributes !== "";
$initialize = $doNotInitialize === "";
$usersAttributes = $this->buildUsersAttributesArray($setDefaultAttributes, $table);
$this->usersHaveBeenCreated(
$initialize,
$usersAttributes
);
}
/**
* expects a table of users with the heading
* "|username|password|displayname|email|"
* password, displayname & email are optional
*
* @param boolean $setDefaultAttributes
* @param boolean $initialize
* @param boolean $skeleton
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function createTheseUsers(bool $setDefaultAttributes, bool $initialize, bool $skeleton, TableNode $table):void {
$this->verifyTableNodeColumns($table, ['username'], ['displayname', 'email', 'password']);
$table = $table->getColumnsHash();
$usersAttributes = $this->buildUsersAttributesArray($setDefaultAttributes, $table);
$this->usersHaveBeenCreated(
$initialize,
$usersAttributes,
null,
$skeleton
);
foreach ($usersAttributes as $expectedUser) {
$this->userShouldExist($expectedUser["userid"]);
}
}
/**
* @Given /^these users have been created with ?(default attributes and|) (tiny|small|large)\s?skeleton files ?(but not initialized|):$/
*
* expects a table of users with the heading
* "|username|password|displayname|email|"
* password, displayname & email are optional
*
* @param string $defaultAttributesText
* @param string $skeletonType
* @param string $doNotInitialize
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theseUsersHaveBeenCreated(
string $defaultAttributesText,
string $skeletonType,
string $doNotInitialize,
TableNode $table
):void {
if ($skeletonType === "") {
$skeletonType = $this->getSmallestSkeletonDirName();
foreach ($users as $user) {
Assert::assertTrue(
$this->userExists($user["userid"]),
"User '" . $user["userid"] . "' should exist but does not exist"
);
}
$originalSkeletonPath = $this->setSkeletonDirByType($skeletonType);
$setDefaultAttributes = $defaultAttributesText !== "";
$initialize = $doNotInitialize === "";
try {
$this->createTheseUsers($setDefaultAttributes, $initialize, true, $table);
} finally {
// The effective skeleton directory is the one when the user is initialized
// If we did not initialize the user on creation, then we need to leave
// the skeleton directory in effect so that it applies when some action
// happens later in the scenario that causes the user to be initialized.
if ($initialize) {
$this->setSkeletonDir($originalSkeletonPath);
if ($initialize) {
foreach ($users as $user) {
$this->initializeUser($user['userid'], $user['password']);
}
}
}
@@ -2380,7 +2186,6 @@ trait Provisioning {
* @throws JsonException
*/
public function userShouldExist(string $user):void {
$user = $this->getActualUsername($user);
Assert::assertTrue(
$this->userExists($user),
"User '$user' should exist but does not exist"
@@ -2723,8 +2528,13 @@ trait Provisioning {
* @return void
*/
public function initializeUser(string $user, string $password):void {
$url = $this->getBaseUrl()
. "/ocs/v$this->ocsApiVersion.php/cloud/users/$user";
$url = $this->getBaseUrl() . "/graph/v1.0/users/$user";
if (OcisHelper::isTestingOnReva()) {
$url = $this->getBaseUrl()
. "/ocs/v$this->ocsApiVersion.php/cloud/users/$user";
}
HttpRequestHelper::get(
$url,
$this->getStepLineRef(),
@@ -2830,41 +2640,35 @@ trait Provisioning {
/**
* creates a single user
*
* @param string|null $user
* @param string|null $password if null, then select a password
* @param string|null $displayName
* @param string|null $email
* @param bool $initialize initialize the user skeleton files etc
* @param string|null $method how to create the user api|occ, default api
* @param bool $setDefault sets the missing values to some default
* @param bool $skeleton
* @param array $userData
* @param string|null $byUser
*
* @return void
* @throws Exception|GuzzleException
*/
public function createUser(
?string $user,
?string $password = null,
?string $displayName = null,
?string $email = null,
bool $initialize = true,
?string $method = null,
bool $setDefault = true,
bool $skeleton = true
public function userHasBeenCreated(
array $userData,
string $byUser = null
):void {
$userId = null;
$user = $userData["userName"];
$displayName = $userData["displayName"] ?? null;
$email = $userData["email"] ?? null;
$password = $userData["password"] ?? null;
if ($password === null) {
$password = $this->getPasswordForUser($user);
}
if ($displayName === null && $setDefault === true) {
if ($displayName === null) {
$displayName = $this->getDisplayNameForUser($user);
if ($displayName === null) {
$displayName = $this->getDisplayNameForUser('regularuser');
}
}
if ($email === null && $setDefault === true) {
if ($email === null) {
$email = $this->getEmailAddressForUser($user);
if ($email === null) {
@@ -2872,61 +2676,50 @@ trait Provisioning {
$email = \str_replace(["@", " "], "", $user) . '@owncloud.com';
}
}
$user = $this->getActualUsername($user);
if ($method === null && $this->isTestingWithLdap()) {
//guess yourself
$method = "ldap";
} elseif (OcisHelper::isTestingWithGraphApi()) {
$method = "graph";
} elseif ($method === null) {
$method = "api";
}
$user = \trim($user);
$method = \trim(\strtolower($method));
switch ($method) {
case "api":
case "ldap":
$settings = [];
$setting["userid"] = $user;
$setting["displayName"] = $displayName;
$setting["password"] = $password;
$setting["email"] = $email;
$settings[] = $setting;
try {
$this->usersHaveBeenCreated(
$initialize,
$settings,
$method,
$skeleton
);
} catch (LdapException $exception) {
throw new Exception(
__METHOD__ . " cannot create a LDAP user with provided data. Error: $exception"
);
}
break;
case "graph":
$this->graphContext->theAdminHasCreatedUser(
$user,
$password,
$email,
$displayName,
);
$newUser = $this->getJsonDecodedResponse();
$userId = $newUser['id'];
break;
default:
throw new InvalidArgumentException(
__METHOD__ . " Invalid method to create a user"
if ($this->isTestingWithLdap()) {
$setting["userid"] = $user;
$setting["displayName"] = $displayName;
$setting["password"] = $password;
$setting["email"] = $email;
try {
$this->createLdapUser($setting);
} catch (LdapException $exception) {
throw new Exception(
__METHOD__ . " cannot create a LDAP user with provided data. Error: $exception"
);
}
} else {
$reqUser = $byUser ? $this->getActualUsername($byUser) : $this->getAdminUsername();
$response = GraphHelper::createUser(
$this->getBaseUrl(),
$this->getStepLineRef(),
$reqUser,
$this->getPasswordForUser($reqUser),
$user,
$password,
$email,
$displayName,
);
Assert::assertEquals(
200,
$response->getStatusCode(),
__METHOD__ . " cannot create user '$user' using Graph API.\nResponse:" .
json_encode($this->getJsonDecodedResponse($response))
);
$userId = $this->getJsonDecodedResponse($response)['id'];
}
$this->addUserToCreatedUsersList($user, $password, $displayName, $email, $userId);
if ($initialize) {
$this->initializeUser($user, $password);
}
Assert::assertTrue(
$this->userExists($user),
"User '$user' should exist but does not exist"
);
$this->initializeUser($user, $password);
}
/**
@@ -2976,46 +2769,32 @@ trait Provisioning {
}
/**
* @param string|null $user
* @param string $user
*
* @return bool
* @throws JsonException
*/
public function userExists(?string $user):bool {
// in OCIS there is no admin user and in oC10 there are issues when
// sending the username in lowercase in the auth but in uppercase in
// the URL see https://github.com/owncloud/core/issues/36822
$user = $this->getActualUsername($user);
// In OCIS an intermittent issue restricts users to list their own account
// So use admin account to list the user
// https://github.com/owncloud/ocis/issues/820
// The special code can be reverted once the issue is fixed
if (OcisHelper::isTestingParallelDeployment()) {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($user);
} elseif (OcisHelper::isTestingWithGraphApi()) {
$requestingUser = $this->getAdminUsername();
$requestingPassword = $this->getAdminPassword();
} elseif (!OcisHelper::isTestingOnReva()) {
$requestingUser = 'moss';
$requestingPassword = 'vista';
} else {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($requestingUser);
}
$path = (OcisHelper::isTestingWithGraphApi())
public function userExists(string $user):bool {
$path = (!OcisHelper::isTestingOnReva())
? "/graph/v1.0"
: "/ocs/v2.php/cloud";
$fullUrl = $this->getBaseUrl() . $path . "/users/$user";
$this->response = HttpRequestHelper::get(
if (OcisHelper::isTestingOnReva()) {
$requestingUser = $this->getActualUsername($user);
$requestingPassword = $this->getPasswordForUser($user);
} else {
$requestingUser = $this->getAdminUsername();
$requestingPassword = $this->getAdminPassword();
}
$response = HttpRequestHelper::get(
$fullUrl,
$this->getStepLineRef(),
$requestingUser,
$requestingPassword
);
if ($this->response->getStatusCode() >= 400) {
if ($response->getStatusCode() >= 400) {
return false;
}
return true;

View File

@@ -74,7 +74,7 @@ trait WebDav {
/**
* response content parsed into a SimpleXMLElement
*/
private ?SimpleXMLElement $responseXmlObject;
private ?SimpleXMLElement $responseXmlObject = null;
private int $httpRequestTimeout = 0;
@@ -2390,8 +2390,6 @@ trait WebDav {
false,
'new'
);
$this->pushToLastStatusCodesArrays();
}
/**

View File

@@ -8,7 +8,7 @@ Feature: sharing works when a username and group name are the same
Scenario: creating a new share with user and a group having same name
Given these users have been created without skeleton files:
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
| Carol |
@@ -30,7 +30,7 @@ Feature: sharing works when a username and group name are the same
Scenario: creating a new share with group and a user having same name
Given these users have been created without skeleton files:
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
| Carol |
@@ -52,7 +52,7 @@ Feature: sharing works when a username and group name are the same
Scenario: creating a new share with user and a group having same name but different case
Given these users have been created without skeleton files:
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
| Carol |
@@ -74,7 +74,7 @@ Feature: sharing works when a username and group name are the same
Scenario: creating a new share with group and a user having same name but different case
Given these users have been created without skeleton files:
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
| Carol |

View File

@@ -398,7 +398,7 @@ Feature: sharing
Scenario: share with user when username contains capital letters
Given these users have been created without skeleton files:
Given these users have been created with default attributes and without skeleton files:
| username |
| brian |
And user "Alice" has uploaded file with content "Random data" to "/randomfile.txt"
@@ -415,12 +415,12 @@ Feature: sharing
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And user "brian" should see the following elements
| /Shares/randomfile.txt |
| /Shares/randomfile.txt |
And the content of file "Shares/randomfile.txt" for user "brian" should be "Random data"
Scenario: creating a new share with user of a group when username contains capital letters
Given these users have been created without skeleton files:
Given these users have been created with default attributes and without skeleton files:
| username |
| Brian |
And group "grp1" has been created
@@ -571,7 +571,7 @@ Feature: sharing
And user "Carol" has accepted share "/userOneFolder" offered by user "Brian"
When user "Carol" shares folder "/Shares/userOneFolder" with user "Brian" using the sharing API
Then the HTTP status code should be "200"
# Then the HTTP status code should be "405"
# Then the HTTP status code should be "405"
And the sharing API should report to user "Brian" that no shares are in the pending state
And as "Brian" folder "/Shares/userOneFolder" should not exist
@@ -589,7 +589,7 @@ Feature: sharing
And user "Carol" has accepted share "/userOneFolder" offered by user "Brian"
When user "Carol" shares folder "/Shares/userOneFolder" with user "Alice" using the sharing API
Then the HTTP status code should be "200"
# Then the HTTP status code should be "405"
# Then the HTTP status code should be "405"
And the sharing API should report to user "Alice" that no shares are in the pending state
And as "Alice" folder "/Shares/userOneFolder" should not exist
@@ -610,7 +610,7 @@ Feature: sharing
And user "David" has accepted share "/userOneFolder" offered by user "Brian"
When user "David" shares folder "/Shares/userOneFolder" with user "Carol" using the sharing API
Then the HTTP status code should be "200"
# Then the HTTP status code should be "405"
# Then the HTTP status code should be "405"
And the sharing API should report to user "Carol" that no shares are in the pending state
And as "Carol" folder "/Shares/userOneFolder" should not exist
@@ -624,17 +624,17 @@ Feature: sharing
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the fields of the last response to user "Alice" sharing with user "Brian" should include
| share_with | %username% |
| share_with_displayname | %displayname% |
| share_with | %username% |
| share_with_displayname | %displayname% |
| file_target | /Shares/renamed.txt |
| path | /renamed.txt |
| permissions | share,read,update |
| uid_owner | %username% |
| displayname_owner | %displayname% |
| item_type | file |
| mimetype | text/plain |
| storage_id | ANY_VALUE |
| share_type | user |
| permissions | share,read,update |
| uid_owner | %username% |
| displayname_owner | %displayname% |
| item_type | file |
| mimetype | text/plain |
| storage_id | ANY_VALUE |
| share_type | user |
When user "Brian" accepts share "/renamed.txt" offered by user "Alice" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"

View File

@@ -17,7 +17,7 @@ Feature: dav-versions
Scenario: upload file and no version is available using various chunking methods (except new chunking)
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms except new chunking using the WebDAV API
Then the HTTP status code should be "200"
Then the HTTP status code of all upload responses should be "201"
And the version folder of file "/davtest.txt-olddav-regular" for user "Alice" should contain "0" elements
And the version folder of file "/davtest.txt-newdav-regular" for user "Alice" should contain "0" elements
And the version folder of file "/davtest.txt-olddav-oldchunking" for user "Alice" should contain "0" elements
@@ -34,7 +34,7 @@ Feature: dav-versions
Scenario: upload a file twice and versions are available using various chunking methods (except new chunking)
When user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms except new chunking using the WebDAV API
And user "Alice" uploads file "filesForUpload/davtest.txt" to filenames based on "/davtest.txt" with all mechanisms except new chunking using the WebDAV API
Then the HTTP status code of responses on all endpoints should be "200"
Then the HTTP status code of all upload responses should be between "201" and "204"
And the version folder of file "/davtest.txt-olddav-regular" for user "Alice" should contain "1" element
And the version folder of file "/davtest.txt-newdav-regular" for user "Alice" should contain "1" element
And the version folder of file "/davtest.txt-olddav-oldchunking" for user "Alice" should contain "1" element

View File

@@ -6,7 +6,7 @@ Feature: get quota
Background:
Given using OCS API version "1"
And user "Alice" has been created with default attributes and small skeleton files
And user "Alice" has been created with default attributes and without skeleton files
Scenario Outline: retrieving folder quota when no quota is set
@@ -35,7 +35,7 @@ Feature: get quota
Scenario Outline: retrieving folder quota of shared folder with quota when no quota is set for recipient
Given using <dav-path-version> DAV path
And user "Brian" has been created with default attributes and small skeleton files
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has been given unlimited quota
And the quota of user "Brian" has been set to "10 MB"
And user "Brian" has created folder "/testquota"
@@ -74,7 +74,7 @@ Feature: get quota
Scenario Outline: retrieving folder quota when quota is set and a file was received
Given using <dav-path-version> DAV path
And user "Brian" has been created with default attributes and small skeleton files
And user "Brian" has been created with default attributes and without skeleton files
And the quota of user "Brian" has been set to "1 KB"
And user "Alice" has uploaded file "/Alice.txt" of size 93 bytes
And user "Alice" has shared file "Alice.txt" with user "Brian"