コード例 #1
0
        public void OnRedirect_RedirectContainsError_ErrorLogged()
        {
            OpenIDConnectService oidc         = new OpenIDConnectService();
            IOidcProvider        oidcProvider = A.Fake <IOidcProvider>();
            string errorMsg;

            A.CallTo(() => oidcProvider.ParametersContainError(A <Dictionary <string, string> > .Ignored, out errorMsg))
            .Returns(true)
            .AssignsOutAndRefParameters("This is a simulated fail");
            oidc.OidcProvider = oidcProvider;
            IRedirectServerListener   serverListener            = A.Fake <IRedirectServerListener>();
            RedirectReceivedEventArgs redirectReceivedEventArgs = A.Fake <RedirectReceivedEventArgs>();

            oidc.ServerListener = serverListener;

            LogAssert.Expect(LogType.Error, new Regex(@"\w*This is a simulated fail\w*"));

            oidc.OpenLoginPage();

            serverListener.RedirectReceived += Raise.With(redirectReceivedEventArgs);

            oidc.Update();

            A.CallTo(() => oidcProvider.ParametersContainError(A <Dictionary <string, string> > .Ignored, out errorMsg))
            .MustHaveHappenedOnceExactly();
            Assert.IsTrue(string.IsNullOrEmpty(oidc.AccessToken));
        }
コード例 #2
0
        public void OnRedirect_AuthFlow_RetrievesAccessToken()
        {
            OpenIDConnectService oidc         = new OpenIDConnectService();
            IOidcProvider        oidcProvider = A.Fake <IOidcProvider>();

            A.CallTo(() => oidcProvider.GetAuthorizationCode(A <Dictionary <string, string> > .Ignored)).Returns("myCode");
            A.CallTo(() => oidcProvider.GetAccessTokenFromCodeAsync(A <string> .Ignored, A <string> .Ignored))
            .Returns(Task.FromResult("myAccessToken"));
            A.CallTo(() => oidcProvider.AuthorizationFlow).Returns(AuthorizationFlow.AUTHORIZATION_CODE);
            oidc.OidcProvider = oidcProvider;
            IRedirectServerListener serverListener = A.Fake <IRedirectServerListener>();

            oidc.ServerListener = serverListener;

            oidc.OpenLoginPage();

            RedirectReceivedEventArgs redirectReceivedEventArgs = A.Fake <RedirectReceivedEventArgs>();

            serverListener.RedirectReceived += Raise.With(redirectReceivedEventArgs);

            oidc.Update();

            A.CallTo(() => oidcProvider.GetAccessTokenFromCodeAsync("myCode", A <string> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.AreEqual("myAccessToken", oidc.AccessToken);
        }
コード例 #3
0
        public void OnRedirect_AuthFlow_ExtractsCode()
        {
            OpenIDConnectService oidc         = new OpenIDConnectService();
            IOidcProvider        oidcProvider = A.Fake <IOidcProvider>();

            A.CallTo(() => oidcProvider.AuthorizationFlow).Returns(AuthorizationFlow.AUTHORIZATION_CODE);
            oidc.OidcProvider = oidcProvider;
            IRedirectServerListener serverListener = A.Fake <IRedirectServerListener>();

            oidc.ServerListener = serverListener;

            oidc.OpenLoginPage();

            RedirectReceivedEventArgs redirectReceivedEventArgs = A.Fake <RedirectReceivedEventArgs>();

            serverListener.RedirectReceived += Raise.With(redirectReceivedEventArgs);

            oidc.Update();

            A.CallTo(() => oidcProvider.GetAuthorizationCode(A <Dictionary <string, string> > .Ignored)).MustHaveHappenedOnceExactly();
        }
コード例 #4
0
        public void IsLoggedIn_SuccessfulLogin_ReturnsTrue()
        {
            OpenIDConnectService oidc         = new OpenIDConnectService();
            IOidcProvider        oidcProvider = A.Fake <IOidcProvider>();

            A.CallTo(() => oidcProvider.GetAccessToken(A <Dictionary <string, string> > .Ignored)).Returns("myAccessToken");
            A.CallTo(() => oidcProvider.AuthorizationFlow).Returns(AuthorizationFlow.IMPLICIT);
            oidc.OidcProvider = oidcProvider;
            IRedirectServerListener serverListener = A.Fake <IRedirectServerListener>();

            oidc.ServerListener = serverListener;

            oidc.OpenLoginPage();

            RedirectReceivedEventArgs redirectReceivedEventArgs = A.Fake <RedirectReceivedEventArgs>();

            serverListener.RedirectReceived += Raise.With(redirectReceivedEventArgs);

            oidc.Update();

            Assert.IsTrue(oidc.IsLoggedIn);
        }
コード例 #5
0
        public void OnRedirect_ImplicitFlow_AccessTokenRetrieved()
        {
            OpenIDConnectService oidc         = new OpenIDConnectService();
            IOidcProvider        oidcProvider = A.Fake <IOidcProvider>();

            A.CallTo(() => oidcProvider.GetAccessToken(A <Dictionary <string, string> > .Ignored)).Returns("myAccessToken");
            A.CallTo(() => oidcProvider.AuthorizationFlow).Returns(AuthorizationFlow.IMPLICIT);
            oidc.OidcProvider = oidcProvider;
            IRedirectServerListener serverListener = A.Fake <IRedirectServerListener>();

            oidc.ServerListener = serverListener;

            oidc.OpenLoginPage();

            RedirectReceivedEventArgs redirectReceivedEventArgs = A.Fake <RedirectReceivedEventArgs>();

            serverListener.RedirectReceived += Raise.With(redirectReceivedEventArgs);

            oidc.Update();

            Assert.AreEqual("myAccessToken", oidc.AccessToken);
        }
コード例 #6
0
        public void OnRedirect_Success_EventRaised()
        {
            OpenIDConnectService oidc         = new OpenIDConnectService();
            IOidcProvider        oidcProvider = A.Fake <IOidcProvider>();

            oidc.OidcProvider = oidcProvider;
            IRedirectServerListener serverListener = A.Fake <IRedirectServerListener>();

            oidc.ServerListener = serverListener;
            RedirectReceivedEventArgs redirectReceivedEventArgs = A.Fake <RedirectReceivedEventArgs>();

            int eventCalls = 0;

            oidc.LoginCompleted += delegate
            {
                eventCalls++;
            };
            oidc.OpenLoginPage();

            serverListener.RedirectReceived += Raise.With(redirectReceivedEventArgs);
            oidc.Update();

            Assert.AreEqual(1, eventCalls);
        }