Skip to content

Commit

Permalink
Sr integration test2 (#141)
Browse files Browse the repository at this point in the history
* get partyId from context instead of header

* changed SystemUserDescriptor to reflect recent design changes

* New API endpoint for Default Rights
  • Loading branch information
simen-rekkedal authored Jan 9, 2024
1 parent 2cb599c commit e69bfe2
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Altinn.Authentication.UI.Core.SystemRegister
{
public class DefaultRightsDTO
{
public string Right { get; set; } = string.Empty;
public string ServiceProvider { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ public class SystemUserDescriptor
/// </summary>
public string? IntegrationTitle { get; set; }

/// <summary>
/// Either set by the end-user as instructions to self,
/// or provided by the SystemType as extra info
/// </summary>
public string? Description { get; set; }

/// <summary>
/// The actual chosen systemType that this SystemUser
/// creates an integration / delegation for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ private static SystemUserReal MapDescriptorToSystemUserReal(SystemUserDescriptor
ClientId = Guid.NewGuid().ToString(),
SystemType = sysdescr.SelectedSystemType,
Title = sysdescr.IntegrationTitle,
Description = sysdescr.Description,
Created = DateTime.UtcNow.Date.ToString()

};
Expand Down Expand Up @@ -66,8 +65,6 @@ public SystemUserClient(HttpClient httpClient)
}

return null;


}

public async Task<bool> DeleteSystemUserReal(Guid id, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private static SystemUserReal MapDescriptorToSystemUserReal(SystemUserDescriptor
ClientId = Guid.NewGuid().ToString(),
SystemType = sysdescr.SelectedSystemType,
Title = sysdescr.IntegrationTitle,
Description = sysdescr.Description,
Created = DateTime.UtcNow.Date.ToString()

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace Altinn.Authentication.UI.Tests.Clients;
/// Needs a running instance of the Authentication Component on localhost on port 44377
/// </summary>
[Collection ("SystemUserClient Integration Test vs Authentication Component")]
public class SystemUserClientTest : IClassFixture<CustomWebApplicationFactory<SystemUserController>>
public class SystemUserClientIntegrationTest : IClassFixture<CustomWebApplicationFactory<SystemUserController>>
{
private readonly ISystemUserClient _systemUserClient;

public SystemUserClientTest()
public SystemUserClientIntegrationTest()
{
_systemUserClient = new SystemUserClient(
new HttpClient{BaseAddress = new UriBuilder("https://localhost:44377/").Uri});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ public async Task<ActionResult> GetListOfRegisteredSystems(CancellationToken can
{
List<RegisteredSystemDTO> lista = new();

lista.AddRange( await _systemRegisterService.GetListRegSys(cancellationToken));
lista.AddRange(await _systemRegisterService.GetListRegSys(cancellationToken));

return Ok(lista);
}

[HttpGet("product/{productId}")]
public async Task<ActionResult> GetDefaultRightsForProductName(string productId, CancellationToken cancellationToken = default)
{
List<DefaultRightsDTO> lista = new();
DefaultRightsDTO l1 = new() { Right = "Mva Registrering", ServiceProvider = "Skatteetaten" };
DefaultRightsDTO l2 = new() { Right = "Lønns Rapportering", ServiceProvider = "Skatteetaten" };
DefaultRightsDTO l3 = new() { Right = "Lakselus Rapportering", ServiceProvider = "Mattilsynet" };
lista.Add(l1);
lista.Add(l2);
lista.Add(l3);
return Ok(lista);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Authentication.UI.Core.SystemUsers;
using Altinn.Authentication.UI.Core.Authentication;
using Altinn.Authentication.UI.Core.SystemUsers;
using Altinn.Authentication.UI.Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -17,13 +18,15 @@ namespace Altinn.Authentication.UI.Controllers;
public class SystemUserController : ControllerBase
{
ISystemUserService _systemUserService;
IHttpContextAccessor _httpContextAccessor;

/// <summary>
/// Constructor for <see cref="SystemUserController"/>
/// </summary>
public SystemUserController(ISystemUserService systemUserService)
public SystemUserController(ISystemUserService systemUserService, IHttpContextAccessor httpContextAccessor)
{
_systemUserService = systemUserService;
_systemUserService = systemUserService;
_httpContextAccessor = httpContextAccessor;
}


Expand Down Expand Up @@ -88,9 +91,11 @@ public async Task<ActionResult> UploadCertificate([FromForm] IFormFile file, [Fr

//[Authorize]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[HttpPost("{partyId}")]
public async Task<ActionResult> Post(int partyId ,[FromBody] SystemUserDescriptor newSystemUserDescriptor, CancellationToken cancellationToken = default)
[HttpPost]
public async Task<ActionResult> Post([FromBody] SystemUserDescriptor newSystemUserDescriptor, CancellationToken cancellationToken = default)
{
int partyId = AuthenticationHelper.GetUsersPartyId( _httpContextAccessor.HttpContext!);

var usr = await _systemUserService.PostNewSystemUserDescriptor(partyId, newSystemUserDescriptor, cancellationToken);
if (usr is not null)
{
Expand All @@ -105,8 +110,7 @@ public async Task<ActionResult> Post(int partyId ,[FromBody] SystemUserDescripto
[HttpPut("{id}")]
public async void Put(Guid id, [FromBody] SystemUserDescriptor modifiedSystemUser, CancellationToken cancellationToken = default)
{
if (modifiedSystemUser.IntegrationTitle is not null) await _systemUserService.ChangeSystemUserTitle(modifiedSystemUser.IntegrationTitle, id, cancellationToken);
if (modifiedSystemUser.Description is not null) await _systemUserService.ChangeSystemUserTitle(modifiedSystemUser.Description, id, cancellationToken);
if (modifiedSystemUser.IntegrationTitle is not null) await _systemUserService.ChangeSystemUserTitle(modifiedSystemUser.IntegrationTitle, id, cancellationToken);
if (modifiedSystemUser.SelectedSystemType is not null) await _systemUserService.ChangeSystemUserProduct(modifiedSystemUser.SelectedSystemType, id, cancellationToken);
}

Expand Down

0 comments on commit e69bfe2

Please sign in to comment.