mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-22 11:35:21 +01:00
[PM-5731] feat: add unknown error handling
This commit is contained in:
parent
c90ed74faa
commit
8be604feac
@ -83,9 +83,14 @@ namespace Bit.Core.Services
|
||||
var reencrypted = await _cipherService.EncryptAsync(cipher);
|
||||
await _cipherService.SaveWithServerAsync(reencrypted);
|
||||
credentialId = fido2Credential.CredentialId;
|
||||
} catch {
|
||||
} catch (NotAllowedError) {
|
||||
throw;
|
||||
// throw new NotImplementedException();
|
||||
} catch (Exception e) {
|
||||
_logService.Error(
|
||||
$"[Fido2Authenticator] Unknown error occured during attestation: {e.Message}"
|
||||
);
|
||||
|
||||
throw new UnknownError();
|
||||
}
|
||||
|
||||
return new Fido2AuthenticatorMakeCredentialResult
|
||||
@ -182,9 +187,9 @@ namespace Bit.Core.Services
|
||||
AuthenticatorData = authenticatorData,
|
||||
Signature = signature
|
||||
};
|
||||
} catch {
|
||||
_logService.Info(
|
||||
"[Fido2Authenticator] Aborting because no matching credentials were found in the vault."
|
||||
} catch (Exception e) {
|
||||
_logService.Error(
|
||||
$"[Fido2Authenticator] Unknown error occured during assertion: {e.Message}"
|
||||
);
|
||||
|
||||
throw new UnknownError();
|
||||
|
@ -365,20 +365,33 @@ namespace Bit.Core.Test.Services
|
||||
await Assert.ThrowsAsync<NotAllowedError>(() => sutProvider.Sut.MakeCredentialAsync(mParams));
|
||||
}
|
||||
|
||||
// /** Spec: If any error occurred while creating the new credential object, return an error code equivalent to "UnknownError" and terminate the operation. */
|
||||
// it("should throw unkown error if creation fails", async () => {
|
||||
// const _encryptedCipher = Symbol();
|
||||
// userInterfaceSession.confirmNewCredential.mockResolvedValue({
|
||||
// cipherId: existingCipher.id,
|
||||
// userVerified: false,
|
||||
// });
|
||||
// cipherService.encrypt.mockResolvedValue(_encryptedCipher as unknown as Cipher);
|
||||
// cipherService.updateWithServer.mockRejectedValue(new Error("Internal error"));
|
||||
[Theory]
|
||||
[InlineCustomAutoData(new[] { typeof(SutProviderCustomization) })]
|
||||
public async Task MakeCredentialAsync_ThrowsUnknownError_SavingCipherFails(SutProvider<Fido2AuthenticatorService> sutProvider, Fido2AuthenticatorMakeCredentialParams mParams)
|
||||
{
|
||||
// Common Arrange
|
||||
mParams.CredTypesAndPubKeyAlgs = [
|
||||
new PublicKeyCredentialAlgorithmDescriptor {
|
||||
Type = "public-key",
|
||||
Algorithm = -7 // ES256
|
||||
}
|
||||
];
|
||||
mParams.RpEntity = new PublicKeyCredentialRpEntity { Id = "bitwarden.com" };
|
||||
mParams.RequireUserVerification = false;
|
||||
sutProvider.GetDependency<ICryptoFunctionService>().EcdsaGenerateKeyPairAsync(Arg.Any<CryptoEcdsaAlgorithm>())
|
||||
.Returns((RandomBytes(32), RandomBytes(32)));
|
||||
|
||||
// const result = async () => await authenticator.makeCredential(params, tab);
|
||||
// Arrange
|
||||
sutProvider.GetDependency<ICipherService>().GetAsync(Arg.Is(_encryptedCipher.Id)).Returns(_encryptedCipher);
|
||||
sutProvider.GetDependency<IFido2UserInterface>().ConfirmNewCredentialAsync(Arg.Any<Fido2ConfirmNewCredentialParams>()).Returns(new Fido2ConfirmNewCredentialResult {
|
||||
CipherId = _encryptedCipher.Id,
|
||||
UserVerified = false
|
||||
});
|
||||
sutProvider.GetDependency<ICipherService>().SaveWithServerAsync(Arg.Any<Cipher>()).Throws(new Exception("Error"));
|
||||
|
||||
// await expect(result).rejects.toThrowError(Fido2AuthenticatorErrorCode.Unknown);
|
||||
// });
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<UnknownError>(() => sutProvider.Sut.MakeCredentialAsync(mParams));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user