diff --git a/app/Http/Requests/CreateKeyLookupRequest.php b/app/Http/Requests/CreateKeyLookupRequest.php index a3f037ae8b..58d4f32d95 100644 --- a/app/Http/Requests/CreateKeyLookupRequest.php +++ b/app/Http/Requests/CreateKeyLookupRequest.php @@ -18,7 +18,7 @@ public function authorize(): Response { return $this->publicKey() instanceof SshPublicKey ? Response::allow() - : Response::denyAsNotFound('None of your SSH keys are on the GitHub account of a /dev/null user. Add your key on GitHub (Settings → SSH and GPG keys), then sign in on '.url('/').'.'); + : Response::denyAsNotFound('None of your SSH keys are on the GitHub account of a /dev/null user. Add your key on GitHub (Settings → SSH and GPG keys), then click Sync from GitHub on '.route('user-profile.edit').'.'); } /** diff --git a/tests/Feature/Controllers/Cli/KeyLookupControllerTest.php b/tests/Feature/Controllers/Cli/KeyLookupControllerTest.php index 2bb5d1d7ca..93c03a312e 100644 --- a/tests/Feature/Controllers/Cli/KeyLookupControllerTest.php +++ b/tests/Feature/Controllers/Cli/KeyLookupControllerTest.php @@ -2,7 +2,9 @@ declare(strict_types=1); +use App\Contracts\Services\GitHubProvider; use App\Models\SshKey; +use App\Models\User; use Illuminate\Support\Facades\Http; use Tests\Support\SshKeyPair; @@ -33,7 +35,26 @@ $response->assertNotFound() ->assertHeader('Content-Type', 'text/plain; charset=utf-8') - ->assertSee('None of your SSH keys are on the GitHub account of a /dev/null user.'); + ->assertSee('None of your SSH keys are on the GitHub account of a /dev/null user.') + ->assertSee('then click Sync from GitHub on '.route('user-profile.edit').'.'); +}); + +it('finds a key added on github after signing in once the user syncs from github', function (): void { + $user = User::factory()->create(['github_id' => '42']); + $key = SshKeyPair::generate()->publicKey; + $github = $this->mock(GitHubProvider::class); + $github->shouldReceive('account')->with('42')->andReturn(['login' => 'taylor']); + $github->shouldReceive('login')->with('42')->andReturn('taylor'); + $github->shouldReceive('sshKeys')->with('taylor')->andReturn([$key->toOpenSsh()]); + + $this->call('POST', route('cli-key-lookup.store'), content: $key->toOpenSsh())->assertNotFound(); + + $this->actingAs($user)->put(route('user-profile.update')) + ->assertInertiaFlash('toast', ['type' => 'success', 'message' => 'Synced from GitHub.']); + + $this->call('POST', route('cli-key-lookup.store'), content: $key->toOpenSsh()) + ->assertOk() + ->assertContent($key->toOpenSsh()."\n"); }); it('only considers the first 20 keys', function (): void {