Exemple #1
0
 public void SetNullAlgorithmName()
 {
     using (HMAC hmac = new TestHMAC())
     {
         Assert.Throws <ArgumentNullException>(() => hmac.HashName = null);
         Assert.Null(hmac.HashName);
     }
 }
Exemple #2
0
        public void SetNullAlgorithmName()
        {
            using (HMAC hmac = new TestHMAC())
            {
                // Assert.NoThrows is implicit
                hmac.HashName = null;

                Assert.Null(hmac.HashName);
            }
        }
Exemple #3
0
        public void SetNullAlgorithmName()
        {
            using (HMAC hmac = new TestHMAC())
            {
                // Assert.NoThrows is implicit
                hmac.HashName = null;

                Assert.Null(hmac.HashName);
            }
        }
Exemple #4
0
        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>()));
            }
        }
Exemple #5
0
        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>()));
            }
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        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);
            }
        }
Exemple #8
0
        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);
            }
        }
Exemple #9
0
        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);
            }
        }
Exemple #10
0
        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);
            }
        }
Exemple #11
0
        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));
            }
        }