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.AddItemToStartOfPipeline(A<Func<NancyContext, Response>>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
public void Should_return_unauthorized_response_with_RequiresAuthentication_enabled_and_no_user() { var module = new FakeHookedModule(new BeforePipeline()); module.RequiresAuthentication(); var result = module.Before.Invoke(new NancyContext(), new CancellationToken()); result.Result.ShouldNotBeNull(); result.Result.StatusCode.ShouldEqual(HttpStatusCode.Unauthorized); }
public void Should_return_null_with_RequiresAuthentication_enabled_and_user_provided() { var module = new FakeHookedModule(new BeforePipeline()); module.RequiresAuthentication(); var context = new NancyContext { CurrentUser = GetFakeUser("Bob") }; var result = module.Before.Invoke(context, new CancellationToken()); result.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 { CurrentUser = GetFakeUser(String.Empty) }; var result = module.Before.Invoke(context, new CancellationToken()); result.Result.ShouldNotBeNull(); result.Result.StatusCode.ShouldEqual(HttpStatusCode.Unauthorized); }
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_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(); }