Skip to content

Commit

Permalink
Flip around where AsSpan is called with string comparisons in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerhardt committed Nov 6, 2024
1 parent 540cf1a commit 0f9d339
Show file tree
Hide file tree
Showing 17 changed files with 156 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public void Encrypt_KnownKey()
// | 00 00 00 00 (postBuffer)

string retValAsString = Convert.ToBase64String(retVal);
Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA".AsSpan(), retValAsString);
Assert.Equal("AAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaG0O2kY0NZtmh2UQtXY5B2jlgnOgAAAAA", retValAsString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void Protect_EncryptsToDefaultProtector_MultiplePurposes()
.Setup(o => o.Encrypt(It.IsAny<ArraySegment<byte>>(), It.IsAny<ArraySegment<byte>>()))
.Returns<ArraySegment<byte>, ArraySegment<byte>>((actualPlaintext, actualAad) =>
{
Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext);
Assert.Equal(expectedAad.AsSpan(), actualAad);
Assert.Equal(expectedPlaintext, actualPlaintext.AsSpan());
Assert.Equal(expectedAad, actualAad.AsSpan());
return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag
});

Expand Down Expand Up @@ -83,8 +83,8 @@ public void Protect_EncryptsToDefaultProtector_SinglePurpose()
.Setup(o => o.Encrypt(It.IsAny<ArraySegment<byte>>(), It.IsAny<ArraySegment<byte>>()))
.Returns<ArraySegment<byte>, ArraySegment<byte>>((actualPlaintext, actualAad) =>
{
Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext);
Assert.Equal(expectedAad.AsSpan(), actualAad);
Assert.Equal(expectedPlaintext, actualPlaintext.AsSpan());
Assert.Equal(expectedAad, actualAad.AsSpan());
return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag
});

Expand Down Expand Up @@ -423,8 +423,8 @@ public void Unprotect_KeyRevoked_RevocationAllowed_ReturnsOriginalData_SetsRevok
.Setup(o => o.Decrypt(It.IsAny<ArraySegment<byte>>(), It.IsAny<ArraySegment<byte>>()))
.Returns<ArraySegment<byte>, ArraySegment<byte>>((actualCiphertext, actualAad) =>
{
Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext);
Assert.Equal(expectedAad.AsSpan(), actualAad);
Assert.Equal(expectedCiphertext, actualCiphertext.AsSpan());
Assert.Equal(expectedAad, actualAad.AsSpan());
return expectedPlaintext;
});
var mockDescriptor = new Mock<IAuthenticatedEncryptorDescriptor>();
Expand Down Expand Up @@ -470,8 +470,8 @@ public void Unprotect_IsAlsoDefaultKey_Success_NoMigrationRequired()
.Setup(o => o.Decrypt(It.IsAny<ArraySegment<byte>>(), It.IsAny<ArraySegment<byte>>()))
.Returns<ArraySegment<byte>, ArraySegment<byte>>((actualCiphertext, actualAad) =>
{
Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext);
Assert.Equal(expectedAad.AsSpan(), actualAad);
Assert.Equal(expectedCiphertext, actualCiphertext.AsSpan());
Assert.Equal(expectedAad, actualAad.AsSpan());
return expectedPlaintext;
});
var mockDescriptor = new Mock<IAuthenticatedEncryptorDescriptor>();
Expand Down Expand Up @@ -519,8 +519,8 @@ public void Unprotect_IsNotDefaultKey_Success_RequiresMigration()
.Setup(o => o.Decrypt(It.IsAny<ArraySegment<byte>>(), It.IsAny<ArraySegment<byte>>()))
.Returns<ArraySegment<byte>, ArraySegment<byte>>((actualCiphertext, actualAad) =>
{
Assert.Equal(expectedCiphertext.AsSpan(), actualCiphertext);
Assert.Equal(expectedAad.AsSpan(), actualAad);
Assert.Equal(expectedCiphertext, actualCiphertext.AsSpan());
Assert.Equal(expectedAad, actualAad.AsSpan());
return expectedPlaintext;
});
var mockDescriptor = new Mock<IAuthenticatedEncryptorDescriptor>();
Expand Down Expand Up @@ -594,8 +594,8 @@ public void CreateProtector_ChainsPurposes()
.Setup(o => o.Encrypt(It.IsAny<ArraySegment<byte>>(), It.IsAny<ArraySegment<byte>>()))
.Returns<ArraySegment<byte>, ArraySegment<byte>>((actualPlaintext, actualAad) =>
{
Assert.Equal(expectedPlaintext.AsSpan(), actualPlaintext);
Assert.Equal(expectedAad.AsSpan(), actualAad);
Assert.Equal(expectedPlaintext, actualPlaintext.AsSpan());
Assert.Equal(expectedAad, actualAad.AsSpan());
return new byte[] { 0x23, 0x29, 0x31, 0x37 }; // ciphertext + tag
});

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Headers/test/CacheControlHeaderValueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public void Properties_SetAndGetAllProperties_SetValueReturnedInGetter()
Assert.Throws<FormatException>(() => cacheControl.NoCacheHeaders.Add("invalid PLACEHOLDER"));
cacheControl.NoCacheHeaders.Add("PLACEHOLDER");
Assert.Single(cacheControl.NoCacheHeaders);
Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.NoCacheHeaders.First());
Assert.Equal("PLACEHOLDER", cacheControl.NoCacheHeaders.First().AsSpan());

Assert.NotNull(cacheControl.PrivateHeaders);
Assert.Throws<ArgumentException>(() => cacheControl.PrivateHeaders.Add(null));
Assert.Throws<FormatException>(() => cacheControl.PrivateHeaders.Add("invalid PLACEHOLDER"));
cacheControl.PrivateHeaders.Add("PLACEHOLDER");
Assert.Single(cacheControl.PrivateHeaders);
Assert.Equal("PLACEHOLDER".AsSpan(), cacheControl.PrivateHeaders.First());
Assert.Equal("PLACEHOLDER", cacheControl.PrivateHeaders.First().AsSpan());

// NameValueHeaderValue collection property
Assert.NotNull(cacheControl.Extensions);
Expand Down
Loading

0 comments on commit 0f9d339

Please sign in to comment.