예제 #1
0
        public void TestAuth()
        {
            DigestAuthentication auth = new DigestAuthentication(OnTestAuth, null);
            object res = auth.Authenticate(
                @"Digest username=""Mufasa"",
                      realm=""*****@*****.**"",
                      nonce=""dcd98b7102dd2f0e8b11d0f600bfb0c093"",
                      uri=""/dir/index.html"",
                      qop=auth,
                      nc=00000001,
                      cnonce=""0a4f113b"",
                      response=""6629fae49393a05397450978507c4ef1"",
                      opaque=""5ccc069c403ebaf9f0171e9517f40e41"" ", "*****@*****.**", "GET", false);

            Assert.NotNull(res);
            Assert.Equal("testobj", (string)res);
        }
예제 #2
0
        public void TestAuth2()
        {
            string realm = "myrealm";
            string userName = "******";
            string password = "******";
            DigestAuthentication auth = new DigestAuthentication(OnAuth2, null);
            string server = auth.CreateResponse(realm);

            NameValueCollection args = Decode(server);
            string cnonce = "a773bd8";

            string response = CreateResponse(userName, realm, password, args["nonce"], cnonce, args["qop"]);

            string client = string.Format(
                "Digest username=\"{6}\", realm=\"{5}\", nonce={0}, uri=\"{1}\", qop=auth, nc=00000001, cnonce=\"{2}\", response=\"{3}\", opaque=\"{4}\"",
                args["nonce"],
                "/membersonly/",
                cnonce,
                response,
                args["opaque"],
                realm,
                userName);

            object obj = auth.Authenticate(client, realm, "GET");
            Assert.NotNull(obj);
            Assert.Equal("hello", (string)obj);
        }