Skip to content

Commit

Permalink
Changes to LocalTest to support test of multiple apps (#6967)
Browse files Browse the repository at this point in the history
* • Support for authorization of multiple apps
• Changed interface of InstanceClient.GetInstances to  match interface in test/prod
• Added implementation of GetInstancesFromQuery

* Corrected bug in test for appId

* Corrected typeo in "LocalPlatformSettings:AppRepositoryBasePath"

* Restored InstanceClient.cs

* deleting outdated file

* Added more supported filters for GetInstances

* Changed parameter names (https://docs.altinn.studio/api/platform/instances/) is wrong.

* Removed error condition check

* triggering github actions

* Removed test for active app

Co-authored-by: Henning Normann <[email protected]>
Co-authored-by: Stephanie Buadu <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2021
1 parent dcdfa80 commit 48113ba
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ public async Task<ActionResult> LogInTestUser(StartAppModel startAppModel)

Application app = GetAppItem(startAppModel.AppPathSelection + "/config");

_appSelectionService.SetAppPath(startAppModel.AppPathSelection);

return Redirect($"{_generalSettings.GetBaseUrl}/{app.Id}/");
}

Expand Down Expand Up @@ -168,6 +166,7 @@ public async Task<ActionResult> GetTestOrgToken(string id, [FromQuery] string or
string issuer = "altinn3local.no";
claims.Add(new Claim(AltinnCoreClaimTypes.Org, id.ToLower(), ClaimValueTypes.String, issuer));
claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, "2", ClaimValueTypes.Integer32, issuer));
claims.Add(new Claim("urn:altinn:scope", "altinn:serviceowner/instances.read", ClaimValueTypes.String, issuer));
if (!string.IsNullOrEmpty(orgNumber))
{
claims.Add(new Claim(AltinnCoreClaimTypes.OrgNumber, orgNumber, ClaimValueTypes.String, issuer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PolicyRetrievalPoint(IOptions<LocalPlatformSettings> localPlatformSetting
/// <inheritdoc/>
public Task<XacmlPolicy> GetPolicyAsync(XacmlContextRequest request)
{
string policyPath = GetPolicyPath();
string policyPath = GetPolicyPath(request);
return Task.FromResult(ParsePolicy(policyPath));
}

Expand All @@ -44,9 +44,9 @@ public Task<XacmlPolicy> GetPolicyAsync(string org, string app)
throw new NotImplementedException();
}

private string GetPolicyPath()
private string GetPolicyPath(XacmlContextRequest request)
{
return _localTestAppSelectionService.GetAppPath() + $"config/authorization/policy.xml";
return _localTestAppSelectionService.GetAppPath(request) + $"config/authorization/policy.xml";
}

public static XacmlPolicy ParsePolicy(string policyPath)
Expand Down
22 changes: 17 additions & 5 deletions src/Services/Localtest/Implementation/LocalTestAppSelectionSI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Altinn.Authorization.ABAC.Xacml;
using LocalTest.Services.Localtest.Interface;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -8,16 +10,26 @@ namespace LocalTest.Services.Localtest.Implementation
{
public class LocalTestAppSelectionSI : ILocalTestAppSelection
{
private string _appPath;
private string _appRepsitoryBasePath;

public string GetAppPath()
public LocalTestAppSelectionSI(IConfiguration configuration)
{
return _appPath;
_appRepsitoryBasePath = configuration["LocalPlatformSettings:AppRepositoryBasePath"];
}

public void SetAppPath(string path)
public string GetAppPath(XacmlContextRequest request)
{
_appPath = path;
string app = request.GetResourceAttributes().Attributes.Where(a => a.AttributeId.ToString() == "urn:altinn:app").Select(a => a.AttributeValues.FirstOrDefault()).FirstOrDefault().Value;

return GetAppPath(app);
}

public string GetAppPath(string app)
{
if (string.IsNullOrEmpty(app))
return null;

return $"{_appRepsitoryBasePath.TrimEnd('/').TrimEnd('\\')}/{app}/App/";
}
}
}
7 changes: 4 additions & 3 deletions src/Services/Localtest/Interface/ILocalTestAppSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using System.Linq;
using System.Threading.Tasks;

using Altinn.Authorization.ABAC.Xacml;

namespace LocalTest.Services.Localtest.Interface
{
public interface ILocalTestAppSelection
{
public string GetAppPath(XacmlContextRequest request);

public void SetAppPath(string path);

public string GetAppPath();
public string GetAppPath(string app);
}
}
6 changes: 3 additions & 3 deletions src/Services/Storage/Implementation/ApplicationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Task<bool> Delete(string appId, string org)
public Task<Application> FindOne(string appId, string org)
{
string filedata = string.Empty;
string filename = GetApplicationPath();
string filename = GetApplicationPath(string.IsNullOrEmpty(appId) ? appId : appId.Split('/')[1]);

try
{
Expand Down Expand Up @@ -70,9 +70,9 @@ public Task<Application> Update(Application item)
throw new NotImplementedException();
}

private string GetApplicationPath()
private string GetApplicationPath(string app)
{
return _localTestAppSelectionService.GetAppPath() + "config/applicationmetadata.json";
return _localTestAppSelectionService.GetAppPath(app) + "config/applicationmetadata.json";
}

public Task<List<Application>> FindAll()
Expand Down
6 changes: 0 additions & 6 deletions src/Services/Storage/Implementation/InstanceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ public async Task<InstanceQueryResponse> GetInstancesFromQuery(Dictionary<string
throw new NotImplementedException($"Queries for instances must include applicationId in local test.");
}

string appName = queryParams["appId"].First().Split("/")[1];
if (!_localTestAppSelectionService.GetAppPath().Contains(appName))
{
throw new NotImplementedException($"Only possible to query active application in local test ");
}

List<Instance> instances = new List<Instance>();

string instancesPath = GetInstanceFolder();
Expand Down
6 changes: 3 additions & 3 deletions src/Services/Storage/Implementation/TextRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<TextResource> Get(string org, string app, string language)
{
ValidateArguments(org, app, language);
TextResource textResource = null;
string path = GetTextPath(language);
string path = GetTextPath(language, app);

if (File.Exists(path))
{
Expand All @@ -47,9 +47,9 @@ public async Task<TextResource> Get(string org, string app, string language)
return textResource;
}

private string GetTextPath(string language)
private string GetTextPath(string language, string app)
{
return _localTestAppSelectionService.GetAppPath() + $"config/texts/resource.{language.AsFileName()}.json";
return _localTestAppSelectionService.GetAppPath(app) + $"config/texts/resource.{language.AsFileName()}.json";
}

/// <inheritdoc/>
Expand Down

0 comments on commit 48113ba

Please sign in to comment.