Esempio n. 1
0
        public void TestBrokenFacebook()
        {
            var headers = AuthHeaderUtilities.ParseAuthenticationHeader("OAuth \"Facebook Platform\" \"invalid_token\" \r\n    \"Error validating access token: Session has expired \r\n    at unix time 1334415600.The current unix time is 1334822619.\"").ToList();

            Assert.Equal(1, headers.Count);

            var header = headers[0];

            Assert.Equal("OAuth", header.Name);
            Assert.Equal("\"Facebook Platform\" \"invalid_token\" \r\n    \"Error validating access token: Session has expired \r\n    at unix time 1334415600.The current unix time is 1334822619.\"", header.RawValue);
            Assert.Collection(
                header.Values,
                valueItem =>
            {
                Assert.Equal(string.Empty, valueItem.Key);
                Assert.Collection(
                    valueItem,
                    value => Assert.Equal("Facebook Platform", value),
                    value => Assert.Equal("invalid_token", value),
                    value => Assert.Equal("Error validating access token: Session has expired \r\n    at unix time 1334415600.The current unix time is 1334822619.", value));
            });
            Assert.Collection(
                header.RawValues,
                valueItem =>
            {
                Assert.Equal(string.Empty, valueItem.Key);
                Assert.Collection(
                    valueItem,
                    value => Assert.Equal("\"Facebook Platform\"", value),
                    value => Assert.Equal("\"invalid_token\"", value),
                    value => Assert.Equal("\"Error validating access token: Session has expired \r\n    at unix time 1334415600.The current unix time is 1334822619.\"", value));
            });
        }
Esempio n. 2
0
        public void TestSimpleBasicNewParam2()
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader("Basic bar=\"xyz\", realm=\"foo\"").ToList();

            Assert.Equal(1, items.Count);

            var item = items[0];

            Assert.Equal("Basic", item.Name);
            Assert.Equal("bar=\"xyz\", realm=\"foo\"", item.RawValue);
            Assert.Collection(
                item.Values,
                param =>
            {
                Assert.Equal("bar", param.Key);
                Assert.Equal("xyz", param.Single());
            },
                param =>
            {
                Assert.Equal("realm", param.Key);
                Assert.Equal("foo", param.Single());
            });
            Assert.Collection(
                item.RawValues,
                param =>
            {
                Assert.Equal("bar", param.Key);
                Assert.Equal("\"xyz\"", param.Single());
            },
                param =>
            {
                Assert.Equal("realm", param.Key);
                Assert.Equal("\"foo\"", param.Single());
            });
        }
Esempio n. 3
0
        public void TestMultiBasicQuotedStrings()
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader("Newauth realm=\"apps\", type=1, title=\"Login to \\\"apps\\\"\", Basic realm = \"simple\"").ToList();

            Assert.Collection(
                items,
                item =>
            {
                Assert.Equal("Newauth", item.Name);
                Assert.Equal("realm=\"apps\", type=1, title=\"Login to \\\"apps\\\"\"", item.RawValue);
                Assert.Collection(
                    item.Values,
                    value =>
                {
                    Assert.Equal("realm", value.Key);
                    Assert.Equal("apps", value.Single());
                },
                    value =>
                {
                    Assert.Equal("type", value.Key);
                    Assert.Equal("1", value.Single());
                },
                    value =>
                {
                    Assert.Equal("title", value.Key);
                    Assert.Equal("Login to \"apps\"", value.Single());
                });
                Assert.Collection(
                    item.RawValues,
                    value =>
                {
                    Assert.Equal("realm", value.Key);
                    Assert.Equal("\"apps\"", value.Single());
                },
                    value =>
                {
                    Assert.Equal("type", value.Key);
                    Assert.Equal("1", value.Single());
                },
                    value =>
                {
                    Assert.Equal("title", value.Key);
                    Assert.Equal("\"Login to \\\"apps\\\"\"", value.Single());
                });
            },
                item =>
            {
                Assert.Equal("Basic", item.Name);
                Assert.Equal("realm = \"simple\"", item.RawValue);
                Assert.Equal("simple", item.Values["realm"].Single());
                Assert.Equal("\"simple\"", item.RawValues["realm"].Single());
            });
        }
Esempio n. 4
0
        public void TestMethodAndRealm(string headerValue, string method, string rawValue, string realmValue, string rawRealmValue)
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader(headerValue).ToList();

            Assert.Equal(1, items.Count);

            var item = items[0];

            Assert.Equal(method, item.Name);
            Assert.Equal(rawValue, item.RawValue);
            Assert.Equal(realmValue, item.Values["realm"].Single());
            Assert.Equal(rawRealmValue, item.RawValues["realm"].Single());
        }
Esempio n. 5
0
        public void TestSimpleBasicNoRealm()
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader("Basic").ToList();

            Assert.Equal(1, items.Count);

            var item = items[0];

            Assert.Equal("Basic", item.Name);
            Assert.Equal(string.Empty, item.RawValue);
            Assert.Null(item.Values["realm"].SingleOrDefault());
            Assert.Null(item.RawValues["realm"].SingleOrDefault());
        }
Esempio n. 6
0
        public void TestMissingQuote()
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader("Basic realm=\"basic").ToList();

            Assert.Equal(1, items.Count);

            var item = items[0];

            Assert.Equal("Basic", item.Name);
            Assert.Equal("realm=\"basic", item.RawValue);
            Assert.Equal("basic", item.Values["realm"].Single());
            Assert.Equal("\"basic", item.RawValues["realm"].Single());
        }
Esempio n. 7
0
        public void TestMultiBasicEmpty()
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader(",Basic realm=\"basic\"").ToList();

            Assert.Collection(
                items,
                item =>
            {
                Assert.Equal("Basic", item.Name);
                Assert.Equal("realm=\"basic\"", item.RawValue);
                Assert.Equal("basic", item.Values["realm"].Single());
                Assert.Equal("\"basic\"", item.RawValues["realm"].Single());
            });
        }
Esempio n. 8
0
        public void TestSimpleBasicWhiteSpaceRealm()
        {
            var items = AuthHeaderUtilities.ParseAuthenticationHeader("Basic realm = \"foo\"").ToList();

            Assert.Equal(1, items.Count);

            var item = items[0];

            Assert.Equal("Basic", item.Name);
            Assert.Equal("realm = \"foo\"", item.RawValue);
            Assert.Collection(
                item.Values["realm"],
                value => Assert.Equal("foo", value));
            Assert.Collection(
                item.RawValues["realm"],
                value => Assert.Equal("\"foo\"", value));
        }