Skip to content

Commit

Permalink
merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
83585-Vanderlan committed Sep 24, 2023
2 parents fb5060b + 6543751 commit 36ea645
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Orion.Api/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<IActionResult> Login([FromBody] UserLoginModel model)
[HttpPost]
public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenModel refreshTokenModel)
{
var userOutput = Mapper.Map<UserOutput>(await _userService.GetUserByRefreshToken(refreshTokenModel.RefreshToken));
var userOutput = Mapper.Map<UserOutput>(await _userService.GetUserByRefreshTokenAsync(refreshTokenModel.RefreshToken));

return await AuthorizeUser(userOutput);
}
Expand All @@ -56,7 +56,7 @@ private async Task<IActionResult> AuthorizeUser(UserOutput userOutput)
{
var token = CreateToken(userOutput);

var refreshToken = await _userService.AddRefreshToken(new RefreshToken { Email = userOutput.Email, Refreshtoken = Guid.NewGuid().ToString().ToSha512()});
var refreshToken = await _userService.AddRefreshTokenAsync(new RefreshToken { Email = userOutput.Email, Refreshtoken = Guid.NewGuid().ToString().ToSha512()});

return Ok(
new UserApiTokenModel
Expand Down
2 changes: 1 addition & 1 deletion Orion.Api/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public UsersController(IUserService userService, IMapper mapper) : base(mapper)
[ProducesResponseType((int)HttpStatusCode.OK)]
public async Task<IActionResult> Get([FromQuery] UserFilter filter)
{
var user = await _userService.ListPaginate(filter);
var user = await _userService.ListPaginateAsync(filter);

var userOutputList = Mapper.Map<PagedList<UserOutput>>(user);

Expand Down
14 changes: 7 additions & 7 deletions Orion.Api/Orion.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
Expand All @@ -23,14 +23,14 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.1" />
<PackageReference Include="NLog" Version="5.1.1" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.5" />
<PackageReference Include="NLog" Version="5.1.2" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 0 additions & 16 deletions Orion.Api/ValidateModelStateAttribute .cs
Original file line number Diff line number Diff line change
@@ -1,16 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Orion.Api
{
public class ValidateModelStateAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
context.Result = new BadRequestObjectResult(context.ModelState);
}
}
}
}
6 changes: 3 additions & 3 deletions Orion.Data/Orion.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions Orion.Domain/Implementation/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ public async Task UpdateAsync(User user)
await _unitOfWork.CommitAsync();
}

public async Task<RefreshToken> AddRefreshToken(RefreshToken refreshToken)
public async Task<RefreshToken> AddRefreshTokenAsync(RefreshToken refreshToken)
{
var existentRt = await _unitOfWork.RefreshTokenRepository.GetBy(x => x.Email == refreshToken.Email);
var existantRt = await _unitOfWork.RefreshTokenRepository.GetBy(x => x.Email == refreshToken.Email);

if (existentRt.Any())
return existentRt.First();
if (existantRt.Any())
return existantRt.First();

var added = await _unitOfWork.RefreshTokenRepository.AddAsync(refreshToken);
await _unitOfWork.CommitAsync();

return added;
}

