-
Notifications
You must be signed in to change notification settings - Fork 7
DE-135 - Doppler security #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52272ef
chore: add public and private key files for development environment
andresmoschini 1a61e6e
chore(deps): add dependency on Microsoft.AspNetCore.Authentication.Jw…
andresmoschini c341615
feat: add a new test endpoint for anonymous connections
andresmoschini 6ffde0e
feat: add a new test endpoint for connections with valid token signature
andresmoschini 8db618a
feat: add a new test endpoint for connections with a super user's token
andresmoschini fbc09fe
feat: add a new test endpoint for connections related to an account id
andresmoschini 78e27fd
feat: add a new test endpoint for connections related to an accountname
andresmoschini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,82 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Mvc.Testing; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Doppler.HelloMicroservice | ||
| { | ||
| public class AuthorizationTest | ||
| : IClassFixture<WebApplicationFactory<Startup>> | ||
| { | ||
| const string TOKEN_EMPTY = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.e30.Nbd00AAiP2vJjxr78oPZoPRsDml5dx2bdD1Y6SXomfZN8pzJdKel2zrplvXCGBBYNBOo90rdYSlBCCo15rxsVydiFcAP84qZv-2mh4pFED9tVyDbxV5hvYDSg2bHPFyYFAi26fJusu_oYY3ne8OWxx-W1MEzNxh2hPfEKTkd0zVBm4dZv_irizRpa_qBwjn3hbCLUtOhBFbTTFItM9hESo6RwHvtQaB0667Sj8N97-bleCY5Ppf6bUUMz2A35PDb8-roF5Scf97lTZfug_DymgpPRSNK2VcRjfAynKfbBSih4QqVeaxR5AhYtXVFbQgByrynYNLok1SFD-M48WpzSA"; | ||
| const string TOKEN_BROKEN = "eyJhbGciOiJSzI1NiIsInR5cCI6IkpXVCJ9.e0.Nbd00AAiP2vJjxr8oPZoPRsDml5dx2bdD1Y6SXomfZN8pzJdKel2zrplvXCGBBYNBOo90rdYSlBCCo15rxsVydiFcAP84qZv-2mh4pFED9tVyDbxV5hvYDSg2bHPFyYFAi26fJusu_oYY3ne8OWxx-W1MEzNxh2hPfEKTkd0zVBm4dZv_irizRpa_qBwjn3hbCLUtOhBFbTTFItM9hESo6RwHvtQaB0667Sj8N97-bleCY5Ppf6bUUMz2A35PDb8-roF5Scf97lTZfug_DymgpPRSNK2VcRjfAynKfbBSih4QqVeaxR5AhYtXVbQgByrynYNLok1SFD-M48WpzSA"; | ||
| const string TOKEN_EXPIRE_20961002 = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjQwMDAwMDAwMDB9.aOGfzmkPUKPE9dpIBvH1tMmCOAjLnNQ_nPulDc8dVW0eQbpII5ijDM_QHs8rRI4k7WQFml_AI-KigLqH2kloT58UaVU9UoYsJhPbM7cDYTMvs718EoopTJVCT5liPZM884m26YoFk9DE3GWkgh959kHZAWnzEFqDcaPUcrtcbbK4i9MPdJa_3Pu5tmWbWwdK0d3yIAuPWiQCAc-mbEqDwMCuI57gnX9RtnE1p-iflLxjjtjpovR0cSlwR6ESpQhhdBipFGjpvNOXxgS9ufxKGPg3e6UWN4SJUQzaskwh9QkZRFz_ca5Ge_yuGSQ_c6ZNJaNclkhxnH4BS5w7nnlUdQ"; | ||
| const string TOKEN_EXPIRE_20330518 = "eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp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
|
||
| private readonly WebApplicationFactory<Startup> _factory; | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public AuthorizationTest(WebApplicationFactory<Startup> factory, ITestOutputHelper output) | ||
| { | ||
| _factory = factory; | ||
| _output = output; | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("/hello/anonymous", HttpStatusCode.OK)] | ||
| public async Task GET_helloAnonymous_should_not_require_token(string url, HttpStatusCode expectedStatusCode) | ||
| { | ||
| // Arrange | ||
| var client = _factory.CreateClient(new WebApplicationFactoryClientOptions()); | ||
|
|
||
| // Act | ||
| var response = await client.GetAsync(url); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expectedStatusCode, response.StatusCode); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("/hello/anonymous", TOKEN_EMPTY, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_EXPIRE_20961002, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_EXPIRE_20330518, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_EXPIRE_20010908, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_BROKEN, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_SUPERUSER_EXPIRE_20961002, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_SUPERUSER_EXPIRE_20330518, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_SUPERUSER_EXPIRE_20010908, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_SUPERUSER_FALSE_EXPIRE_20330518, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_ACCOUNT_123_TEST1_AT_TEST_DOT_COM_EXPIRE_20961002, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_ACCOUNT_123_TEST1_AT_TEST_DOT_COM_EXPIRE_20330518, HttpStatusCode.OK)] | ||
| [InlineData("/hello/anonymous", TOKEN_ACCOUNT_123_TEST1_AT_TEST_DOT_COM_EXPIRE_20010908, HttpStatusCode.OK)] | ||
| public async Task GET_helloAnonymous_should_accept_any_token(string url, string token, HttpStatusCode expectedStatusCode) | ||
| { | ||
| // Arrange | ||
| var client = _factory.CreateClient(new WebApplicationFactoryClientOptions()); | ||
|
|
||
| var request = new HttpRequestMessage(HttpMethod.Get, url) | ||
| { | ||
| Headers = { { "Authorization", $"Bearer {token}" } } | ||
| }; | ||
|
|
||
| // Act | ||
| var response = await client.SendAsync(request); | ||
| _output.WriteLine(response.GetHeadersAsString()); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expectedStatusCode, response.StatusCode); | ||
| } | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
Doppler.HelloMicroservice.Test/HttpResponseMessageExtensions.cs
This file contains hidden or 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,16 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
|
|
||
| namespace Doppler.HelloMicroservice | ||
| { | ||
| public static class HttpResponseMessageExtensions | ||
| { | ||
| public static string GetHeadersAsString(this HttpResponseMessage response) | ||
| { | ||
| var keysAndValues = response.Headers.SelectMany(x => x.Value.Select(y => new { x.Key, Value = y })); | ||
| var headerLines = keysAndValues.Select(x => $"{x.Key}: {x.Value}"); | ||
| return string.Join("\n", headerLines); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Authorization; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Doppler.HelloMicroservice.Controllers | ||
| { | ||
| [ApiController] | ||
| public class HelloController | ||
| { | ||
| [HttpGet("/hello/anonymous")] | ||
| public string GetForAnonymous() | ||
| { | ||
| return "Hello anonymous!"; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,3 +13,6 @@ GET {{base}}/swagger/index.html | |
|
|
||
| ### | ||
| GET {{base}}/version.txt | ||
|
|
||
| ### | ||
| GET {{base}}/hello/anonymous | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure but we need that anonymous endpoint just not response
401status code.Assert.NotEqual(HttpStatusCode.Unauthorized, response.StatusCode);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not understand.
Is not enough waiting for a
200 OK?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, It is, but I am thinking on another response status like
InternalServerError, and that still a valid scenario.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I understand now.
I think that an
InternalServerErroris not enough to confirm that anonymous authorization is working fine.Maybe there is another problem, so, in that case, the result should not be pass, maybe inconclusive, but in that case, the test will be more complex.