Skip to content
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

Sr at21 integration test config4 #234

Merged
merged 15 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ public interface ISystemUserService
Task<bool> ChangeSystemUserTitle(string newTitle, Guid id, CancellationToken cancellationToken = default);
Task<bool> ChangeSystemUserDescription(string newDescr, Guid id, CancellationToken cancellationToken = default);
Task<bool> ChangeSystemUserProduct(string selectedSystemType, Guid id, CancellationToken cancellationToken = default);
Task<SystemUserDTO?> CheckIfPartyHasIntegration(string clientId, string partyId, string systemOrg, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,4 @@ public async Task<bool> ChangeSystemUserProduct(string selectedSystemType, Guid
{
return await _systemUserClient.ChangeSystemUserRealProduct(selectedSystemType, id, cancellationToken);
}

public Task<SystemUserDTO?> CheckIfPartyHasIntegration(string clientId, string partyId, string systemOrg, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ namespace Altinn.Authentication.UI.Core.UserProfiles;

public class UserProfileService : IUserProfileService
{
//private readonly ILogger _logger;
private readonly ILogger _logger;
private readonly IUserProfileClient _profileClient;

public UserProfileService(
//ILogger logger,
ILogger<UserProfileService> logger,
IUserProfileClient profileClient)
{
//_logger = logger;
_logger = logger;
_profileClient = profileClient;
}

/// <inheritdoc/>
public async Task<UserProfile> GetUserProfile(int userid)
{
UserProfile userProfile = await _profileClient.GetUserProfile(userid);
return userProfile;
return userProfile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/// </summary>
public class PlatformSettings
{
/// <summary>
/// Gets or sets the access management api endpoint
/// </summary>
public string ApiAccessManagementEndpoint { get; set; }

/// <summary>
/// Gets or sets the authentication api endpoint
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,73 @@
using Altinn.Authentication.UI.Core.UserProfiles;
using Altinn.Authentication.UI.Core.Authentication;
using Altinn.Authentication.UI.Core.UserProfiles;
using Altinn.Authentication.UI.Integration.Configuration;
using Altinn.Authentication.UI.Core.Extensions;
using Altinn.Platform.Register.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Altinn.Authentication.UI.Integration.UserProfiles;

/// <summary>
/// Proxy implementation for parties
/// </summary>
[ExcludeFromCodeCoverage]
public class PartyClient : IPartyClient
{
private readonly ILogger _logger;
private readonly HttpClient _client;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly PlatformSettings _platformSettings;
private readonly JsonSerializerOptions _serializerOptions =
new() { PropertyNameCaseInsensitive = true };

/// <summary>
/// Initializes a new instance of the <see cref="LookupClient"/> class
/// </summary>
/// <param name="httpClient">HttpClient from default httpclientfactory</param>
/// <param name="logger">the logger</param>
/// <param name="httpContextAccessor">handler for http context</param>
/// <param name="platformSettings">the platform setttings</param>
public PartyClient(
HttpClient httpClient,
ILogger<PartyClient> logger,
IHttpContextAccessor httpContextAccessor,
IOptions<PlatformSettings> platformSettings)
{
_logger = logger;
_httpContextAccessor = httpContextAccessor;
_platformSettings = platformSettings.Value;
httpClient.BaseAddress = new Uri(_platformSettings.ApiAccessManagementEndpoint);
_client = httpClient;
_serializerOptions.Converters.Add(new JsonStringEnumConverter());
}

/// <inheritdoc/>
public async Task<Party> GetPartyFromReporteeListIfExists(int partyId)
{
Party mock = new()
try
{
PartyId = 5001,
OrgNumber = "123456789MVA",
Name = "Framifrå Bedrift AS"
};
string endpointUrl = $"authorizedparty/{partyId}?includeAltinn2=true";
string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext!, _platformSettings.JwtCookieName!)!;

return mock;
HttpResponseMessage response = await _client.GetAsync(token, endpointUrl);

if ( response.StatusCode == System.Net.HttpStatusCode.OK )
{
string responseContent = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<Party>(responseContent, _serializerOptions)!;
}

return null!;
}
catch (Exception ex)
{
_logger.LogError(ex, "Authentication.UI // PartyClient // GetPartyFromReporteeListIfExists // Exception");
throw;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class UserProfileClient : IUserProfileClient
/// <param name="platformSettings"></param>
/// <param name="accessTokenProvider"></param>
public UserProfileClient(
ILogger logger,
ILogger<UserProfileClient> logger,
HttpClient httpClient,
IHttpContextAccessor httpContextAccessor,
PlatformSettings platformSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Text;
using System.Text.Json;
using Xunit;
using Microsoft.Extensions.Logging;
//using Moq;

namespace Altinn.Authentication.UI.Tests.Controllers;
Expand All @@ -32,11 +33,12 @@ public class ProfileControllerTest : IClassFixture<CustomWebApplicationFactory<P
private readonly IUserProfileService _userProfileService;

public ProfileControllerTest(
CustomWebApplicationFactory<ProfileController> factory)
CustomWebApplicationFactory<ProfileController> factory
)
{
_factory = factory;
//_userProfileClient = new UserProfileClientMock(); //Mock.Of<IUserProfileClient>();
_userProfileService = new UserProfileService( new UserProfileClientMock() );
_userProfileService = new UserProfileService(null, new UserProfileClientMock() );
_client = SetupUtils.GetTestClient(_factory, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,6 @@ public async Task<ActionResult> GetSystemUserDetailsById(Guid guid, Cancellation

return Ok(details);
}

/// <summary>
/// Used by IdPorten, to find if a given systemOrg owns a SystemUser Integration for a Vendor's Product, by ClientId.
/// ConsumerId is the first entry in the path.
/// SystemOrg is the second entry in the path.
/// ClientId is the third entry in the path.
/// </summary>
/// <param name="clientId">The unique id maintained by IdPorten tying their clients to the Registered Systems we maintain</param>
/// <param name="cancellationToken">Cancellationtoken</param>
/// <param name="consumerId">The legal number (Orgno) of the Vendor creating the Registered System (Accounting system)</param>
/// <param name="systemOrg">The legal number (Orgno) of the party owning the System User Integration</param>
/// <returns>The SystemUserIntegration model API DTO</returns>
[Authorize]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[HttpGet("get-consumers-integration-by-clientId/{consumerId}/{systemOrg}/{clientId}")]
public async Task<ActionResult> CheckIfPartyHasIntegration(string clientId, string consumerId, string systemOrg,CancellationToken cancellationToken = default)
{
SystemUserDTO? res = await _systemUserService.CheckIfPartyHasIntegration(clientId, consumerId, systemOrg, cancellationToken);
if (res is null) return NoContent();
return Ok(res);
}

/// <summary>
/// Used to upload a certificate for the System User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using Altinn.Authentication.UI.Filters;
using Altinn.Authentication.UI.Integration.Authentication;
using Altinn.Authentication.UI.Integration.Configuration;
using Altinn.Authentication.UI.Integration.SystemRegister;
using Altinn.Authentication.UI.Integration.SystemUsers;
using Altinn.Authentication.UI.Integration.UserProfiles;
using Altinn.Authentication.UI.Mocks.SystemRegister;
using Altinn.Authentication.UI.Mocks.SystemUsers;
using Altinn.Authentication.UI.Mocks.UserProfiles;
Expand Down Expand Up @@ -126,12 +129,12 @@ public static IServiceCollection AddIntegrationLayer(this IServiceCollection ser
//Clients in the Integration layer for the login user and auth logic
//services.AddHttpClient<IAuthenticationClient, AuthenticationClientMock>();
services.AddHttpClient<IAuthenticationClient, AuthenticationClient>();
services.AddSingleton<IUserProfileClient, UserProfileClientMock>();
services.AddSingleton<IPartyClient, PartyClientMock>();
services.AddHttpClient<IUserProfileClient, UserProfileClient>();

//Clients for the actual Features' Services
services.AddSingleton<ISystemUserClient, SystemUserClientMock>();
services.AddSingleton<ISystemRegisterClient, SystemRegisterClientMock>();
services.AddHttpClient<ISystemUserClient, SystemUserClient>();
services.AddHttpClient<ISystemRegisterClient, SystemRegisterClient>();
services.AddHttpClient<IPartyClient, PartyClient>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"PlatformSettings": {
"ApiAccessManagementEndpoint": "https://platform.at21.altinn.cloud/accessmanagement/api/v1/",
"ApiAuthenticationEndpoint": "https://platform.at21.altinn.cloud/authentication/api/v1/",
"ApiProfileEndpoint": "https://platform.at21.altinn.cloud/profile/api/v1/",
"OpenIdWellKnownEndpoint": "https://platform.at21.altinn.cloud/authentication/api/v1/openid/"
Expand Down
Loading