コード例 #1
0
        public void Should_add_two_items_to_the_start_of_the_begin_pipeline_when_RequiresValidatedClaims_enabled()
        {
            var module = new FakeHookedModule(A.Fake <BeforePipeline>());

            module.RequiresValidatedClaims(c => false);

            A.CallTo(() => module.Before.AddItemToStartOfPipeline(A <Func <NancyContext, Response> > .Ignored)).MustHaveHappened(Repeated.Exactly.Twice);
        }
コード例 #2
0
        public void Should_return_unauthorized_response_with_RequiresValidatedClaims_enabled_and_no_username()
        {
            var module = new FakeHookedModule(new BeforePipeline());

            module.RequiresValidatedClaims(c => false);

            var result = module.Before.Invoke(new NancyContext());

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Unauthorized);
        }
コード例 #3
0
        public void Should_return_null_with_RequiresValidatedClaims_and_IsValid_returns_true()
        {
            var module  = new FakeHookedModule(new BeforePipeline());
            var context = new NancyContext();

            context.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = "username";
            context.Items[Nancy.Security.SecurityConventions.AuthenticatedClaimsKey]   = new[] { "Claim1", "Claim2", "Claim3" };
            module.RequiresValidatedClaims(s => true);

            var result = module.Before.Invoke(context);

            result.ShouldBeNull();
        }
コード例 #4
0
        public void Should_return_null_with_RequiresValidatedClaims_and_IsValid_returns_true()
        {
            var module  = new FakeHookedModule(new BeforePipeline());
            var context = new NancyContext
            {
                CurrentUser = GetFakeUser("username", new[] { "Claim1", "Claim2", "Claim3" })
            };

            module.RequiresValidatedClaims(s => true);

            var result = module.Before.Invoke(context);

            result.ShouldBeNull();
        }
コード例 #5
0
        public void Should_return_forbidden_response_with_RequiresValidatedClaims_enabled_but_claims_missing()
        {
            var module = new FakeHookedModule(new BeforePipeline());

            module.RequiresValidatedClaims(s => true);
            var context = new NancyContext
            {
                CurrentUser = GetFakeUser("username")
            };
            var result = module.Before.Invoke(context);

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
        }
コード例 #6
0
        public void Should_return_forbidden_response_with_RequiresValidatedClaims_and_IsValid_returns_true()
        {
            var module  = new FakeHookedModule(new BeforePipeline());
            var context = new NancyContext();

            context.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = "username";
            context.Items[Nancy.Security.SecurityConventions.AuthenticatedClaimsKey]   = new[] { "Claim1", "Claim2", "Claim3" };
            module.RequiresValidatedClaims(s => false);

            var result = module.Before.Invoke(context);

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
        }
コード例 #7
0
        public void Should_return_forbidden_response_with_RequiresValidatedClaims_enabled_but_claims_key_missing()
        {
            var module = new FakeHookedModule(new BeforePipeline());

            module.RequiresValidatedClaims(s => true);
            var context = new NancyContext();

            context.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = "username";

            var result = module.Before.Invoke(context);

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
        }
コード例 #8
0
        public void Should_return_unauthorized_response_with_RequiresValidatedClaims_enabled_and_blank_username()
        {
            var module = new FakeHookedModule(new BeforePipeline());

            module.RequiresValidatedClaims(c => false);
            var context = new NancyContext();

            context.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = String.Empty;

            var result = module.Before.Invoke(context);

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Unauthorized);
        }
コード例 #9
0
        public void Should_return_forbidden_response_with_RequiresValidatedClaims_and_IsValid_returns_false()
        {
            var module  = new FakeHookedModule(new BeforePipeline());
            var context = new NancyContext
            {
                CurrentUser = GetFakeUser("username", new[] { "Claim1", "Claim2", "Claim3" })
            };

            module.RequiresValidatedClaims(s => false);

            var result = module.Before.Invoke(context);

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(HttpStatusCode.Forbidden);
        }
コード例 #10
0
        public void Should_return_unauthorized_response_with_RequiresValidatedClaims_enabled_and_blank_username()
        {
            var module = new FakeHookedModule(new BeforePipeline());

            module.RequiresValidatedClaims(c => false);
            var context = new NancyContext
            {
                CurrentUser = GetFakeUser(String.Empty)
            };

            var result = module.Before.Invoke(context, new CancellationToken());

            result.Result.ShouldNotBeNull();
            result.Result.StatusCode.ShouldEqual(HttpStatusCode.Unauthorized);
        }
コード例 #11
0
        public void Should_call_IsValid_delegate_with_RequiresValidatedClaims_and_valid_username()
        {
            bool called  = false;
            var  module  = new FakeHookedModule(new BeforePipeline());
            var  context = new NancyContext();

            context.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = "username";
            context.Items[Nancy.Security.SecurityConventions.AuthenticatedClaimsKey]   = new[] { "Claim1", "Claim2", "Claim3" };
            module.RequiresValidatedClaims(s =>
            {
                called = true;
                return(true);
            });

            module.Before.Invoke(context);

            called.ShouldEqual(true);
        }
コード例 #12
0
        public void Should_call_IsValid_delegate_with_RequiresValidatedClaims_and_valid_username()
        {
            bool called  = false;
            var  module  = new FakeHookedModule(new BeforePipeline());
            var  context = new NancyContext
            {
                CurrentUser = GetFakeUser("username", new[] { "Claim1", "Claim2", "Claim3" })
            };

            module.RequiresValidatedClaims(s =>
            {
                called = true;
                return(true);
            });

            module.Before.Invoke(context);

            called.ShouldEqual(true);
        }