diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 35217a455a0..71e071abce8 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -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) diff --git a/tests/acceptance/features/apiGraph/editUser.feature b/tests/acceptance/features/apiGraph/editUser.feature index 93f8968a0a7..7168269ed57 100644 --- a/tests/acceptance/features/apiGraph/editUser.feature +++ b/tests/acceptance/features/apiGraph/editUser.feature @@ -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 "" using the Graph API diff --git a/tests/acceptance/features/apiGraph/getUser.feature b/tests/acceptance/features/apiGraph/getUser.feature index 0ef67b5e321..e9f2cd0d0a8 100644 --- a/tests/acceptance/features/apiGraph/getUser.feature +++ b/tests/acceptance/features/apiGraph/getUser.feature @@ -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 "" 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 diff --git a/tests/acceptance/features/bootstrap/AppConfigurationContext.php b/tests/acceptance/features/bootstrap/AppConfigurationContext.php index 69eef74801e..59f83b39918 100644 --- a/tests/acceptance/features/bootstrap/AppConfigurationContext.php +++ b/tests/acceptance/features/bootstrap/AppConfigurationContext.php @@ -171,7 +171,7 @@ public function theUserGetsCapabilitiesCheckResponse():void { /** * @return string - * @throws Exception + * @throws Exception|GuzzleException */ public function getAdminUsernameForCapabilitiesCheck():string { if (\TestHelpers\OcisHelper::isTestingOnReva()) { @@ -182,7 +182,7 @@ public function getAdminUsernameForCapabilitiesCheck():string { $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(); diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index acadf6010e5..13a8344e0ad 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -724,41 +724,6 @@ public function theAdminHasRetrievedMembersListOfGroupUsingTheGraphApi(string $g 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 @@ public function theUserCreatesNewUser(string $user, TableNode $table): void { $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 * diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index bb539b0e865..3ab6aa6d26a 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -29,6 +29,7 @@ use TestHelpers\HttpRequestHelper; use TestHelpers\OcisHelper; use TestHelpers\WebDavHelper; +use TestHelpers\GraphHelper; use Laminas\Ldap\Exception\LdapException; use Laminas\Ldap\Ldap; @@ -362,108 +363,31 @@ public function theGroupShouldExist(string $groupname):bool { } /** - * - * @param string $groupname - * - * @return boolean - * @throws Exception - */ - public function theGroupShouldBeAbleToBeDeleted(string $groupname):bool { - if (\array_key_exists($groupname, $this->createdGroups)) { - return $this->createdGroups[$groupname]['possibleToDelete'] ?? true; - } - - if (\array_key_exists($groupname, $this->createdRemoteGroups)) { - return $this->createdRemoteGroups[$groupname]['possibleToDelete'] ?? true; - } - - throw new Exception( - __METHOD__ - . " group '$groupname' was not created by this test run" - ); - } - - /** - * @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$/ + * @Given user :user has been created with default attributes and without skeleton files * * @param string $user - * @param string $skeletonType - * @param boolean $skeleton * * @return void - * @throws Exception + * @throws Exception|GuzzleException */ public function userHasBeenCreatedWithDefaultAttributes( - string $user, - string $skeletonType = "", - bool $skeleton = true + string $user ):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); - } + $this->userHasBeenCreated(["userName" => $user]); } /** - * @Given /^user "([^"]*)" has been created with default attributes and without skeleton files$/ + * @Given these users have been created without skeleton files and not initialized: * - * @param string $user + * @param TableNode $table * * @return void - * @throws Exception + * @throws Exception|GuzzleException */ - public function userHasBeenCreatedWithDefaultAttributesAndWithoutSkeletonFiles(string $user):void { - $this->userHasBeenCreatedWithDefaultAttributes($user); + public function userHasBeenCreatedWithDefaultAttributesAndNotInitialized( + TableNode $table + ):void { + $this->usersHaveBeenCreated($table, true, false); } /** @@ -477,29 +401,46 @@ public function userHasBeenCreatedWithDefaultAttributesAndWithoutSkeletonFiles(s * @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); - } + $this->usersHaveBeenCreated($table); } /** - * @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 + * @Given the user :byUser has created a new user using the Graph API with the following settings: * + * @param string $byUser * @param TableNode $table - * @param string $doNotInitialize * * @return void + * @throws Exception|GuzzleException + */ + public function theAdministratorHasCreatedANewUserWithFollowingSettings(string $byUser, TableNode $table): void { + $rows = $table->getRowsHash(); + $this->userHasBeenCreated( + $rows, + $byUser + ); + } + + /** + * + * @param string $groupname + * + * @return boolean * @throws Exception */ - public function theseUsersHaveBeenCreatedWithoutSkeletonFiles(TableNode $table, string $doNotInitialize):void { - $this->theseUsersHaveBeenCreated("", "", $doNotInitialize, $table); + public function theGroupShouldBeAbleToBeDeleted(string $groupname):bool { + if (\array_key_exists($groupname, $this->createdGroups)) { + return $this->createdGroups[$groupname]['possibleToDelete'] ?? true; + } + + if (\array_key_exists($groupname, $this->createdRemoteGroups)) { + return $this->createdRemoteGroups[$groupname]['possibleToDelete'] ?? true; + } + + throw new Exception( + __METHOD__ + . " group '$groupname' was not created by this test run" + ); } /** @@ -837,43 +778,36 @@ public function manuallyAddSkeletonFiles(array $usersAttributes):void { } /** + * 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 @@ public function usersHaveBeenCreated( } 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 @@ public function usersHaveBeenCreated( $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 @@ public function userRetrievesTheInformationOfUserUsingTheProvisioningApi( * @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 @@ public function userGetsTheListOfAllUsersUsingTheProvisioningApi(string $user):v * @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 @@ public function rememberThatUserIsNotExpectedToExist(string $user):void { /** * 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 @@ public function createUser( $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 @@ public function cleanupGroup(string $group):void { } /** - * @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()) { + public function userExists(string $user):bool { + $path = (!OcisHelper::isTestingOnReva()) + ? "/graph/v1.0" + : "/ocs/v2.php/cloud"; + $fullUrl = $this->getBaseUrl() . $path . "/users/$user"; + + if (OcisHelper::isTestingOnReva()) { $requestingUser = $this->getActualUsername($user); $requestingPassword = $this->getPasswordForUser($user); - } elseif (OcisHelper::isTestingWithGraphApi()) { + } else { $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()) - ? "/graph/v1.0" - : "/ocs/v2.php/cloud"; - $fullUrl = $this->getBaseUrl() . $path . "/users/$user"; - - $this->response = HttpRequestHelper::get( + $response = HttpRequestHelper::get( $fullUrl, $this->getStepLineRef(), $requestingUser, $requestingPassword ); - if ($this->response->getStatusCode() >= 400) { + if ($response->getStatusCode() >= 400) { return false; } return true; diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index bcb511c7db4..1e5809cb632 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -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 @@ public function userUploadsAFileToWithAllMechanismsExceptNewChunking( false, 'new' ); - - $this->pushToLastStatusCodesArrays(); } /** diff --git a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareGroupAndUserWithSameName.feature b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareGroupAndUserWithSameName.feature index 7a8b3db185e..39b94e112a7 100644 --- a/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareGroupAndUserWithSameName.feature +++ b/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareGroupAndUserWithSameName.feature @@ -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 | diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature index 039dd1ab75e..c2408a0ffaa 100644 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature +++ b/tests/acceptance/features/coreApiShareManagementBasicToShares/createShareToSharesFolder.feature @@ -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 "" 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 "" And the HTTP status code should be "200" diff --git a/tests/acceptance/features/coreApiVersions/fileVersions.feature b/tests/acceptance/features/coreApiVersions/fileVersions.feature index 40e5b48bf18..92124d2fae1 100644 --- a/tests/acceptance/features/coreApiVersions/fileVersions.feature +++ b/tests/acceptance/features/coreApiVersions/fileVersions.feature @@ -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 diff --git a/tests/acceptance/features/coreApiWebdavProperties1/getQuota.feature b/tests/acceptance/features/coreApiWebdavProperties1/getQuota.feature index fec64b8198c..09505c6291e 100644 --- a/tests/acceptance/features/coreApiWebdavProperties1/getQuota.feature +++ b/tests/acceptance/features/coreApiWebdavProperties1/getQuota.feature @@ -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 - 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 - 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"