Add ability to specify auth tokens when creating new users

This commit is contained in:
Marcel Pociot
2021-06-07 21:02:26 +02:00
parent 8664d7ea80
commit 4131b6abb7
2 changed files with 29 additions and 1 deletions

View File

@@ -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'),

View File

@@ -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()
{