Skip to content

Commit

Permalink
Tidy up tests (#494)
Browse files Browse the repository at this point in the history
* [Tests] Use collection expressions

* [Tests] Use collection expressions (part 2)

* [Tests] Apply formatting

* Try to make dotnet format happy
  • Loading branch information
iamcarbon authored Jan 16, 2024
1 parent 81e125d commit 2b60596
Show file tree
Hide file tree
Showing 10 changed files with 1,119 additions and 1,166 deletions.
2 changes: 1 addition & 1 deletion Test/Attestation/AndroidKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public async Task TestAndroidKeyAlgNotInMap()
public async Task TestAndroidKeySigNotASN1()
{
var attStmt = (CborMap)_attestationObject["attStmt"];
attStmt.Set("sig", new CborByteString(new byte[] { 0xf1, 0xd0 }));
attStmt.Set("sig", new CborByteString([0xf1, 0xd0]));
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
Assert.Equal("Failed to decode android key attestation signature from ASN.1 encoded form", ex.Message);

Expand Down
18 changes: 9 additions & 9 deletions Test/Attestation/Apple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class Apple : Fido2Tests.Attestation
public string[] validX5cStrings;
public Apple()
{
validX5cStrings = new[] {
validX5cStrings = [
"MIICRDCCAcmgAwIBAgIGAXUCfWGDMAoGCCqGSM49BAMCMEgxHDAaBgNVBAMME0FwcGxlIFdlYkF1dGhuIENBIDExEzARBgNVBAoMCkFwcGxlIEluYy4xEzARBgNVBAgMCkNhbGlmb3JuaWEwHhcNMjAxMDA3MDk0NjEyWhcNMjAxMDA4MDk1NjEyWjCBkTFJMEcGA1UEAwxANjEyNzZmYzAyZDNmZThkMTZiMzNiNTU0OWQ4MTkyMzZjODE3NDZhODNmMmU5NGE2ZTRiZWUxYzcwZjgxYjViYzEaMBgGA1UECwwRQUFBIENlcnRpZmljYXRpb24xEzARBgNVBAoMCkFwcGxlIEluYy4xEzARBgNVBAgMCkNhbGlmb3JuaWEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR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kwwUh4Udlg7Wp18etKyr44zSW4l9DIBb7wx/eLB6VxxugOBw=="
};
];
_attestationObject = new CborMap { { "fmt", "apple" } };
var (type, alg, crv) = Fido2Tests._validCOSEParameters[0];
X509Certificate2 root, attestnCert;
Expand Down Expand Up @@ -224,8 +224,8 @@ public async Task TestApplePublicKeyMismatch()
var attestationResponse = new AuthenticatorAttestationRawResponse
{
Type = PublicKeyCredentialType.PublicKey,
Id = new byte[] { 0xf1, 0xd0 },
RawId = new byte[] { 0xf1, 0xd0 },
Id = [0xf1, 0xd0],
RawId = [0xf1, 0xd0],
Response = new AuthenticatorAttestationRawResponse.AttestationResponse
{
AttestationObject = _attestationObject.Encode(),
Expand All @@ -244,10 +244,10 @@ public async Task TestApplePublicKeyMismatch()
},
Challenge = _challenge,
ErrorMessage = "",
PubKeyCredParams = new List<PubKeyCredParam>()
{
PubKeyCredParams =
[
PubKeyCredParam.ES256
},
],
Rp = new PublicKeyCredentialRpEntity("https://www.passwordless.dev", "6cc3c9e7967a.ngrok.io", ""),
Status = "ok",
User = new Fido2User
Expand All @@ -274,9 +274,9 @@ public async Task TestApplePublicKeyMismatch()
var credentialMakeResult = await lib.MakeNewCredentialAsync(attestationResponse, originalOptions, callback);
}

private string[] StackAllocSha256(byte[] authData, byte[] clientDataJson)
private string[] StackAllocSha256(ReadOnlySpan<byte> authData, ReadOnlySpan<byte> clientDataJson)
{
var data = DataHelper.Concat(authData, SHA256.HashData(clientDataJson));
byte[] data = [.. authData, .. SHA256.HashData(clientDataJson)];
Span<byte> dataHash = stackalloc byte[32];
SHA256.HashData(data, dataHash);

Expand Down
18 changes: 9 additions & 9 deletions Test/Attestation/FidoU2f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public FidoU2f()
var x = (byte[])_credentialPublicKey.GetCborObject()[COSE.KeyTypeParameter.X];
var y = (byte[])_credentialPublicKey.GetCborObject()[COSE.KeyTypeParameter.Y];

byte[] publicKeyU2F = DataHelper.Concat(new byte[1] { 0x4 }, x, y);
byte[] publicKeyU2F = [0x4, .. x, .. y];

byte[] verificationData = DataHelper.Concat(
new byte[1] { 0x00 },
_rpIdHash,
_clientDataHash,
_credentialID,
publicKeyU2F
);
byte[] verificationData = [
0x00,
.. _rpIdHash,
.. _clientDataHash,
.. _credentialID,
.. publicKeyU2F
];

byte[] signature = Fido2Tests.SignData(COSE.KeyType.EC2, COSE.Algorithm.ES256, verificationData, ecdsaAtt, null, null);

Expand Down Expand Up @@ -164,7 +164,7 @@ public async Task TestU2fSigByteStringZeroLen()
[Fact]
public async Task TestU2fSigNotASN1()
{
((CborMap)_attestationObject["attStmt"]).Set("sig", new CborByteString(new byte[] { 0xf1, 0xd0 }));
((CborMap)_attestationObject["attStmt"]).Set("sig", new CborByteString([0xf1, 0xd0]));
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
Assert.Equal("Failed to decode fido-u2f attestation signature from ASN.1 encoded form", ex.Message);
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Attestation/Packed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public async Task TestFull()
{
var avr = new VerifyAssertionResult
{
CredentialId = new byte[] { 0xf1, 0xd0 },
CredentialId = [0xf1, 0xd0],
ErrorMessage = string.Empty,
Status = "ok",
};
Expand Down
Loading

0 comments on commit 2b60596

Please sign in to comment.