$this->actingAs($user)->postJson('/api/client/account/ssh-keys',['name'=>'Name','public_key'=>$key->public_key])->assertUnprocessable()->assertJsonPath('errors.0.detail','DSA keys are not supported.');
expect($user->sshKeys()->count())->toEqual(0);
});
test('weak rsa key is rejected',function():void{
$user=User::factory()->create();
$key=UserSSHKey::factory()->rsa(true)->make();
$this->actingAs($user)->postJson('/api/client/account/ssh-keys',['name'=>'Name','public_key'=>$key->public_key])->assertUnprocessable()->assertJsonPath('errors.0.detail','RSA keys must be at least 2048 bytes in length.');
expect($user->sshKeys()->count())->toEqual(0);
});
test('invalid or private key is rejected',function():void{
$user=User::factory()->create();
$this->actingAs($user)->postJson('/api/client/account/ssh-keys',['name'=>'Name','public_key'=>'invalid'])->assertUnprocessable()->assertJsonPath('errors.0.detail','The public key provided is not valid.');
expect($user->sshKeys()->count())->toEqual(0);
$key=EC::createKey('Ed25519');
$this->actingAs($user)->postJson('/api/client/account/ssh-keys',['name'=>'Name','public_key'=>$key->toString('PKCS8')])->assertUnprocessable()->assertJsonPath('errors.0.detail','The public key provided is not valid.');
});
test('only supported public key material can be stored',function(string$publicKey):void{
test('public key that already exists cannot be added a second time',function():void{
$user=User::factory()->create();
$key=UserSSHKey::factory()->for($user)->create();
$this->actingAs($user)->postJson('/api/client/account/ssh-keys',['name'=>'Name','public_key'=>$key->public_key])->assertUnprocessable()->assertJsonPath('errors.0.detail','The public key provided already exists on your account.');