public void Should_add_an_item_to_the_start_of_the_begin_pipeline_when_RequiresAuthentication_enabled() { var module = new FakeHookedModule(A.Fake <BeforePipeline>()); module.RequiresAuthentication(); A.CallTo(() => module.Before.AddItemToEndOfPipeline(A <Func <NancyContext, Response> > .Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
public void Should_return_null_with_RequiresAuthentication_enabled_and_username_provided() { var module = new FakeHookedModule(new BeforePipeline()); module.RequiresAuthentication(); var context = new NancyContext(); context.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = "test"; var result = module.Before.Invoke(context); result.ShouldBeNull(); }
public void Should_return_unauthorized_response_with_RequiresAuthentication_enabled_and_blank_username() { var module = new FakeHookedModule(new BeforePipeline()); module.RequiresAuthentication(); 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); }
public void Should_return_unauthorized_response_with_RequiresAuthentication_enabled_and_no_identity() { var module = new FakeHookedModule(new BeforePipeline()); module.RequiresAuthentication(); var context = new NancyContext { CurrentUser = new ClaimsPrincipal() }; var result = module.Before.Invoke(context, new CancellationToken()); result.Result.ShouldNotBeNull(); result.Result.StatusCode.ShouldEqual(HttpStatusCode.Unauthorized); }