Example #1
0
        public void IsInRole_Is_False_When_User_Is_Not_In_Role()
        {
            var acc = MockAccessor.With("tester",
                                        new Claim(ClaimTypes.Role, Role.Admin));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.False(ctx.IsInRole(Role.Fed));
        }
Example #2
0
        public void IsInstitutional_Is_False_When_Issues_Do_Not_Match()
        {
            var acc = MockAccessor.With("tester",
                                        new Claim(JwtRegisteredClaimNames.Iss, "urn:leaf:iss:test.tld"));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions("urn:leaf:iss:failTest.tld"));

            Assert.False(ctx.IsInstitutional);
        }
Example #3
0
        public void Roles_Contains_All_Role_Claims()
        {
            var acc = MockAccessor.With("user",
                                        new Claim(ClaimTypes.Role, Role.Admin));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.Contains(ctx.Roles, r => r.Equals(Role.Admin));
        }
Example #4
0
        public void UUID_Does_Not_Return_Null()
        {
            var acc = MockAccessor.With("tester",
                                        new Claim(JwtRegisteredClaimNames.Iss, "urn:leaf:iss:test.tld"));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.Equal("tester@urn:leaf:iss:test.tld", ctx.UUID);
        }
Example #5
0
        public void IsQuarantined_Is_True_When_User_Is_Not_In_Fed_Role()
        {
            var acc = MockAccessor.With("tester",
                                        new Claim(ClaimTypes.Role, Role.Admin));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.True(ctx.IsQuarantined);
        }
Example #6
0
        public void Groups_Contains_All_Group_Claims()
        {
            var acc = MockAccessor.With("user@localhost",
                                        new Claim(Group.Key, "test-group-1"),
                                        new Claim(JwtRegisteredClaimNames.Iss, "urn:leaf:iss:test.tld"));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.Contains(ctx.Groups, g => g.Equals("test-group-1@localhost@urn:leaf:iss:test.tld"));
        }
Example #7
0
        public void SessionNonce_Returns_A_Guid_If_Session_Exists()
        {
            var sess = Guid.NewGuid();
            var acc  = MockAccessor.With("tester",
                                         new Claim(Nonce.Access, sess.ToString()));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.Equal(sess, ctx.SessionNonce);
        }
Example #8
0
        public void IdNonce_Returns_A_Guid()
        {
            var id  = Guid.NewGuid();
            var acc = MockAccessor.With("tester",
                                        new Claim(Nonce.Id, id.ToString()));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.Equal(id, ctx.IdNonce);
        }
Example #9
0
        public void IsAdmin_Is_False_When_User_Is_Not_In_Admin_Role()
        {
            var acc = MockAccessor.With("tester",
                                        new Claim(ClaimTypes.Role, Role.Fed),
                                        new Claim(JwtRegisteredClaimNames.Iss, "urn:leaf:iss:test.tld"));
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions("urn:leaf:iss:test.tld"));

            Assert.False(ctx.IsAdmin);
        }
Example #10
0
        public void SessionNonce_Returns_Default_If_Session_Does_Not_Exist()
        {
            var acc = MockAccessor.With("tester");
            var ctx = new HttpUserContext(acc, GetJwtVerifyingOptions());

            Assert.Equal(default, ctx.SessionNonce);