Skip to content

Commit 7bdb68b

Browse files
committed
Make tests less opinionated, move Vaildation to ClientMetadata Model
Signed-off-by: Johannes Tuerk <johannes.tuerk@lissi.id>
1 parent 5fb9dda commit 7bdb68b

File tree

5 files changed

+46
-45
lines changed

5 files changed

+46
-45
lines changed

src/WalletFramework.Oid4Vc/Oid4Vp/Models/ClientMetadata.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using LanguageExt;
22
using Newtonsoft.Json;
33
using OneOf;
4+
using WalletFramework.Core.Functional;
45
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.Models;
6+
using WalletFramework.Oid4Vc.Oid4Vp.Errors;
57
using WalletFramework.Oid4Vc.Oid4Vp.Jwk;
68
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Models;
79

@@ -124,7 +126,7 @@ public ClientMetadata(
124126

125127
public static class ClientMetadataExtensions
126128
{
127-
public static bool IsVpFormatsSupported(this ClientMetadata clientMetadata, OneOf<DcqlQuery, PresentationDefinition> requirements)
129+
public static Validation<AuthorizationRequestCancellation, Option<ClientMetadata>> VpFormatsSupportedValidation(this ClientMetadata clientMetadata, OneOf<DcqlQuery, PresentationDefinition> requirements, Option<Uri> responseUri)
128130
{
129131
return requirements.Match(
130132
dcql =>
@@ -137,14 +139,19 @@ public static bool IsVpFormatsSupported(this ClientMetadata clientMetadata, OneO
137139

138140
return (sdJwtRequested, mdocRequested) switch
139141
{
140-
(true, false) => IsSdJwtVpFormatSupported(clientMetadata, walletMetadata),
141-
(false, true) => IsMdocVpFormatSupported(clientMetadata, walletMetadata),
142-
(true, true) => IsSdJwtVpFormatSupported(clientMetadata, walletMetadata) &&
143-
IsMdocVpFormatSupported(clientMetadata, walletMetadata),
144-
_ => true
142+
(true, false) => IsSdJwtVpFormatSupported(clientMetadata, walletMetadata)
143+
? clientMetadata.AsOption()
144+
: (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) GetVpFormatsNotSupportedCancellation(responseUri),
145+
(false, true) => IsMdocVpFormatSupported(clientMetadata, walletMetadata)
146+
? clientMetadata.AsOption()
147+
: (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) GetVpFormatsNotSupportedCancellation(responseUri),
148+
(true, true) => IsSdJwtVpFormatSupported(clientMetadata, walletMetadata) && IsMdocVpFormatSupported(clientMetadata, walletMetadata)
149+
? clientMetadata.AsOption()
150+
: (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) GetVpFormatsNotSupportedCancellation(responseUri),
151+
_ => clientMetadata.AsOption()
145152
};
146153
},
147-
_ => true);
154+
_ => clientMetadata.AsOption());
148155
}
149156

150157
private static bool IsMdocVpFormatSupported(ClientMetadata clientMetadata, WalletMetadata walletMetadata)
@@ -196,4 +203,10 @@ private static bool IsSdJwtVpFormatSupported(ClientMetadata clientMetadata, Wall
196203

197204
return true;
198205
}
206+
207+
private static AuthorizationRequestCancellation GetVpFormatsNotSupportedCancellation(Option<Uri> responseUri)
208+
{
209+
var error = new VpFormatsNotSupportedError("The provided vp_formats_supported values are not supported");
210+
return new AuthorizationRequestCancellation(responseUri, [error]);
211+
}
199212
}

src/WalletFramework.Oid4Vc/Oid4Vp/Services/AuthorizationRequestService.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,7 @@ private async Task<Validation<AuthorizationRequestCancellation, RequestObject>>
187187
private async Task<Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>> FetchClientMetadata(AuthorizationRequest authorizationRequest)
188188
{
189189
return await authorizationRequest.ClientMetadata.AsOption().Match(
190-
clientMetadata =>
191-
{
192-
if (clientMetadata.IsVpFormatsSupported(authorizationRequest.Requirements))
193-
{
194-
var error = new VpFormatsNotSupportedError("The provided vp_formats_supported values are not supported");
195-
var authorizationCancellation = new AuthorizationRequestCancellation(authorizationRequest.GetResponseUriMaybe(), [error]);
196-
return Task.FromResult((Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) authorizationCancellation);
197-
}
198-
199-
return Task.FromResult<Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>>(clientMetadata.AsOption());
200-
},
190+
clientMetadata => Task.FromResult(clientMetadata.VpFormatsSupportedValidation(authorizationRequest.Requirements, authorizationRequest.GetResponseUriMaybe())),
201191
async () =>
202192
{
203193
if (string.IsNullOrWhiteSpace(authorizationRequest.ClientMetadataUri))
@@ -214,14 +204,7 @@ private async Task<Validation<AuthorizationRequestCancellation, Option<ClientMet
214204
if (clientMetadata == null)
215205
return Option<ClientMetadata>.None;
216206

217-
if (clientMetadata.IsVpFormatsSupported(authorizationRequest.Requirements))
218-
{
219-
var error = new VpFormatsNotSupportedError("The provided vp_formats_supported values are not supported");
220-
var authorizationCancellation = new AuthorizationRequestCancellation(authorizationRequest.GetResponseUriMaybe(), [error]);
221-
return (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) authorizationCancellation;
222-
}
223-
224-
return clientMetadata.AsOption();
207+
return clientMetadata.VpFormatsSupportedValidation(authorizationRequest.Requirements, authorizationRequest.GetResponseUriMaybe());
225208
});
226209
}
227210
}

