diff options
author | Vincent Petry <vincent@nextcloud.com> | 2020-12-08 20:15:17 +0300 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2020-12-11 20:15:51 +0300 |
commit | 7748fb93c2f122bb42fc9453e30648762486ba7c (patch) | |
tree | e14f72cc673b6c2a55fe9e927b8facc152ae1c52 /tests | |
parent | 6d75ad2b62a9f99b845596544c022b45e199a3fe (diff) |
Extend spreedcheats to allow creating guest account users
Added a spreedcheats endpoint to allow creating guest account
users for integration tests.
Grabs the GuestManager from the guests app to create a guest user in the
correct backend.
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'tests')
4 files changed, 42 insertions, 2 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index bf1e22965..d938360b1 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -69,6 +69,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { protected $createdGroups = []; /** @var array */ + protected $createdGuestAccountUsers = []; + + /** @var array */ protected $changedConfigs = []; /** @var SharingContext */ @@ -100,6 +103,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { $this->createdUsers = []; $this->createdGroups = []; + $this->createdGuestAccountUsers = []; } /** @@ -121,6 +125,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { foreach ($this->createdGroups as $group) { $this->deleteGroup($group); } + foreach ($this->createdGuestAccountUsers as $user) { + $this->deleteUser($user); + } } /** @@ -1418,6 +1425,21 @@ class FeatureContext implements Context, SnippetAcceptingContext { } } + /** + * @Given /^user "([^"]*)" is a guest account user/ + * @param string $user + */ + public function createGuestUser($user) { + $currentUser = $this->currentUser; + $this->setCurrentUser('admin'); + $this->sendRequest('POST', '/apps/spreedcheats/guest-users', [ + 'userid' => $user, + ]); + $this->assertStatusCode($this->response, 200); + $this->createdGuestAccountUsers[] = $user; + $this->setCurrentUser($currentUser); + } + private function userExists($user) { $currentUser = $this->currentUser; $this->setCurrentUser('admin'); diff --git a/tests/integration/features/callapi/joining-listable-rooms.feature b/tests/integration/features/callapi/joining-listable-rooms.feature index de890b929..0086ffbd4 100644 --- a/tests/integration/features/callapi/joining-listable-rooms.feature +++ b/tests/integration/features/callapi/joining-listable-rooms.feature @@ -2,8 +2,7 @@ Feature: callapi/listable-rooms Background: Given user "creator" exists And user "regular-user" exists - And user "user-guest" exists - And user "user-guest" is member of group "guest_app" + And user "user-guest" is a guest account user # implicit: And user "guest" is a guest user with no account # ----------------------------------------------------------------------------- diff --git a/tests/integration/spreedcheats/appinfo/routes.php b/tests/integration/spreedcheats/appinfo/routes.php index 7798d929f..61b574d7d 100644 --- a/tests/integration/spreedcheats/appinfo/routes.php +++ b/tests/integration/spreedcheats/appinfo/routes.php @@ -26,5 +26,6 @@ declare(strict_types=1); 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 654a7be93..745ba8ce2 100644 --- a/tests/integration/spreedcheats/lib/Controller/ApiController.php +++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php @@ -74,4 +74,22 @@ class ApiController extends OCSController { return new DataResponse(); } + + /** + * @NoCSRFRequired + * + * @return DataResponse + */ + public function createGuestAppUser($userid): DataResponse { + $guestAppContainer =\OC::$server->getRegisteredAppContainer('guests'); + $guestManager = $guestAppContainer->query('\OCA\Guests\GuestManager'); + $guestManager->createGuest( + \OC::$server->getUserSession()->getUser(), + $userid, + $userid . '@localhost', + $userid . '-displayname' + ); + + return new DataResponse(); + } } |