From 4131b6abb7957be6a2fad9fe62b697e1439415f3 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 7 Jun 2021 21:02:26 +0200 Subject: [PATCH] Add ability to specify auth tokens when creating new users --- .../Admin/StoreUsersController.php | 2 +- tests/Feature/Server/ApiTest.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/Server/Http/Controllers/Admin/StoreUsersController.php b/app/Server/Http/Controllers/Admin/StoreUsersController.php index b846f92..0d83292 100644 --- a/app/Server/Http/Controllers/Admin/StoreUsersController.php +++ b/app/Server/Http/Controllers/Admin/StoreUsersController.php @@ -37,7 +37,7 @@ class StoreUsersController extends AdminController $insertData = [ 'name' => $request->get('name'), - 'auth_token' => (string) Str::uuid(), + 'auth_token' => $request->get('token', (string) Str::uuid()), 'can_specify_subdomains' => (int) $request->get('can_specify_subdomains'), 'can_specify_domains' => (int) $request->get('can_specify_domains'), 'can_share_tcp_ports' => (int) $request->get('can_share_tcp_ports'), diff --git a/tests/Feature/Server/ApiTest.php b/tests/Feature/Server/ApiTest.php index b7f749f..2fb2f98 100644 --- a/tests/Feature/Server/ApiTest.php +++ b/tests/Feature/Server/ApiTest.php @@ -65,6 +65,34 @@ class ApiTest extends TestCase $this->assertSame([], $users[0]->sites); } + /** @test */ + public function it_can_specify_tokens_when_creating_a_user() + { + /** @var Response $response */ + $this->await($this->browser->post('http://127.0.0.1:8080/api/users', [ + 'Host' => 'expose.localhost', + 'Authorization' => base64_encode('username:secret'), + 'Content-Type' => 'application/json', + ], json_encode([ + 'name' => 'Marcel', + 'token' => 'this-is-my-token' + ]))); + + /** @var Response $response */ + $response = $this->await($this->browser->get('http://127.0.0.1:8080/api/users', [ + 'Host' => 'expose.localhost', + 'Authorization' => base64_encode('username:secret'), + 'Content-Type' => 'application/json', + ])); + + $body = json_decode($response->getBody()->getContents()); + $users = $body->paginated->users; + + $this->assertCount(1, $users); + $this->assertSame('Marcel', $users[0]->name); + $this->assertSame('this-is-my-token', $users[0]->auth_token); + } + /** @test */ public function it_does_not_allow_domain_reservation_for_users_without_the_right_flag() {