Esempio n. 1
0
        public void should_login_token()
        {
            var secureSession = new SecureSession<Token>(null, new MemoryTokenStore<Token>());
            var token = new Token(Guid.Empty, null, false);

            secureSession.Login(token);

            secureSession.IsLoggedIn().ShouldBeTrue();
            secureSession.GetCurrentToken().ShouldEqual(token);
        }
Esempio n. 2
0
        public void should_not_log_in_an_invalid_user()
        {
            var authenticationService = Substitute.For<IAuthenticationService<Token>>();
            var secureSession = new SecureSession<Token>(authenticationService, new MemoryTokenStore<Token>());

            authenticationService.Authenticate(Arg.Any<string>(), Arg.Any<string>()).
                                  ReturnsForAnyArgs(x => { throw new AuthenticationService.AccessDeniedException(); });

            Assert.Throws<AuthenticationService.AccessDeniedException>(() => secureSession.Login("username", "password"));

            secureSession.IsLoggedIn().ShouldBeFalse();
            secureSession.GetCurrentToken().ShouldBeNull();
        }
Esempio n. 3
0
        public void should_logout_user()
        {
            var authenticationService = Substitute.For<IAuthenticationService<Token>>();
            var secureSession = new SecureSession<Token>(authenticationService, new MemoryTokenStore<Token>());

            authenticationService.Authenticate(Arg.Any<string>(), Arg.Any<string>()).
                                  ReturnsForAnyArgs(new Token(Guid.Empty, null, false));

            secureSession.Login("username", "password");
            secureSession.Logout();

            secureSession.IsLoggedIn().ShouldBeFalse();
            secureSession.GetCurrentToken().ShouldBeNull();
        }
Esempio n. 4
0
        public void should_login_valid_user()
        {
            var authenticationService = Substitute.For<IAuthenticationService<Token>>();
            var secureSession = new SecureSession<Token>(authenticationService, new MemoryTokenStore<Token>());
            var userId = Guid.NewGuid();

            authenticationService.Authenticate(Arg.Any<string>(), Arg.Any<string>()).
                                  ReturnsForAnyArgs(new Token(userId, "username", true));

            secureSession.Login("username", "password");

            secureSession.IsLoggedIn().ShouldBeTrue();
            var token = secureSession.GetCurrentToken();
            token.ShouldNotBeNull();
            token.UserId.ShouldEqual(userId);
            token.Username.ToString().ShouldEqual("username");
            token.IsAdministrator.ShouldBeTrue();
        }