Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2020-12-15 18:33:55 +0300
committerVincent Petry <vincent@nextcloud.com>2020-12-18 18:07:13 +0300
commitc0358096b3e5298803676928860e7f14c2beb337 (patch)
tree61b6650b687c4e6c0ac619da78120f50d587d3ba /tests
parentf68a87108fe14fc2f8b5c5789c43bc110cfb225b (diff)
Integration tests use occ guests:add to create guests
Removed cheat that used GuestManager directly from the guests app. Now using occ guests:add to create guest account users. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/bootstrap/CommandLineTrait.php5
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php20
-rw-r--r--tests/integration/spreedcheats/appinfo/routes.php1
-rw-r--r--tests/integration/spreedcheats/lib/Controller/ApiController.php27
4 files changed, 20 insertions, 33 deletions
diff --git a/tests/integration/features/bootstrap/CommandLineTrait.php b/tests/integration/features/bootstrap/CommandLineTrait.php
index d35315ec1..31b5c5b93 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 @@ trait CommandLineTrait {
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 a8d0e19ea..258ca643a 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -1583,11 +1583,23 @@ class FeatureContext implements Context, SnippetAcceptingContext {
$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 61b574d7d..7798d929f 100644
--- a/tests/integration/spreedcheats/appinfo/routes.php
+++ b/tests/integration/spreedcheats/appinfo/routes.php
@@ -26,6 +26,5 @@ 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 8a1556126..0490600fe 100644
--- a/tests/integration/spreedcheats/lib/Controller/ApiController.php
+++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php
@@ -29,7 +29,6 @@ use OCP\AppFramework\OCSController;
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 @@ class ApiController extends OCSController {
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();
- }
}