public void AddAuthenticateHeaderIfNeeded_Basic_NoAuthorization()
        {
            HeyLogger       logger   = new HeyLogger();
            HeyHttpRequest  request  = new HeyHttpRequest(logger);
            HeyHttpResponse response = new HeyHttpResponse(logger);

            request.ParsePath("/?basic=1");

            HeyHttpAuthentication.AddAuthenticateHeaderIfNeeded(request, response);

            Assert.AreEqual("401 Unauthorized", response.Status);
            Assert.IsTrue(response.Headers.Contains("WWW-Authenticate: Basic realm=\"Secure Area\""));
        }
        public void AddAuthenticateHeaderIfNeeded_Basic_InvalidAuthorization()
        {
            HeyLogger       logger   = new HeyLogger();
            HeyHttpRequest  request  = new HeyHttpRequest(logger);
            HeyHttpResponse response = new HeyHttpResponse(logger);

            request.ParsePath("/?basic=1&user=foo&password=bar");
            request.Authorization = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";

            HeyHttpAuthentication.AddAuthenticateHeaderIfNeeded(request, response);

            Assert.AreEqual("401 Unauthorized", response.Status);
            Assert.IsTrue(response.Headers.Contains("WWW-Authenticate: Basic realm=\"Secure Area\""));
        }
        public void AddAuthenticateHeaderIfNeeded_Basic_ValidAuthorization()
        {
            HeyLogger       logger   = new HeyLogger();
            HeyHttpRequest  request  = new HeyHttpRequest(logger);
            HeyHttpResponse response = new HeyHttpResponse(logger);

            request.ParsePath("/?basic=1&user=foo&password=bar");
            request.Authorization = "Basic Zm9vOmJhcg==";

            HeyHttpAuthentication.AddAuthenticateHeaderIfNeeded(request, response);

            Assert.IsTrue(String.IsNullOrEmpty(response.Status));
            Assert.AreEqual(0, response.Headers.Count);
        }