Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Requests/CreateKeyLookupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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').'.');
}

/**
Expand Down
23 changes: 22 additions & 1 deletion tests/Feature/Controllers/Cli/KeyLookupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down