public void SetNullAlgorithmName() { using (HMAC hmac = new TestHMAC()) { Assert.Throws <ArgumentNullException>(() => hmac.HashName = null); Assert.Null(hmac.HashName); } }
public void SetNullAlgorithmName() { using (HMAC hmac = new TestHMAC()) { // Assert.NoThrows is implicit hmac.HashName = null; Assert.Null(hmac.HashName); } }
public void TrivialDerivationThrows() { using (HMAC hmac = new TestHMAC()) { hmac.HashName = "SHA1"; hmac.Key = Array.Empty <byte>(); byte[] ignored; Assert.Throws <PlatformNotSupportedException>(() => ignored = hmac.ComputeHash(Array.Empty <byte>())); } }
public void TrivialDerivationThrows() { using (HMAC hmac = new TestHMAC()) { hmac.HashName = "SHA1"; hmac.Key = Array.Empty<byte>(); byte[] ignored; Assert.Throws<PlatformNotSupportedException>(() => ignored = hmac.ComputeHash(Array.Empty<byte>())); } }
public void SetUnknownAlgorithmName() { using (HMAC hmac = new TestHMAC()) { const string UnknownAlgorithmName = "No known algorithm name has spaces, so this better be invalid..."; // Assert.NoThrows is implicit hmac.HashName = UnknownAlgorithmName; Assert.Equal(UnknownAlgorithmName, hmac.HashName); } }
public void ResetAlgorithmName() { using (HMAC hmac = new TestHMAC()) { hmac.HashName = "SHA1"; // On desktop builds this next line will succeed (modulo FIPS prohibitions on MD5). // On CoreFX it throws. Assert.Throws <PlatformNotSupportedException>(() => hmac.HashName = "MD5"); Assert.Equal("SHA1", hmac.HashName); } }
public void ResetAlgorithmName() { using (HMAC hmac = new TestHMAC()) { hmac.HashName = "SHA1"; // On desktop builds this next line will succeed (modulo FIPS prohibitions on MD5). // On CoreFX it throws. Assert.Throws<PlatformNotSupportedException>(() => hmac.HashName = "MD5"); Assert.Equal("SHA1", hmac.HashName); } }
public void ReassignAlgorithmName() { using (HMAC hmac = new TestHMAC()) { hmac.HashName = "SHA1"; hmac.HashName = hmac.HashName; // Set it again using a guaranteed-to-be-new copy to ensure it is // permissive based on value equality semantics hmac.HashName = new string(new[] { 'S', 'H', 'A', '1' }); Assert.Equal("SHA1", hmac.HashName); } }
public void WhenRequest_ThenHeadersOk() { ClientsPoolProvider.ClearDefaults(); // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, EventHandler)) { var encoding = new System.Text.UnicodeEncoding(); byte[] secretKey = encoding.GetBytes("DummyKey"); int applicationId = 1; IHMAC hmac = new TestHMAC(); var client = new YouScribeClient(TestHelpers.BaseUrl, YousScribeHMACHttpClientDecorator.GetBaseClientFactory(secretKey, applicationId, hmac)); YousScribeHMACHttpClientDecorator httpClient = (YousScribeHMACHttpClientDecorator)((DisposableClient)client.clientFactory()).Client; // Act httpClient.GetAsync(TestHelpers.BaseUrl); // Assert Assert.NotNull(httpClient.BaseClient.DefaultRequestHeaders.Authorization); Assert.NotNull(httpClient.BaseClient.DefaultRequestHeaders.Date); Assert.NotNull(httpClient.BaseClient.DefaultRequestHeaders.GetValues(ApiUrls.HMACAuthenticateRandomKeyHeader)); } }