test/WalletFramework.Oid4Vc.Tests/Oid4Vp/AuthRequest/ClientMetadataTests.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FluentAssertions;
2+
using LanguageExt;
23
using WalletFramework.Core.Functional;
34
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.CredentialQueries;
45
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.Models;
@@ -26,10 +27,10 @@ public void IsVpFormatsSupported_WithDcqlQueryAndMissingVpFormats_ShouldReturnTr
2627
};
2728

2829
// Act
29-
var result = clientMetadata.IsVpFormatsSupported(dcqlQuery);
30+
var result = clientMetadata.VpFormatsSupportedValidation(dcqlQuery, Option<Uri>.None);
3031

3132
// Assert
32-
result.Should().BeTrue();
33+
result.IsSuccess.Should().BeTrue();
3334
}
3435

3536
[Fact]
@@ -69,10 +70,10 @@ public void IsVpFormatsSupported_UsingSdJwt_WithSupportedVpFormats_ShouldSucceed
6970
};
7071

7172
// Act
72-
var result = clientMetadata.IsVpFormatsSupported(dcqlQuery);
73+
var result = clientMetadata.VpFormatsSupportedValidation(dcqlQuery, Option<Uri>.None);
7374

7475
// Assert
75-
result.Should().BeTrue();
76+
result.IsSuccess.Should().BeTrue();
7677
}
7778

7879
[Fact]
@@ -104,10 +105,10 @@ public void IsVpFormatsSupported_UsingMDoc_WithSupportedVpFormats_ShouldSucceed(
104105
};
105106

106107
// Act
107-
var result = clientMetadata.IsVpFormatsSupported(dcqlQuery);
108+
var result = clientMetadata.VpFormatsSupportedValidation(dcqlQuery, Option<Uri>.None);
108109

109110
// Assert
110-
result.Should().BeTrue();
111+
result.IsSuccess.Should().BeTrue();
111112
}
112113

113114
[Fact]
@@ -149,10 +150,10 @@ public void IsVpFormatsSupported_UsingSdJwtAndMDoc_WithSupportedVpFormats_Should
149150
};
150151

151152
// Act
152-
var result = clientMetadata.IsVpFormatsSupported(dcqlQuery);
153+
var result = clientMetadata.VpFormatsSupportedValidation(dcqlQuery, Option<Uri>.None);
153154

154155
// Assert
155-
result.Should().BeTrue();
156+
result.IsSuccess.Should().BeTrue();
156157
}
157158

158159
[Fact]
@@ -184,10 +185,10 @@ public void IsVpFormatsSupported_UsingSdJwt_WithOnlyUnsupportedAlgorithms_Should
184185
};
185186

186187
// Act
187-
var result = clientMetadata.IsVpFormatsSupported(dcqlQuery);
188+
var result = clientMetadata.VpFormatsSupportedValidation(dcqlQuery, Option<Uri>.None);
188189

189190
// Assert
190-
result.Should().BeFalse();
191+
result.IsSuccess.Should().BeFalse();
191192
}
192193

193194
[Fact]
@@ -219,10 +220,10 @@ public void IsVpFormatsSupported_UsingMDoc_WithOnlyUnsupportedAlgorithms_ShouldF
219220
};
220221

221222
// Act
222-
var result = clientMetadata.IsVpFormatsSupported(dcqlQuery);
223+
var result = clientMetadata.VpFormatsSupportedValidation(dcqlQuery, Option<Uri>.None);
223224

224225
// Assert
225-
result.Should().BeFalse();
226+
result.IsSuccess.Should().BeFalse();
226227
}
227228

228229
private static ClientMetadata CreateClientMetadata() =>

test/WalletFramework.Oid4Vc.Tests/Oid4Vp/AuthRequest/Models/Can_Parse_Authorization_Request_With_Attachments.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
]
3232
},
3333
"client_metadata": {
34-
"vp_formats": {
34+
"vp_formats_supported": {
3535
"mso_mdoc": {
36-
"alg": [
37-
"EdDSA",
38-
"ES256",
39-
"ES384"
36+
"issuerauth_alg_values": [
37+
"-7",
38+
"-9",
39+
"-200"
40+
],
41+
"deviceauth_alg_values": [
42+
"-7"
4043
]
4144
},
4245
"vc+sd-jwt": {

test/WalletFramework.Oid4Vc.Tests/Oid4Vp/AuthRequest/Models/Can_Parse_Authorization_Request_Without_Attachments.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
} ]
2020
},
2121
"client_metadata" : {
22-
"vp_formats" : {
22+
"vp_formats_supported" : {
2323
"mso_mdoc" : {
24-
"alg" : [ "EdDSA", "ES256", "ES384" ]
24+
"issuerauth_alg_values": ["-7", "-9", "-200"],
25+
"deviceauth_alg_values": ["-7"]
2526
},
2627
"vc+sd-jwt" : {
2728
"kb-jwt_alg_values" : [ "EdDSA", "ES256", "ES384", "ES256K" ],

0 commit comments

Comments
 (0)