public async Task<User> GetUserByRefreshToken(string refreshToken)
public async Task<User> GetUserByRefreshTokenAsync(string refreshToken)
{
if (string.IsNullOrEmpty(refreshToken))
{
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task<User> GetUserByRefreshToken(string refreshToken)
throw new UnauthorizedUserException(_messages[UserMessages.InvalidRefreshToken], _messages[ExceptionsTitles.AuthenticationError]);
}

public async Task<PagedList<User>> ListPaginate(UserFilter filter)
public async Task<PagedList<User>> ListPaginateAsync(UserFilter filter)
{
return await _unitOfWork.UserRepository.ListPaginate(filter);
}
Expand Down
6 changes: 3 additions & 3 deletions Orion.Domain/Interfaces/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Orion.Domain.Interfaces
public interface IUserService : IBaseService<User>
{
Task<User> LoginAsync(string email, string password);
Task<RefreshToken> AddRefreshToken(RefreshToken refreshToken);
Task<User> GetUserByRefreshToken(string refreshToken);
Task<PagedList<User>> ListPaginate(UserFilter filter);
Task<RefreshToken> AddRefreshTokenAsync(RefreshToken refreshToken);
Task<User> GetUserByRefreshTokenAsync(string refreshToken);
Task<PagedList<User>> ListPaginateAsync(UserFilter filter);
}
}
2 changes: 1 addition & 1 deletion Orion.Resources/Messages/MessagesKeys.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Orion.Resources.Messages
{
/// <summary>
/// Update All Resoure Files to matain the globalization support
/// Update all Resource Files to mantain the globalization support
/// </summary>
public static class MessagesKeys
{
Expand Down
2 changes: 1 addition & 1 deletion Orion.Resources/Orion.Resources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Orion.Test/API/HealthCheckApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Orion.Test.API
public class HealthCheckApiTest: ApiTestInitializer
{
[Fact]
public async Task HealthCheckConfigurationTest()
public async Task GetAsync_HealthCheck_ReturnsHealthy()
{
Setup();

Expand Down
12 changes: 6 additions & 6 deletions Orion.Test/Controllers/AuthControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AuthControllerTest()
}

[Fact]
public async Task LoginValidTest()
public async Task Login_WithValidCredentials_ReturnsOk()
{
var result = await _authController.Login(
new UserLoginModel
Expand All @@ -46,7 +46,7 @@ public async Task LoginValidTest()
}

[Fact]
public async Task LoginInvalidTest()
public async Task Login_WithInvalidCredentials_RetunsUnauthorized()
{
var result = await _authController.Login(
new UserLoginModel
Expand All @@ -63,7 +63,7 @@ public async Task LoginInvalidTest()
}

[Fact]
public async Task RefreshTokenValidTest()
public async Task RefreshToken_WithValidRefreshToken_ReturnsNewToken()
{
var result = await _authController.RefreshToken(
RefreshTokenMotherObject.ValidRefreshTokenModel()
Expand All @@ -80,7 +80,7 @@ public async Task RefreshTokenValidTest()
Assert.True(userApiToken.Expiration > DateTime.Now);
}
[Fact]
public async Task RefreshTokenInValidTest()
public async Task RefreshToken_WithInvalidRefreshToken_ReturnsUnauthorized()
{
var result = await _authController.RefreshToken(
new RefreshTokenModel { RefreshToken = null}
Expand All @@ -99,8 +99,8 @@ private void SetupServiceMock()
userServiceMock.Setup(x => x.LoginAsync(UserMotherObject.ValidAdminUser().Email, UserMotherObject.ValidAdminUser().Password))
.ReturnsAsync(UserMotherObject.ValidAdminUser());

userServiceMock.Setup(x => x.AddRefreshToken(It.IsAny<RefreshToken>())).ReturnsAsync(RefreshTokenMotherObject.ValidRefreshToken());
userServiceMock.Setup(x => x.GetUserByRefreshToken(RefreshTokenMotherObject.ValidRefreshToken().Refreshtoken)).ReturnsAsync(UserMotherObject.ValidAdminUser());
userServiceMock.Setup(x => x.AddRefreshTokenAsync(It.IsAny<RefreshToken>())).ReturnsAsync(RefreshTokenMotherObject.ValidRefreshToken());
userServiceMock.Setup(x => x.GetUserByRefreshTokenAsync(RefreshTokenMotherObject.ValidRefreshToken().Refreshtoken)).ReturnsAsync(UserMotherObject.ValidAdminUser());

//Arrange
var inMemorySettings = new Dictionary<string, string> {
Expand Down
11 changes: 5 additions & 6 deletions Orion.Test/Controllers/CustomersControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public CustomersControllerTestTest()
}

[Fact]
public async Task GetCustomerValidTest()
public async Task GetCustomerById_WithValidId_ReturnsValidCustomer()
{
var result = await _customersController.Get(CustomerMotherObject.ValidCustomer().PublicId);

Expand All @@ -39,7 +39,7 @@ public async Task GetCustomerValidTest()
}

[Fact]
public async Task CreateCustomerValidTest()
public async Task PostCustomer_WithValidData_CreateNewCustomer()
{
var result = await _customersController.Post(CustomerMotherObject.ValidCustomerInput());

Expand All @@ -53,7 +53,7 @@ public async Task CreateCustomerValidTest()
}

[Fact]
public async Task EditCustomerValidTest()
public async Task PutCustomer_WithValidData_EditCustomer()
{
var result = await _customersController.Put(CustomerMotherObject.ValidCustomer().PublicId, CustomerMotherObject.ValidCustomerInput());

Expand All @@ -64,7 +64,7 @@ public async Task EditCustomerValidTest()
}

[Fact]
public async Task DeleteCustomerValidTest()
public async Task DeleteCustomer_WithValidId_DeleteCustomer()
{
var result = await _customersController.Delete(CustomerMotherObject.ValidCustomer().PublicId);

Expand All @@ -75,7 +75,7 @@ public async Task DeleteCustomerValidTest()
}

[Fact]
public async Task ListCustomersTest()
public async Task GetCustomers_WithPagination_ReturnsAllCustomers()
{
var result = await _customersController.Get(new CustomerFilter());

Expand All @@ -86,7 +86,6 @@ public async Task ListCustomersTest()
Assert.Equal(200, contentResult.StatusCode);
}


private void SetupServiceMock()
{
var customerServiceMock = new Mock<ICustomerService>();
Expand Down
2 changes: 1 addition & 1 deletion Orion.Test/Controllers/UsersControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void SetupServiceMock()
userServiceMock.Setup(x => x.AddAsync(It.IsAny<User>())).ReturnsAsync(UserMotherObject.ValidAdminUser());
userServiceMock.Setup(x => x.UpdateAsync(It.IsAny<User>())).Verifiable();
userServiceMock.Setup(x => x.DeleteAsync(UserMotherObject.ValidAdminUser().PublicId)).Verifiable();
userServiceMock.Setup(x => x.ListPaginate(It.IsAny<UserFilter>())).
userServiceMock.Setup(x => x.ListPaginateAsync(It.IsAny<UserFilter>())).
ReturnsAsync(userListPaginated);

_usersController = new UsersController(userServiceMock.Object, Mapper);
Expand Down
12 changes: 6 additions & 6 deletions Orion.Test/Orion.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.4" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="7.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions Orion.Test/Services/UserServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task ListUserPaginatedFilterTest()
var userSaved = await userService.AddAsync(UserMotherObject.ValidAdminUser());
var userFound = await userService.FindByIdAsync(userSaved.PublicId);

var userPaginated = await userService.ListPaginate(
var userPaginated = await userService.ListPaginateAsync(
new UserFilter {
Query = UserMotherObject.ValidAdminUser().Name,
Entity = new User
Expand Down Expand Up @@ -192,9 +192,9 @@ public async Task AddRefreshTokenValidTest()

var refreshToken = Guid.NewGuid().ToString();

var refreshTokenAdded = await userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken });
var refreshTokenAdded = await userService.AddRefreshTokenAsync(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken });

var userByRefreshToken = await userService.GetUserByRefreshToken(refreshTokenAdded.Refreshtoken);
var userByRefreshToken = await userService.GetUserByRefreshTokenAsync(refreshTokenAdded.Refreshtoken);

Assert.NotNull(userByRefreshToken);

Expand All @@ -219,9 +219,9 @@ public async Task RefreshTokenNullTest()

var refreshToken = Guid.NewGuid().ToString();

await userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken });
await userService.AddRefreshTokenAsync(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken });

var exeption = await Assert.ThrowsAsync<UnauthorizedUserException>(() => userService.GetUserByRefreshToken(null));
var exeption = await Assert.ThrowsAsync<UnauthorizedUserException>(() => userService.GetUserByRefreshTokenAsync(null));

Assert.Equal(exeption.Message, messages[UserMessages.InvalidRefreshToken]);

Expand All @@ -242,9 +242,9 @@ public async Task RefreshTokenInvalidTest()

var refreshToken = Guid.NewGuid().ToString();

await userService.AddRefreshToken(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken });
await userService.AddRefreshTokenAsync(new RefreshToken { Email = UserMotherObject.ValidAdminUser().Email, Refreshtoken = refreshToken });

var exeption = await Assert.ThrowsAsync<UnauthorizedUserException>(() => userService.GetUserByRefreshToken("wrong refresh token"));
var exeption = await Assert.ThrowsAsync<UnauthorizedUserException>(() => userService.GetUserByRefreshTokenAsync("wrong refresh token"));

Assert.Equal(exeption.Message, messages[UserMessages.InvalidRefreshToken]);

Expand All @@ -254,8 +254,8 @@ public async Task RefreshTokenInvalidTest()
[Fact]
public void CryptoSha512Test()
{
var stringValidTest = "userPawssTest1234A%@&!";
var expectedResult = "8c890b40034e242c05f27eec302a1f552be2a0a879b25b546c38d73c096d04aa8dfbf013a6c7e63a06ef42a346035c0e2256726d5aecb628df7bf6b42804802a";
const string stringValidTest = "userPawssTest1234A%@&!";
const string expectedResult = "8c890b40034e242c05f27eec302a1f552be2a0a879b25b546c38d73c096d04aa8dfbf013a6c7e63a06ef42a346035c0e2256726d5aecb628df7bf6b42804802a";

Assert.Equal(expectedResult, stringValidTest.ToSha512());
}
Expand Down
Loading

0 comments on commit 36ea645

Please sign in to comment.