Exemplo n.º 1
0
        public void WhenSigningIn_ThenRedirectsToOpenProvidedAction()
        {
            string providerUrl = @"http://ssomeauthcontroller.com";

            TestableAuthController authController =
                GetTestableAuthController(OpenIdRelyingPartyBuilder.DefaultParty().Object);

            ActionResult response = authController.SignInWithProvider(providerUrl);

            // For the test we ensure that controller responsds with whatever the OpenIdRelyingParty facade returns.
            Assert.IsType(typeof(RedirectResult), response);
        }
Exemplo n.º 2
0
        public void WhenSigningInWithoutSpecifyingProviderUrl_ThenRedirectsToOpenProvidedAction()
        {
            var relyingPartyMock = new Mock <IOpenIdRelyingParty>();

            relyingPartyMock
            .Setup(x => x.RedirectToProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <FetchRequest>()))
            .Throws(new Exception("Relying party expects a url, a null or empty string will raise an exception."));

            TestableAuthController authController = GetTestableAuthController(relyingPartyMock.Object);

            var result = authController.SignInWithProvider(null) as RedirectToRouteResult;

            Assert.NotNull(result);
            Assert.Equal("Index", result.RouteValues["action"]);
        }
        public void WhenProviderCreateRequestThrows_ThenRedirectsToSignInActionWithAMessage()
        {
            var relyingParty = new Mock <IOpenIdRelyingParty>();

            relyingParty.Setup(
                r => r.RedirectToProvider(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <FetchRequest>()))
            .Throws(new Exception("Some Provider Exception"));

            TestableAuthController authController = GetTestableAuthController(relyingParty.Object);

            ActionResult result = authController.SignInWithProvider(@"http://providerUrl");

            Assert.IsType(typeof(RedirectToRouteResult), result);
            Assert.Equal("SignIn", ((RedirectToRouteResult)result).RouteValues["action"]);
            Assert.NotNull(authController.TempData["Message"]);
        }
Exemplo n.º 4
0
        public void WhenSigningIn_ThenSetsReturnUrlToCorrectSchema()
        {
            string providerUrl = @"http://ssomeauthcontroller.com";

            var relyingPartyMock = new Mock <IOpenIdRelyingParty>();

            TestableAuthController authController = GetTestableAuthController(relyingPartyMock.Object);

            Mock <HttpRequestBase> requestMock = Mock.Get(authController.Request);

            requestMock.SetupGet(r => r.Url)
            .Returns(new Uri(@"https://nothingmattersbutschema.com", UriKind.Absolute));

            ActionResult response = authController.SignInWithProvider(providerUrl);

            relyingPartyMock.Verify(x => x.RedirectToProvider(
                                        It.IsAny <string>(),
                                        It.Is <string>(s => s.StartsWith("https:")),
                                        It.IsAny <FetchRequest>()), "Incorrect schema applied for return URL.");
        }