Skip to content

Commit

Permalink
Integration tests use occ guests:add to create guests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
PVince81 committed Dec 17, 2020
1 parent 250139d commit a384b3f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
5 changes: 3 additions & 2 deletions tests/integration/features/bootstrap/CommandLineTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
20 changes: 16 additions & 4 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion tests/integration/spreedcheats/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@
return [
'ocs' => [
['name' => 'Api#resetSpreed', 'url' => '/', 'verb' => 'DELETE'],
['name' => 'Api#createGuestAppUser', 'url' => '/guest-users', 'verb' => 'POST'],
],
];
27 changes: 1 addition & 26 deletions tests/integration/spreedcheats/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Share\IShare;

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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit a384b3f

Please sign in to comment.