Beispiel #1
0
        public async Task UpdateModeratedSubredditsTest()
        {
            var uman  = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext(  )));
            var ident = uman.FindByName("snoonotes");

            AuthUtils.CheckTokenExpiration(ident);

            ident.Claims.Clear();

            ident.Claims.Add(new IdentityUserClaim()
            {
                UserId = ident.Id, ClaimType = "urn:snoonotes:subreddits:goawaynoonelikesyou:admin", ClaimValue = "true"
            });
            ident.Claims.Add(new IdentityUserClaim()
            {
                UserId = ident.Id, ClaimType = ClaimsIdentity.DefaultRoleClaimType, ClaimValue = "gooaway"
            });

            await AuthUtils.UpdateModeratedSubreddits(ident, uman);

            if (ident.Claims.Any(c => c.ClaimType == "urn:snoonotes:subreddits:goawaynoonelikesyou:admin"))
            {
                Assert.Fail("Admin claim not removed.");
            }
            if (ident.Claims.Any(c => c.ClaimType == ClaimsIdentity.DefaultRoleClaimType && c.ClaimValue == "gooaway"))
            {
                Assert.Fail("Invalid sub claim not removed");
            }
            if (!ident.Claims.Any(c => c.ClaimType == ClaimsIdentity.DefaultRoleClaimType && c.ClaimValue == "snoonotes"))
            {
                Assert.Fail("Access roll not added");
            }
            if (!ident.Claims.Any(c => c.ClaimType == ClaimsIdentity.DefaultRoleClaimType && c.ClaimValue == "goawaynoonelikesyou"))
            {
                Assert.Fail("Access roll not added");
            }
            if (!ident.Claims.Any(c => c.ClaimType == "urn:snoonotes:subreddits:snoonotes:admin" && c.ClaimValue == "true"))
            {
                Assert.Fail("Admin roll not added");
            }
        }