25
25
import org .junit .experimental .runners .Enclosed ;
26
26
import org .junit .runner .RunWith ;
27
27
import org .keycloak .common .util .MultivaluedHashMap ;
28
+ import org .keycloak .jose .jwe .JWEConstants ;
29
+ import org .keycloak .models .KeycloakSession ;
28
30
import org .keycloak .models .RealmModel ;
29
31
import org .keycloak .protocol .oid4vc .issuance .OID4VCIssuerWellKnownProvider ;
30
32
import org .keycloak .protocol .oid4vc .issuance .OID4VCIssuerWellKnownProviderFactory ;
31
33
import org .keycloak .protocol .oid4vc .model .CredentialIssuer ;
32
- import org .keycloak .protocol .oid4vc .model .CredentialResponseEncryption ;
33
34
import org .keycloak .protocol .oid4vc .model .CredentialResponseEncryptionMetadata ;
34
35
import org .keycloak .protocol .oid4vc .model .Format ;
35
36
import org .keycloak .representations .idm .ClientRepresentation ;
@@ -83,77 +84,48 @@ public void configureTestRealm(RealmRepresentation testRealm) {
83
84
84
85
}
85
86
86
- public static class TestCredentialDefinitionInClientAttributes extends OID4VCTest {
87
-
88
- @ Test
89
- public void testCredentialConfig () {
90
- OID4VCIssuerWellKnownProviderTest
91
- .testCredentialConfig (suiteContext , testingClient );
92
- }
87
+ public static class TestCredentialIssuerMetadataFields extends OID4VCTest {
93
88
94
89
@ Test
95
90
public void testCredentialIssuerMetadataFields () {
96
- String expectedIssuer = suiteContext .getAuthServerInfo ().getContextRoot ().toString () + "/auth/realms/" + TEST_REALM_NAME ;
97
91
KeycloakTestingClient testingClient = this .testingClient ;
98
92
99
93
testingClient
100
94
.server (TEST_REALM_NAME )
101
95
.run (session -> {
102
- // Setup test realm attributes
103
- RealmModel realm = session .getContext ().getRealm ();
104
- realm .setAttribute ("oid4vci.encryption.algs" , "RSA-OAEP" );
105
- realm .setAttribute ("oid4vci.encryption.encs" , "A256GCM" );
106
- realm .setAttribute ("oid4vci.encryption.required" , "true" );
107
- realm .setAttribute ("batch_credential_issuance.batch_size" , "10" );
108
- realm .setAttribute ("signed_metadata" , "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.XYZ123abc" );
109
-
110
- OID4VCIssuerWellKnownProvider provider = new OID4VCIssuerWellKnownProvider (session );
111
- Object config = provider .getConfig ();
112
- assertTrue ("Should return CredentialIssuer" , config instanceof CredentialIssuer );
113
- CredentialIssuer issuer = (CredentialIssuer ) config ;
114
-
115
- // Check basic endpoints
116
- assertEquals (expectedIssuer , issuer .getCredentialIssuer ());
117
- assertNotNull (issuer .getCredentialEndpoint ());
118
- assertNotNull (issuer .getNonceEndpoint ());
119
- assertNotNull (issuer .getDeferredCredentialEndpoint ());
120
- assertEquals (List .of (expectedIssuer ), issuer .getAuthorizationServers ());
121
-
122
- // Check credential_response_encryption
96
+ CredentialIssuer issuer = getCredentialIssuer (session );
97
+
123
98
CredentialResponseEncryptionMetadata encryption = issuer .getCredentialResponseEncryption ();
124
- assertNotNull ("credential_response_encryption should be present" , encryption );
125
- assertEquals (List .of ("RSA-OAEP" ), encryption .getAlgValuesSupported ());
126
- assertEquals (List .of ("A256GCM" ), encryption .getEncValuesSupported ());
127
- assertTrue ("encryption_required should be true" , encryption .getEncryptionRequired ());
128
-
129
- // Check batch_credential_issuance
130
- CredentialIssuer .BatchCredentialIssuance batch = issuer .getBatchCredentialIssuance ();
131
- assertNotNull ("batch_credential_issuance should be present" , batch );
132
- assertEquals (Integer .valueOf (10 ), batch .getBatchSize ());
133
-
134
- // Check signed_metadata
135
- assertEquals (
136
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.XYZ123abc" ,
137
- issuer .getSignedMetadata ()
138
- );
139
-
140
- // Check credentials_supported is not empty
141
- assertNotNull (issuer .getCredentialsSupported ());
142
- assertFalse (issuer .getCredentialsSupported ().isEmpty ());
99
+ assertNotNull (encryption );
100
+
101
+ assertTrue (encryption .getAlgValuesSupported ().contains ("RSA-OAEP" ));
102
+ assertTrue ("Supported encryption methods should include A256GCM" , encryption .getEncValuesSupported ().contains (JWEConstants .A256GCM ));
103
+ assertTrue (encryption .getEncryptionRequired ());
104
+ assertEquals (Integer .valueOf (10 ), issuer .getBatchCredentialIssuance ().getBatchSize ());
105
+ assertEquals ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.XYZ123abc" ,
106
+ issuer .getSignedMetadata ());
143
107
});
144
108
}
145
109
110
+ private static CredentialIssuer getCredentialIssuer (KeycloakSession session ) {
111
+ RealmModel realm = session .getContext ().getRealm ();
112
+
113
+ realm .setAttribute ("oid4vci.encryption.required" , "true" );
114
+ realm .setAttribute ("batch_credential_issuance.batch_size" , "10" );
115
+ realm .setAttribute ("signed_metadata" , "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.XYZ123abc" );
116
+
117
+ OID4VCIssuerWellKnownProvider provider = new OID4VCIssuerWellKnownProvider (session );
118
+ return (CredentialIssuer ) provider .getConfig ();
119
+ }
120
+
146
121
@ Override
147
122
public void configureTestRealm (RealmRepresentation testRealm ) {
148
- Map <String , String > clientAttributes = new HashMap <>(getTestCredentialDefinitionAttributes ());
149
- Map <String , String > realmAttributes = new HashMap <>();
150
- OID4VCIssuerWellKnownProviderTest
151
- .configureTestRealm (
152
- getTestClient ("did:web:test.org" ),
153
- testRealm ,
154
- clientAttributes ,
155
- realmAttributes
156
- );
123
+ Map <String , String > attributes = new HashMap <>();
124
+ attributes .put ("oid4vci.encryption.required" , "true" );
125
+ attributes .put ("batch_credential_issuance.batch_size" , "10" );
126
+ attributes .put ("signed_metadata" , "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.XYZ123abc" );
127
+ testRealm .setAttributes (attributes );
128
+
157
129
}
158
130
}
159
131
@@ -184,11 +156,6 @@ public static void configureTestRealm(
184
156
Map <String , String > clientAttributes ,
185
157
Map <String , String > realmAttributes
186
158
) {
187
- realmAttributes .put ("credential_response_encryption.alg_values_supported" , "[\" RSA-OAEP\" ]" );
188
- realmAttributes .put ("credential_response_encryption.enc_values_supported" , "[\" A256GCM\" ]" );
189
- realmAttributes .put ("credential_response_encryption.encryption_required" , "true" );
190
- realmAttributes .put ("batch_credential_issuance.batch_size" , "10" );
191
- realmAttributes .put ("signed_metadata" , "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIifQ.XYZ123abc" ); // example JWT
192
159
testClient .setAttributes (new HashMap <>(clientAttributes ));
193
160
testRealm .setAttributes (new HashMap <>(realmAttributes ));
194
161
extendConfigureTestRealm (testRealm , testClient );
@@ -214,16 +181,18 @@ public void testIssuerMetadataIncludesEncryptionSupport() throws IOException {
214
181
oid4vciIssuerConfig .getCredentialResponseEncryption ().getAlgValuesSupported ().isEmpty ());
215
182
assertFalse ("Supported encryption methods should not be empty" ,
216
183
oid4vciIssuerConfig .getCredentialResponseEncryption ().getEncValuesSupported ().isEmpty ());
184
+ assertTrue ("Supported algorithms should include RSA-OAEP" ,
185
+ oid4vciIssuerConfig .getCredentialResponseEncryption ().getAlgValuesSupported ().contains (JWEConstants .RSA_OAEP ));
186
+ assertTrue ("Supported encryption methods should include A256GCM" ,
187
+ oid4vciIssuerConfig .getCredentialResponseEncryption ().getEncValuesSupported ().contains (JWEConstants .A256GCM ));
217
188
}
218
189
}
219
190
}
220
191
221
192
@ Override
222
193
public void configureTestRealm (RealmRepresentation testRealm ) {
223
- // Configure realm with encryption support if needed
224
194
Map <String , String > realmAttributes = new HashMap <>();
225
- realmAttributes .put ("oid4vci.encryption.algs" , "RSA-OAEP,RSA-OAEP-256" );
226
- realmAttributes .put ("oid4vci.encryption.encs" , "A256GCM,A128CBC-HS256" );
195
+ realmAttributes .put ("oid4vci.encryption.required" , "true" );
227
196
testRealm .setAttributes (realmAttributes );
228
197
229
198
extendConfigureTestRealm (testRealm , getTestClient ("did:web:test.org" ));
0 commit comments