Ejemplo n.º 1
0
        public void ReturnTrueForGroupByName()
        {
            IAccount testAccount = null;
            var      group1Name  = $"group1-{_fixture.TestKey}";
            var      group2Name  = $"group2-{_fixture.TestKey}";

            using (new AutoCleanup(_fixture.Client, async c =>
            {
                testAccount = await _fixture.TestDirectory.CreateAccountAsync(NewTestAccount(c));
                var group1 = await _fixture.TestDirectory.CreateGroupAsync(group1Name, $"Stormpath.Owin IT {_fixture.TestKey}");
                var group2 = await _fixture.TestDirectory.CreateGroupAsync(group2Name, $"Stormpath.Owin IT {_fixture.TestKey}");
                await testAccount.AddGroupAsync(group1);
                await testAccount.AddGroupAsync(group2);
                return(new IResource[] { testAccount, group1, group2 });
            }))
            {
                var filter1 = new RequireGroupsFilter(new[] { group1Name });
                filter1.IsAuthorized(testAccount).Should().BeTrue();

                var filter2 = new RequireGroupsFilter(new[] { group2Name });
                filter2.IsAuthorized(testAccount).Should().BeTrue();

                var filterBoth = new RequireGroupsFilter(new[] { group1Name, group2Name });
                filterBoth.IsAuthorized(testAccount).Should().BeTrue();
            }
        }
Ejemplo n.º 2
0
        public void ReturnTrueForGroupByHref()
        {
            IAccount testAccount = null;
            string   group1Href = null, group2Href = null;

            using (new AutoCleanup(_fixture.Client, async c =>
            {
                testAccount = await _fixture.TestDirectory.CreateAccountAsync(NewTestAccount(c));
                var group1 = await _fixture.TestDirectory.CreateGroupAsync($"group1-{Guid.NewGuid()}", $"Stormpath.Owin IT {_fixture.TestKey}");
                var group2 = await _fixture.TestDirectory.CreateGroupAsync($"group1-{Guid.NewGuid()}", $"Stormpath.Owin IT {_fixture.TestKey}");
                await testAccount.AddGroupAsync(group1);
                await testAccount.AddGroupAsync(group2);
                group1Href = group1.Href;
                group2Href = group2.Href;
                return(new IResource[] { testAccount, group1, group2 });
            }))
            {
                var filter1 = new RequireGroupsFilter(new[] { group1Href });
                filter1.IsAuthorized(testAccount).Should().BeTrue();

                var filter2 = new RequireGroupsFilter(new[] { group2Href });
                filter2.IsAuthorized(testAccount).Should().BeTrue();

                var filterBoth = new RequireGroupsFilter(new[] { group1Href, group2Href });
                filterBoth.IsAuthorized(testAccount).Should().BeTrue();
            }
        }