-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TestData rewrite for LocalTest (#9342)
* Consolidate reading of TestData in Localtest This is in preparation of adding multiple data sources for registry data. Also enable <ImplicitUsings> for localtest and gradually enable nullable reference types on single files while I touch them. * Add indentation to json responses from LocalTest * Add new simplified test data model, and a few debug endpoints on HomeController * Add functionality to fetch an alternate user database from the app itself it is stored in `app/wwwroot/testData.json`
- Loading branch information
Showing
23 changed files
with
666 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 10 additions & 26 deletions
36
src/Services/Authorization/Implementation/ClaimsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,28 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
#nullable enable | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Altinn.Platform.Authentication.Model; | ||
using Altinn.Platform.Authorization.Services.Interface; | ||
using LocalTest.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using LocalTest.Services.TestData; | ||
|
||
namespace LocalTest.Services.Authorization.Implementation | ||
{ | ||
public class ClaimsService : IClaims | ||
{ | ||
private readonly LocalPlatformSettings _localPlatformSettings; | ||
private readonly TestDataService _testDataService; | ||
|
||
public ClaimsService(IOptions<LocalPlatformSettings> localPlatformSettings) | ||
public ClaimsService(TestDataService testDataService) | ||
{ | ||
_localPlatformSettings = localPlatformSettings.Value; | ||
_testDataService = testDataService; | ||
} | ||
|
||
public Task<List<Claim>> GetCustomClaims(int userId, string issuer) | ||
public async Task<List<Claim>> GetCustomClaims(int userId, string issuer) | ||
{ | ||
var path = GetCustomClaimsPath(userId); | ||
|
||
if (File.Exists(path)) | ||
var data = await _testDataService.GetTestData(); | ||
if(data.Authorization.Claims.TryGetValue(userId.ToString(), out var customClaims)) | ||
{ | ||
var content = File.ReadAllText(path); | ||
var claims = JsonConvert.DeserializeObject<List<CustomClaim>>(content) ?? new List<CustomClaim>(); | ||
return Task.FromResult(claims.Select(c => new Claim(c.Type, c.Value, c.ValueType, issuer)).ToList()); | ||
return customClaims.Select(c => new Claim(c.Type, c.Value, c.ValueType, issuer)).ToList(); | ||
} | ||
|
||
return Task.FromResult(new List<Claim>()); | ||
} | ||
|
||
private string GetCustomClaimsPath(int userId) | ||
{ | ||
return _localPlatformSettings.LocalTestingStaticTestDataPath + | ||
_localPlatformSettings.AuthorizationDataFolder + _localPlatformSettings.ClaimsFolder + userId + | ||
".json"; | ||
return new List<Claim>(); | ||
} | ||
} | ||
} |
35 changes: 8 additions & 27 deletions
35
src/Services/Authorization/Implementation/PartiesService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,29 @@ | ||
#nullable enable | ||
using Altinn.Platform.Authorization.Services.Interface; | ||
using Altinn.Platform.Register.Models; | ||
using LocalTest.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using LocalTest.Services.TestData; | ||
|
||
namespace LocalTest.Services.Authorization.Implementation | ||
{ | ||
public class PartiesService : IParties | ||
{ | ||
private readonly LocalPlatformSettings _localPlatformSettings; | ||
private readonly TestDataService _testDataService; | ||
|
||
public PartiesService(IOptions<LocalPlatformSettings> localPlatformSettings) | ||
public PartiesService(TestDataService testDataService) | ||
{ | ||
_localPlatformSettings = localPlatformSettings.Value; | ||
_testDataService = testDataService; | ||
} | ||
|
||
public Task<List<Party>> GetParties(int userId) | ||
public async Task<List<Party>?> GetParties(int userId) | ||
{ | ||
string path = GetPartyListPath(userId); | ||
|
||
if (File.Exists(path)) | ||
{ | ||
string content = System.IO.File.ReadAllText(path); | ||
List<Party> instance = (List<Party>)JsonConvert.DeserializeObject(content, typeof(List<Party>)); | ||
return Task.FromResult(instance); | ||
} | ||
|
||
return null; | ||
var data = await _testDataService.GetTestData(); | ||
return data.Authorization.PartyList.TryGetValue(userId.ToString(), out var result) ? result : null; | ||
} | ||
|
||
public Task<bool> ValidateSelectedParty(int userId, int partyId) | ||
{ | ||
return Task.FromResult(true); | ||
} | ||
|
||
|
||
private string GetPartyListPath(int userId) | ||
{ | ||
return _localPlatformSettings.LocalTestingStaticTestDataPath + _localPlatformSettings.AuthorizationDataFolder + _localPlatformSettings.PartyListFolder + userId + ".json"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.