public void When_Given_Admin_And_Dev_Return_Admin_ClaimsPrincipal()
        {
            // Assign
            #region Options
            IOptions <LdapConfig> ldapOptions = Options.Create(new LdapConfig());
            #endregion
            #region Service
            var authService = new LdapAuthenticationService(ldapOptions);
            #endregion
            var authenticationProvider = new DevelopmentAuthenticationProvider(authService);
            var user = new User
            {
                DisplayName = "Calle Carlsson",
                Username    = "******",
                Email       = "*****@*****.**",
                IsAdmin     = true,
                IsDeveloper = true,
            };

            // Act
            var claimsPrincipal = authenticationProvider.GetClaimsPrincipal(user);

            // Assert
            Assert.True(claimsPrincipal.HasClaim(c => c.Type == ClaimTypes.Role && c.Value == "Admin"));
        }
Beispiel #2
0
        public void When_Given_User_Return_ClaimsPrincipal()
        {
            // Assign
            #region Options
            IOptions <LdapConfig> ldapOptions = Options.Create(new LdapConfig());
            #endregion
            #region Service
            var authService = new LdapAuthenticationService(ldapOptions);
            #endregion
            var authenticationProvider = new DevelopmentAuthenticationProvider(authService);
            var user = new User
            {
                DisplayName = "Calle Carlsson",
                Username    = "******",
                IsDeveloper = true,
            };

            // Act
            var claimsPrincipal = authenticationProvider.GetClaimsPrincipal(user);

            // Assert
            Assert.True(claimsPrincipal.Identity.IsAuthenticated);
            Assert.True(claimsPrincipal.Identity.AuthenticationType == authService.GetType().Name);
            Assert.True(claimsPrincipal.HasClaim(c => c.Type == "displayName" && c.Value == user.DisplayName));
            Assert.True(claimsPrincipal.HasClaim(c => c.Type == "username" && c.Value == user.Username));
            Assert.True(claimsPrincipal.HasClaim(c => c.Type == ClaimTypes.Role && c.Value == "Admin"));
        }
Beispiel #3
0
        public void When_Given_Non_Developer_Ignore_Role_Return_ClaimsPrincipal()
        {
            // Assign
            #region Options
            IOptions <LdapConfig> ldapOptions = Options.Create(new LdapConfig());
            #endregion
            #region Service
            var authService = new LdapAuthenticationService(ldapOptions);
            #endregion
            var authenticationProvider = new DevelopmentAuthenticationProvider(authService);
            var user = new User
            {
                DisplayName = "Calle Carlsson",
                Username    = "******",
            };

            // Act
            var claimsPrincipal = authenticationProvider.GetClaimsPrincipal(user);

            // Assert
            Assert.False(claimsPrincipal.HasClaim(c => c.Type == ClaimTypes.Role));
        }