Пример #1
0
        public void DoA401ClearsHeaders()
        {
            //Arrange
            var response = new Mock <HttpResponseBase>();
            var context  = new Mock <IServicesContext>();

            context.Setup(x => x.DoA401).Returns(true);
            context.Setup(x => x.BaseContext.Response).Returns(response.Object);

            //Act
            ServicesModule.CheckForReal401(context.Object);

            //Assert
            response.Verify(x => x.ClearHeaders());
        }
Пример #2
0
        public void SupportsDigestAddsDigestHeader()
        {
            //Arrange
            var response = new Mock <HttpResponseBase>();
            var context  = new Mock <IServicesContext>();

            context.Setup(x => x.DoA401).Returns(true);
            context.Setup(x => x.SupportDigestAuth).Returns(true);
            context.Setup(x => x.BaseContext.Response).Returns(response.Object);

            //Act
            ServicesModule.CheckForReal401(context.Object);

            //Assert
            response.Verify(x => x.AppendHeader("WWW-Authenticate", It.IsRegex("^Digest.*", RegexOptions.IgnoreCase)));
        }
Пример #3
0
        public void DoA401CausesStatusCode401()
        {
            //Arrange
            var response = new Mock <HttpResponseBase>();

            response.SetupProperty(x => x.StatusCode);
            var context = new Mock <IServicesContext>();

            context.Setup(x => x.DoA401).Returns(true);
            context.Setup(x => x.BaseContext.Response).Returns(response.Object);

            //Act
            ServicesModule.CheckForReal401(context.Object);

            //Assert
            Assert.AreEqual(401, response.Object.StatusCode);
        }
Пример #4
0
        public void NoDoA401DoesNothing()
        {
            //Arrange
            var response = new Mock <HttpResponseBase>();
            var context  = new Mock <IServicesContext>();

            context.Setup(x => x.DoA401).Returns(false);
            context.Setup(x => x.BaseContext.Response).Returns(response.Object);

            //Act
            ServicesModule.CheckForReal401(context.Object);

            //Assert
            response.Verify(x => x.StatusCode, Times.Never());
            response.Verify(x => x.ClearContent(), Times.Never());
            response.Verify(x => x.AppendHeader(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
            response.Verify(x => x.AddHeader(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
            response.Verify(x => x.Headers, Times.Never());
        }
Пример #5
0
        public void IsStaleSetsStaleNonceIndicator(bool stale)
        {
            //Arrange
            var response = new Mock <HttpResponseBase>();
            var context  = new Mock <IServicesContext>();

            context.Setup(x => x.DoA401).Returns(true);
            context.Setup(x => x.IsStale).Returns(stale);
            context.Setup(x => x.SupportBasicAuth).Returns(false); //avoid basic auth header
            context.Setup(x => x.SupportDigestAuth).Returns(true);
            context.Setup(x => x.BaseContext.Response).Returns(response.Object);

            //Act
            ServicesModule.CheckForReal401(context.Object);

            //Assert
            var regex = string.Format("^Digest.*, stale={0}.*", stale);

            response.Verify(x => x.AppendHeader("WWW-Authenticate", It.IsRegex(regex, RegexOptions.IgnoreCase)));
        }