-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat(ui-web): refactor the web backend, create tests #88
feat(ui-web): refactor the web backend, create tests #88
Conversation
Hey @followynne, |
@mo-esmp sure, no worries - take all the time you need! 👍 Since I didn't proceed in the last weeks on the React part, I wanted to at least submit the completed piece as a separate PR, to get something rollin' 😄 thus 0 hurry :) |
@@ -9,7 +9,7 @@ | |||
<ItemGroup> | |||
<PackageReference Include="NEST" Version="7.11.1" /> | |||
<PackageReference Include="NEST.JsonNetSerializer" Version="7.11.1" /> | |||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> |
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.
Let's move Newtonsoft.Json
to Serilog.Ui.Core
project since it is referenced in most projects.
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.
applied
|
||
namespace Serilog.Ui.Web.Authorization | ||
{ | ||
internal interface IAuthorizationFilterService |
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.
Move the interface to a separate file.
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.
applied
Func<HttpResponse, Task> onFailure = null) | ||
{ | ||
var accessCheck = await CanAccess(httpContext, options); | ||
if (!accessCheck) |
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.
Revert if
condition.
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.
reverted
|
||
namespace Serilog.Ui.Web.Endpoints | ||
{ | ||
internal interface IAppStreamLoader |
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.
Move to a separate file.
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.
done
internal class AppStreamLoader : IAppStreamLoader | ||
{ | ||
private const string AppManifest = "Serilog.Ui.Web.wwwroot.dist.index.html"; | ||
public Stream GetIndex() => |
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.
Add a break line.
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.
applied
internal class SerilogUiEndpoints : ISerilogUiEndpoints | ||
{ | ||
private readonly ILogger<SerilogUiEndpoints> _logger; | ||
private readonly JsonSerializerSettings _jsonSerializerOptions; |
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.
Make it static.
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.
applied
|
||
var provider = httpContext.RequestServices.GetService<AggregateDataProvider>(); | ||
|
||
string key = dbKey; |
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.
Remove the temp variable.
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.
done
public static bool IsLocal(this HttpRequest request) | ||
{ | ||
var ipAddress = request.Headers["X-forwarded-for"].FirstOrDefault(); | ||
if (!string.IsNullOrWhiteSpace(ipAddress)) |
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.
Add {}
->
if(..)
{
...
}
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.
applied
@@ -7,7 +7,7 @@ | |||
</PropertyGroup> | |||
|
|||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" /> | |||
</ItemGroup> | |||
|
|||
<ItemGroup> |
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.
Please remove the below from csproj
.
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
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.
applied
var httpMethod = httpContext.Request.Method; | ||
var isGet = httpMethod == "GET"; | ||
|
||
if (isGet) |
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.
Invert if
.
if (!isGet)
{
return _staticFileMiddleware.Invoke(httpContext);
}
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.
applied
|
||
|
||
[Trait("Ui-Authorization", "Web")] | ||
public class AuthorizationDefaultTest : IClassFixture<WebAppFactory.Default> |
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.
Keep all authorization tests in one class or move test classes to separate files.
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.
moved filters utils to the Utilities folder, separated test classes in files
[Fact] | ||
public async Task It_gets_app_home() | ||
{ | ||
sut.SetOptions(new() |
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.
It would be great if you add // Arrange
, // Act
and // Assert
comments to new tests.
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.
should be added now on entire ui.web :)
[Trait("Ui-Api-Routes", "Web")] | ||
public class SerilogUiAppRoutesTest | ||
{ | ||
private readonly IAppStreamLoader streamLoaderMock; |
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.
Please use _
for all private fields in test classes.
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.
applied
[Fact] | ||
public void It_is_local_when_remote_ip_address_equals_local_ip_address() | ||
{ | ||
var mock = Substitute.For<HttpRequest>(); |
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.
Optional: mockHttpRequest
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.
applied
public void It_is_local_when_remote_ip_address_equals_local_ip_address() | ||
{ | ||
var mock = Substitute.For<HttpRequest>(); | ||
var context = Substitute.For<HttpContext>(); |
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.
Optional: mockHttpContext
(and for the rest of test methods)
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.
applied
Hello @mo-esmp thanks for the deep review, I updated the code on all comments except one (where you'll find a question). I'll leave to you each comment resolution, to be sure I didn't miss anything while doing them 😄 |
@followynne, as always, thanks for the contribution and improving stuff. |
Hello @mo-esmp
this PR aims to refactor the backend part of Web.Ui, to improve maintanability and to be able to test it in depth with a simpler approach.
(I did this part while working on the react-ui; since I'm going longer than expected with the react part (missing the css parts and a couple feat related to the auth token), I'm making this PR with the pieces that are independent-completed)
It includes