From e466fa3390b68cc7a51f0aff2be53486a5d6d668 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Wed, 2 Oct 2024 19:58:48 +0200 Subject: [PATCH] fix: adjust create credential request structure (#266) Refs: #265 Reviewed-By: Evelyn Gurschler --- .../Wallet.Service/Models/CreateCredentialResponse.cs | 8 ++++++-- .../Wallet.Service/Services/WalletService.cs | 2 +- .../Wallet.Service.Tests/Services/WalletServiceTests.cs | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/externalservices/Wallet.Service/Models/CreateCredentialResponse.cs b/src/externalservices/Wallet.Service/Models/CreateCredentialResponse.cs index d090f50..7d214cd 100644 --- a/src/externalservices/Wallet.Service/Models/CreateCredentialResponse.cs +++ b/src/externalservices/Wallet.Service/Models/CreateCredentialResponse.cs @@ -24,11 +24,15 @@ namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Wallet.Service.Models; public record CreateSignedCredentialRequest( [property: JsonPropertyName("application")] string Application, - [property: JsonPropertyName("payload")] CreateSignedPayload Payload + [property: JsonPropertyName("payload")] IssueWithSignature Issue +); + +public record IssueWithSignature( + [property: JsonPropertyName("issueWithSignature")] CreateSignedPayload Payload ); public record CreateSignedPayload( - [property: JsonPropertyName("content")] JsonDocument Issue, + [property: JsonPropertyName("content")] JsonDocument Content, [property: JsonPropertyName("signature")] SignData Signature ); diff --git a/src/externalservices/Wallet.Service/Services/WalletService.cs b/src/externalservices/Wallet.Service/Services/WalletService.cs index 7fa1c41..fb1486d 100644 --- a/src/externalservices/Wallet.Service/Services/WalletService.cs +++ b/src/externalservices/Wallet.Service/Services/WalletService.cs @@ -41,7 +41,7 @@ public class WalletService( public async Task CreateSignedCredential(JsonDocument payload, CancellationToken cancellationToken) { using var client = await basicAuthTokenService.GetBasicAuthorizedClient(_settings, cancellationToken); - var data = new CreateSignedCredentialRequest(_settings.WalletApplication, new CreateSignedPayload(payload, new SignData("external", "jwt", null))); + var data = new CreateSignedCredentialRequest(_settings.WalletApplication, new IssueWithSignature(new CreateSignedPayload(payload, new SignData("external", "jwt", null)))); var result = await client.PostAsJsonAsync(_settings.CreateSignedCredentialPath, data, Options, cancellationToken) .CatchingIntoServiceExceptionFor("create-credential", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE, async x => (false, await x.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None))) diff --git a/tests/externalservices/Wallet.Service.Tests/Services/WalletServiceTests.cs b/tests/externalservices/Wallet.Service.Tests/Services/WalletServiceTests.cs index c05402d..c774ee9 100644 --- a/tests/externalservices/Wallet.Service.Tests/Services/WalletServiceTests.cs +++ b/tests/externalservices/Wallet.Service.Tests/Services/WalletServiceTests.cs @@ -73,10 +73,10 @@ public async Task CreateCredential_WithValid_DoesNotThrowException() x.Content is JsonContent && (x.Content as JsonContent)!.ObjectType == typeof(CreateSignedCredentialRequest) && ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Application == "catena-x-portal" && - ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Payload.Signature.ProofMechanism == "external" && - ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Payload.Signature.ProofType == "jwt" && - ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Payload.Signature.KeyName == null && - ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Payload.Issue == payload + ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Issue.Payload.Signature.ProofMechanism == "external" && + ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Issue.Payload.Signature.ProofType == "jwt" && + ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Issue.Payload.Signature.KeyName == null && + ((x.Content as JsonContent)!.Value as CreateSignedCredentialRequest)!.Issue.Payload.Content == payload ); result.Should().BeOfType().Which.Id.Should().Be(id); }