public void AuthenticationHeaderProvider_GetAuthToken()
        {
            // Invalid input
            string user     = "******";
            string password = "******";

            using (new AssertIgnoreScope())
            {
                Exceptions.Expect <ArgumentOutOfRangeException>(() => AuthenticationHeaderProvider.GetBasicAuthToken(user, password.ToSecureString()));
            }

            // ASCII
            user     = "******";
            password = "******";
            AssertAreEqualUserNameAndPassword(user, password, AuthenticationHeaderProvider.GetBasicAuthToken(user, password.ToSecureString()));

            // UTF-8
            user     = "******"; // hello in Russian
            password = "******";   // hello in Chinese
            AssertAreEqualUserNameAndPassword(user, password, AuthenticationHeaderProvider.GetBasicAuthToken(user, password.ToSecureString()));

            // Digits and signs (including ':' in the password)
            user     = "******";
            password = "******";
            AssertAreEqualUserNameAndPassword(user, password, AuthenticationHeaderProvider.GetBasicAuthToken(user, password.ToSecureString()));
        }
コード例 #2
0
            private bool IsBasicAuthAuthorized(string headerValue)
            {
                const string BasicAuth = "Basic";

                string[] keyValue = headerValue.Split((char[])null /*whitespace*/, StringSplitOptions.RemoveEmptyEntries);
                if (keyValue.Length != 2 || keyValue[0] != BasicAuth)
                {
                    return(false);
                }

                return(this.BasicAuthUsers
                       .Select(kv => AuthenticationHeaderProvider.GetBasicAuthToken(kv.Key, kv.Value.ConvertToSecureString()))
                       .Any(token => token == keyValue[1]));
            }