-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix basic authentication unauthorized result (#91)
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
FakeServer.Test/Authentication/BasicAuthAuthenticationSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace FakeServer.Test.Authentication | ||
{ | ||
[Collection("Integration collection")] | ||
[Trait("category", "integration")] | ||
[Trait("category", "authentication")] | ||
public class BasicAuthAuthenticationSpecs : IDisposable | ||
{ | ||
private readonly IntegrationFixture _fixture; | ||
|
||
public BasicAuthAuthenticationSpecs(IntegrationFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
_fixture.StartServer(authenticationType: "basic"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_fixture.Stop(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUsers_No_Header_Unauthorized() | ||
{ | ||
var result = await _fixture.Client.GetAsync("api/users"); | ||
Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task GetUsers_Authorized() | ||
{ | ||
_fixture.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "YWRtaW46cm9vdA=="); | ||
|
||
var result = await _fixture.Client.GetAsync("api/users"); | ||
Assert.Equal(HttpStatusCode.OK, result.StatusCode); | ||
} | ||
|
||
[Theory] | ||
[InlineData("abbaacdc1234")] | ||
[InlineData("")] | ||
public async Task GetUsers_Wrong_Token_Unauthorized(string token) | ||
{ | ||
_fixture.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", token); | ||
|
||
|
||
var result = await _fixture.Client.GetAsync("api/users"); | ||
Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters