From 1d1df98e0f094d104d538fc06d859e215c1ce837 Mon Sep 17 00:00:00 2001 From: Vincent Talbot Date: Mon, 25 Oct 2021 10:32:59 -0400 Subject: [PATCH 1/2] Allow CI tools to login by providing the token in the command --- app/Commands/LoginCommand.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Commands/LoginCommand.php b/app/Commands/LoginCommand.php index c5436db..39dbab7 100644 --- a/app/Commands/LoginCommand.php +++ b/app/Commands/LoginCommand.php @@ -11,7 +11,7 @@ class LoginCommand extends Command * * @var string */ - protected $signature = 'login'; + protected $signature = 'login {--token= : Forge API token}'; /** * The description of the command. @@ -27,7 +27,11 @@ class LoginCommand extends Command */ public function handle() { - $token = $this->askStep('Please enter your Forge API token'); + $token = $this->option('token'); + + if ($token === null) { + $token = $this->askStep('Please enter your Forge API token'); + } $this->config->set('token', $token); From 85c5320bc0b34ee07d63d8bdcb69a46aa55cea48 Mon Sep 17 00:00:00 2001 From: Vincent Talbot Date: Mon, 25 Oct 2021 13:22:00 -0400 Subject: [PATCH 2/2] Add test for login with token option --- tests/Feature/LoginCommandTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Feature/LoginCommandTest.php b/tests/Feature/LoginCommandTest.php index be55faf..50013c7 100755 --- a/tests/Feature/LoginCommandTest.php +++ b/tests/Feature/LoginCommandTest.php @@ -14,6 +14,19 @@ ->expectsOutput('==> Authenticated Successfully As [nuno@laravel.com]'); }); +it('authenticates users with token', function () { + $this->client->shouldReceive('user')->andReturn((object) [ + 'email' => 'nuno@laravel.com', + ]); + + $this->client->shouldReceive('servers')->andReturn([ + (object) ['id' => 1], + ]); + + $this->artisan('login --token 123123123') + ->expectsOutput('==> Authenticated Successfully As [nuno@laravel.com]'); +}); + it('sets current server', function () { $this->client->shouldReceive('user')->andReturn((object) [ 'email' => 'nuno@laravel.com',