Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 6
0
 public void Initialize()
 {
     Bank.ClearInstance();
     _bank                    = Bank.Instance;
     _mockAccessor            = new MockAccessor();
     _mockNotificationSystem  = new MockNotificationSystem();
     _bank.NotificationSystem = _mockNotificationSystem;
 }
Esempio n. 7
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"));
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        public void Setup()
        {
            testLog = new MockAccessor();

            var services        = new ServiceCollection();
            var serviceProvider = services
                                  .AddLogging(
                builder => builder.AddTestLogging(testLog))
                                  .AddSingleton <MockTestSubject>()
                                  .AddSingleton(testLog)
                                  .AddSingleton <ITestLogAccessor>(testLog)
                                  .BuildServiceProvider();

            logger = serviceProvider
                     .GetRequiredService <MockTestSubject>()
                     .Logger;
        }
Esempio n. 12
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);