diff --git a/tests/integration/features/bootstrap/CommandLineTrait.php b/tests/integration/features/bootstrap/CommandLineTrait.php index d35315ec18b..31b5c5b931e 100644 --- a/tests/integration/features/bootstrap/CommandLineTrait.php +++ b/tests/integration/features/bootstrap/CommandLineTrait.php @@ -43,9 +43,10 @@ trait CommandLineTrait { * Invokes an OCC command * * @param []string $args OCC command, the part behind "occ". For example: "files:transfer-ownership" + * @param []string $env environment variables * @return int exit code */ - public function runOcc($args = []) { + public function runOcc($args = [], $env = null) { // Set UTF-8 locale to ensure that escapeshellarg will not strip // multibyte characters. setlocale(LC_CTYPE, "C.UTF-8"); @@ -61,7 +62,7 @@ public function runOcc($args = []) { 1 => ['pipe', 'w'], 2 => ['pipe', 'w'], ]; - $process = proc_open('php console.php ' . $args, $descriptor, $pipes, $this->ocPath); + $process = proc_open('php console.php ' . $args, $descriptor, $pipes, $this->ocPath, $env); $this->lastStdOut = stream_get_contents($pipes[1]); $this->lastStdErr = stream_get_contents($pipes[2]); $this->lastCode = proc_close($process); diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index e30bb97f778..686b34d66e0 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -1583,11 +1583,23 @@ public function createGuestUser($user) { $this->setCurrentUser('admin'); // in case it exists $this->deleteUser($user); - $this->sendRequest('POST', '/apps/spreedcheats/guest-users', [ - 'userid' => $user, - 'password' => self::TEST_PASSWORD, + + $lastCode = $this->runOcc([ + 'guests:add', + // creator user + 'admin', + // guest user id + $user, + // email + $user . '@localhost', + '--display-name', + $user . '-displayname', + '--password-from-env', + ], [ + 'OC_PASS' => self::TEST_PASSWORD, ]); - $this->assertStatusCode($this->response, 200); + Assert::assertEquals(0, $lastCode, 'Guest creation succeeded for ' . $user); + $this->createdGuestAccountUsers[] = $user; $this->setCurrentUser($currentUser); } diff --git a/tests/integration/spreedcheats/appinfo/routes.php b/tests/integration/spreedcheats/appinfo/routes.php index 61b574d7d15..7798d929fe4 100644 --- a/tests/integration/spreedcheats/appinfo/routes.php +++ b/tests/integration/spreedcheats/appinfo/routes.php @@ -26,6 +26,5 @@ return [ 'ocs' => [ ['name' => 'Api#resetSpreed', 'url' => '/', 'verb' => 'DELETE'], - ['name' => 'Api#createGuestAppUser', 'url' => '/guest-users', 'verb' => 'POST'], ], ]; diff --git a/tests/integration/spreedcheats/lib/Controller/ApiController.php b/tests/integration/spreedcheats/lib/Controller/ApiController.php index 8a15561269d..0490600fe8c 100644 --- a/tests/integration/spreedcheats/lib/Controller/ApiController.php +++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php @@ -29,7 +29,6 @@ use OCP\AppFramework\Http\DataResponse; use OCP\IDBConnection; use OCP\IRequest; -use OCP\IUserManager; use OCP\Share\IShare; class ApiController extends OCSController { @@ -37,13 +36,9 @@ class ApiController extends OCSController { /** @var IDBConnection */ private $db; - /** @var IUserManager */ - private $userManager; - public function __construct(string $appName, IRequest $request, - IDBConnection $db, - IUserManager $userManager + IDBConnection $db ) { parent::__construct($appName, $request); $this->db = $db; @@ -81,24 +76,4 @@ public function resetSpreed(): DataResponse { return new DataResponse(); } - - /** - * @NoCSRFRequired - * - * @return DataResponse - */ - public function createGuestAppUser(string $userid, string $password): DataResponse { - $guestAppContainer = \OC::$server->getRegisteredAppContainer('guests'); - $guestManager = $guestAppContainer->query('\OCA\Guests\GuestManager'); - $guestManager->createGuest( - \OC::$server->getUserSession()->getUser(), - $userid, - $userid . '@localhost', - $userid . '-displayname' - ); - - $this->userManager->get($userid)->setPassword($password); - - return new DataResponse(); - } }