Пример #1
0
        public void TestGetAuthenticationHeaderValue()
        {
            var username1  = "username1";
            var password1  = "password1";
            var credParam1 = Convert.ToBase64String(
                Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username1, password1)));

            var auth       = AuthenticatorFactory.CreateBasicAuthenticator(username1, password1) as BasicAuthenticator;
            var authHeader = auth.AuthorizationHeaderValue;

            Assert.IsNotNull(authHeader);
            Assert.AreEqual(credParam1, authHeader.Split(' ')[1]);

            var username2  = "username2";
            var password2  = "password2";
            var credParam2 = Convert.ToBase64String(
                Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username2, password2)));

            var userinfo = username2 + ":" + password2;
            var uri      = new Uri("http://" + userinfo + "@couchbase.com");

            auth       = (BasicAuthenticator)AuthenticatorFactory.CreateFromUri(uri);
            authHeader = auth.AuthorizationHeaderValue;
            Assert.IsNotNull(authHeader);
            Assert.AreEqual(credParam2, authHeader.Split(' ')[1]);

            uri  = new Uri("http://www.couchbase.com");
            auth = (BasicAuthenticator)AuthenticatorFactory.CreateFromUri(uri);
            Assert.IsNull(auth);

            var auth2 = AuthenticatorFactory.CreateFacebookAuthenticator("1234") as ICustomHeadersAuthorizer;

            Assert.IsNull(auth2);
        }