示例#1
0
        public void TestResponse()
        {
            DigestAuthentication digest = new DigestAuthentication(OnTestAuth, null);
            string response = digest.CreateResponse("blaj", false);
            Assert.Equal("Digest ", response.Substring(0, 7));

            NameValueCollection parts = Decode(response);
            Assert.NotNull(parts["realm"]);
            Assert.NotNull(parts["qop"]);
            Assert.NotNull(parts["nonce"]);
            Assert.NotNull(parts["opaque"]);
            Assert.Equal("blaj", parts["realm"]);
        }
示例#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);
        }