From 8bdf82292b8c25b2bbe6414556822cecb0d8205c Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Tue, 12 Nov 2024 15:29:09 +0100 Subject: [PATCH] feat: make statuslist type configureable Refs: #299 --- .../templates/deployment-issuer-service.yaml | 2 ++ charts/ssi-credential-issuer/values.yaml | 3 +++ .../BusinessLogic/IssuerBusinessLogic.cs | 7 +++---- .../BusinessLogic/IssuerSettings.cs | 3 +++ .../appsettings.json | 1 + .../BusinessLogic/IssuerBusinessLogicTests.cs | 18 +++++++----------- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/charts/ssi-credential-issuer/templates/deployment-issuer-service.yaml b/charts/ssi-credential-issuer/templates/deployment-issuer-service.yaml index 317eac78..219d7baf 100644 --- a/charts/ssi-credential-issuer/templates/deployment-issuer-service.yaml +++ b/charts/ssi-credential-issuer/templates/deployment-issuer-service.yaml @@ -122,6 +122,8 @@ spec: value: "{{ .Values.service.credential.issuerBpn }}" - name: "CREDENTIAL__STATUSLISTURL" value: "{{ .Values.service.credential.statusListUrl }}" + - name: "CREDENTIAL__STATUSLISTTYPE" + value: "{{ .Values.service.credential.statusListType }}" - name: "CREDENTIAL__ENCRYPTIONCONFIG__ENCRYPTIONCONFIGINDEX" value: "{{ .Values.service.credential.encryptionConfigIndex }}" - name: "CREDENTIAL__ENCRYPTIONCONFIGS__0__INDEX" diff --git a/charts/ssi-credential-issuer/values.yaml b/charts/ssi-credential-issuer/values.yaml index 6e29bfe1..40939472 100644 --- a/charts/ssi-credential-issuer/values.yaml +++ b/charts/ssi-credential-issuer/values.yaml @@ -61,6 +61,9 @@ service: issuerDid: "did:web:example" issuerBpn: "BPNL00000001TEST" statusListUrl: "https://example.org/statuslist" + # -- Type of the status list that is referenced unter statusListUrl + # -- valid types are: StatusList2021, BitstringStatusList + statusListType: "BitstringStatusList" encryptionConfigIndex: 0 encryptionConfigs: index0: diff --git a/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerBusinessLogic.cs b/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerBusinessLogic.cs index d9a03a3a..356815cc 100644 --- a/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerBusinessLogic.cs +++ b/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerBusinessLogic.cs @@ -47,7 +47,6 @@ namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Service.BusinessLogic; public class IssuerBusinessLogic : IIssuerBusinessLogic { - private const string StatusList = "StatusList2021"; private static readonly JsonSerializerOptions Options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; private static readonly IEnumerable Context = new[] { "https://www.w3.org/2018/credentials/v1", "https://w3id.org/catenax/credentials/v1.0.0" }; private static readonly Regex UrlPathInvalidCharsRegex = new("""[""<>#%{}|\\^~\[\]`]+""", RegexOptions.Compiled, TimeSpan.FromSeconds(1)); @@ -355,7 +354,7 @@ public async Task CreateBpnCredential(CreateBpnCredentialRequest requestDa ), new CredentialStatus( _settings.StatusListUrl, - StatusList) + _settings.StatusListType) ); var schema = JsonSerializer.Serialize(schemaData, Options); return await HandleCredentialProcessCreation(requestData.BusinessPartnerNumber, VerifiedCredentialTypeKindId.BPN, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, expiryDate, schema, requestData.TechnicalUserDetails, null, requestData.CallbackUrl, companyCredentialDetailsRepository); @@ -383,7 +382,7 @@ public async Task CreateMembershipCredential(CreateMembershipCredentialReq ), new CredentialStatus( _settings.StatusListUrl, - StatusList) + _settings.StatusListType) ); var schema = JsonSerializer.Serialize(schemaData, Options); return await HandleCredentialProcessCreation(requestData.HolderBpn, VerifiedCredentialTypeKindId.MEMBERSHIP, VerifiedCredentialTypeId.MEMBERSHIP, expiryDate, schema, requestData.TechnicalUserDetails, null, requestData.CallbackUrl, companyCredentialDetailsRepository); @@ -452,7 +451,7 @@ public async Task CreateFrameworkCredential(CreateFrameworkCredentialReque ), new CredentialStatus( _settings.StatusListUrl, - StatusList) + _settings.StatusListType) ); var schema = JsonSerializer.Serialize(schemaData, Options); return await HandleCredentialProcessCreation(requestData.HolderBpn, VerifiedCredentialTypeKindId.FRAMEWORK, requestData.UseCaseFrameworkId, result.Expiry, schema, requestData.TechnicalUserDetails, requestData.UseCaseFrameworkVersionId, requestData.CallbackUrl, companyCredentialDetailsRepository); diff --git a/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerSettings.cs b/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerSettings.cs index ab9d2921..a05cfcfa 100644 --- a/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerSettings.cs +++ b/src/issuer/SsiCredentialIssuer.Service/BusinessLogic/IssuerSettings.cs @@ -45,6 +45,9 @@ public class IssuerSettings [Required(AllowEmptyStrings = false)] public string StatusListUrl { get; set; } = null!; + [Required(AllowEmptyStrings = false)] + public string StatusListType { get; set; } = null!; + [Required(AllowEmptyStrings = false)] public string IssuerBpn { get; set; } = null!; } diff --git a/src/issuer/SsiCredentialIssuer.Service/appsettings.json b/src/issuer/SsiCredentialIssuer.Service/appsettings.json index 999997d1..957ff88e 100644 --- a/src/issuer/SsiCredentialIssuer.Service/appsettings.json +++ b/src/issuer/SsiCredentialIssuer.Service/appsettings.json @@ -74,6 +74,7 @@ "IssuerDid": "", "IssuerBpn": "", "StatusListUrl": "", + "StatusListType": "", "MaxPageSize": 15, "EncryptionConfigIndex": 0, "EncryptionConfigs": [] diff --git a/tests/issuer/SsiCredentialIssuer.Service.Tests/BusinessLogic/IssuerBusinessLogicTests.cs b/tests/issuer/SsiCredentialIssuer.Service.Tests/BusinessLogic/IssuerBusinessLogicTests.cs index f159cc07..1f657fa9 100644 --- a/tests/issuer/SsiCredentialIssuer.Service.Tests/BusinessLogic/IssuerBusinessLogicTests.cs +++ b/tests/issuer/SsiCredentialIssuer.Service.Tests/BusinessLogic/IssuerBusinessLogicTests.cs @@ -591,7 +591,7 @@ public async Task RejectCredential_WithValidRequestAndPendingProcessStepIds_Retu VerifiedCredentialExternalTypeId.TRACEABILITY_CREDENTIAL, CompanyUserId.ToString(), Guid.NewGuid(), - Enumerable.Repeat(Guid.NewGuid(), 1))); + Enumerable.Repeat(Guid.NewGuid(), 1))); A.CallTo(() => _companySsiDetailsRepository.AttachAndModifyCompanySsiDetails(CredentialId, A?>._, A>._!)) .Invokes((Guid _, Action? initialize, Action updateFields) => { @@ -678,15 +678,14 @@ public async Task CreateBpnCredential_ReturnsExpected() var data = new CreateBpnCredentialRequest("https://example.org/holder/BPNL12343546/did.json", Bpnl, null, null); var detail = new CompanySsiDetail(CredentialId, _identity.Bpnl, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, DateTimeOffset.Now); - HttpRequestMessage? request = null; ConfigureHttpClientFactoryFixture(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonSerializer.Serialize(didDocument)) - }, requestMessage => request = requestMessage); + }); A.CallTo(() => _companySsiDetailsRepository.CreateSsiDetails(_identity.Bpnl, VerifiedCredentialTypeId.BUSINESS_PARTNER_NUMBER, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, A>._)) - .Invokes((string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, string userId, Action? setOptionalFields) => setOptionalFields?.Invoke(detail)); + .Invokes((string _, VerifiedCredentialTypeId _, CompanySsiDetailStatusId _, string _, string _, Action? setOptionalFields) => setOptionalFields?.Invoke(detail)); // Act await _sut.CreateBpnCredential(data, CancellationToken.None); @@ -718,12 +717,11 @@ public async Task CreateBpnCredential_WithInvalidUri_ReturnsExpected(string hold var didId = Guid.NewGuid().ToString(); var didDocument = new DidDocument(didId); var data = new CreateBpnCredentialRequest(holderUrl, Bpnl, null, null); - HttpRequestMessage? request = null; ConfigureHttpClientFactoryFixture(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonSerializer.Serialize(didDocument)) - }, requestMessage => request = requestMessage); + }); Task Act() => _sut.CreateBpnCredential(data, CancellationToken.None); // Act @@ -754,17 +752,16 @@ public async Task CreateMembershipCredential_ReturnsExpected() var data = new CreateMembershipCredentialRequest("https://example.org/holder/BPNL12343546/did.json", Bpnl, "Test", null, null); var detail = new CompanySsiDetail(CredentialId, _identity.Bpnl, VerifiedCredentialTypeId.MEMBERSHIP, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, DateTimeOffset.Now); - HttpRequestMessage? request = null; A.CallTo(() => _companySsiDetailsRepository.GetCertificateTypes(A._)) .Returns(Enum.GetValues().ToAsyncEnumerable()); ConfigureHttpClientFactoryFixture(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonSerializer.Serialize(didDocument)) - }, requestMessage => request = requestMessage); + }); A.CallTo(() => _companySsiDetailsRepository.CreateSsiDetails(_identity.Bpnl, VerifiedCredentialTypeId.MEMBERSHIP, CompanySsiDetailStatusId.ACTIVE, IssuerBpnl, _identity.IdentityId, A>._)) - .Invokes((string bpnl, VerifiedCredentialTypeId verifiedCredentialTypeId, CompanySsiDetailStatusId companySsiDetailStatusId, string issuerBpn, string userId, Action? setOptionalFields) => setOptionalFields?.Invoke(detail)); + .Invokes((string _, VerifiedCredentialTypeId _, CompanySsiDetailStatusId _, string _, string _, Action? setOptionalFields) => setOptionalFields?.Invoke(detail)); // Act await _sut.CreateMembershipCredential(data, CancellationToken.None); @@ -925,14 +922,13 @@ public async Task CreateFrameworkCredential_ReturnsExpected() var now = DateTimeOffset.Now; A.CallTo(() => _dateTimeProvider.OffsetNow).Returns(now); var data = new CreateFrameworkCredentialRequest("https://example.org/holder/BPNL12343546/did.json", Bpnl, VerifiedCredentialTypeId.TRACEABILITY_FRAMEWORK, useCaseId, null, null); - HttpRequestMessage? request = null; A.CallTo(() => _companySsiDetailsRepository.CheckCredentialTypeIdExistsForExternalTypeDetailVersionId(useCaseId, VerifiedCredentialTypeId.TRACEABILITY_FRAMEWORK, Bpnl)) .Returns((true, "1.0.0", "https://example.org/tempalte", Enumerable.Repeat(VerifiedCredentialExternalTypeId.TRACEABILITY_CREDENTIAL, 1), now.AddDays(5), false)); ConfigureHttpClientFactoryFixture(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonSerializer.Serialize(didDocument)) - }, requestMessage => request = requestMessage); + }); // Act await _sut.CreateFrameworkCredential(data, CancellationToken.None);