public void SetUp()
 {
     registryAuthenticator =
         RegistryAuthenticator.FromAuthenticationMethod(
             new AuthenticationHeaderValue("Bearer", "realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\""),
             registryEndpointRequestProperties,
             new[] { new ProductInfoHeaderValue(new ProductHeaderValue("userAgent")) });
 }
        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"));
        }
 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);
     }
 }
 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"));
     }
 }
        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")) }));
        }