コード例 #1
0
 public void SetUp()
 {
     registryAuthenticator =
         RegistryAuthenticator.FromAuthenticationMethod(
             new AuthenticationHeaderValue("Bearer", "realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\""),
             registryEndpointRequestProperties,
             new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) });
 }
コード例 #2
0
        public void TestFromAuthenticationMethod_noService()
        {
            RegistryAuthenticator registryAuthenticator =
                RegistryAuthenticator.FromAuthenticationMethod(
                    new AuthenticationHeaderValue("Bearer", "realm=\"https://somerealm\""),
                    registryEndpointRequestProperties,
                    new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) });

            Assert.AreEqual(
                new Uri("https://somerealm?service=someserver&scope=repository:someimage:scope"),
                registryAuthenticator.GetAuthenticationUrl(null, "scope"));
        }
コード例 #3
0
 public void TestFromAuthenticationMethod_noRealm()
 {
     try
     {
         RegistryAuthenticator.FromAuthenticationMethod(
             new AuthenticationHeaderValue("Bearer", "scope=\"somescope\""),
             registryEndpointRequestProperties,
             new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) });
         Assert.Fail("Authentication method without 'realm' should fail");
     }
     catch (RegistryAuthenticationFailedException ex)
     {
         Assert.AreEqual(
             "Failed to authenticate with registry someserver/someimage because: 'realm' was not found in the 'WWW-Authenticate' header, tried to parse: scope=\"somescope\"",
             ex.Message);
     }
 }
コード例 #4
0
 public async Task TestUserAgentAsync()
 {
     using (TestWebServer server = new TestWebServer(false))
     {
         try
         {
             RegistryAuthenticator authenticator =
                 RegistryAuthenticator.FromAuthenticationMethod(
                     new AuthenticationHeaderValue("Bearer", "realm=\"" + server.GetAddressAndPort() + "\""),
                     registryEndpointRequestProperties,
                     new[] { new ProductInfoHeaderValue(new ProductHeaderValue("Competent-Agent")) });
             await authenticator.AuthenticatePushAsync(null).ConfigureAwait(false);
         }
         catch (RegistryAuthenticationFailedException)
         {
             // Doesn't matter if auth fails. We only examine what we sent.
         }
         Assert.That(server.GetInputRead(), Does.Contain("User-Agent: Competent-Agent"));
     }
 }
コード例 #5
0
        public void TestFromAuthenticationMethod_basic()
        {
            Assert.IsNull(
                RegistryAuthenticator.FromAuthenticationMethod(
                    new AuthenticationHeaderValue("Basic", "realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\""),
                    registryEndpointRequestProperties,
                    new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) }));

            Assert.IsNull(
                RegistryAuthenticator.FromAuthenticationMethod(
                    new AuthenticationHeaderValue("BASIC", "realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\""),
                    registryEndpointRequestProperties,
                    new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) }));

            Assert.IsNull(
                RegistryAuthenticator.FromAuthenticationMethod(
                    new AuthenticationHeaderValue("bASIC", "realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\""),
                    registryEndpointRequestProperties,
                    new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) }));
        }