Skip to content

Commit 7c7e10f

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 81f377d + f24d054 commit 7c7e10f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/main/java/com/mastercard/developer/encryption/JweConfigBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public JweConfigBuilder withEncryptionKeyFingerprint(String encryptionKeyFingerp
9494
this.encryptionKeyFingerprint = encryptionKeyFingerprint;
9595
return this;
9696
}
97-
97+
9898
private void checkParameterValues() {
99-
if (decryptionKey == null && encryptionCertificate == null) {
100-
throw new IllegalArgumentException("You must include at least an encryption certificate or a decryption key");
99+
if (decryptionKey == null && encryptionCertificate == null && encryptionKey == null) {
100+
throw new IllegalArgumentException("You must include at least an encryption key/certificate or a decryption key");
101101
}
102102
}
103103
}

src/test/java/com/mastercard/developer/encryption/JweConfigBuilderTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ public void testBuild_Nominal() throws Exception {
3131
Assert.assertEquals(Collections.singletonMap("$", "$"), config.getEncryptionPaths());
3232
}
3333

34+
@Test
35+
public void testBuild_EncryptionKeyNoDecryptionKey() throws Exception {
36+
JweConfig config = JweConfigBuilder.aJweEncryptionConfig()
37+
.withEncryptionKey(TestUtils.getTestEncryptionCertificate().getPublicKey())
38+
.withEncryptionPath("$", "$")
39+
.withEncryptedValueFieldName("encryptedPayload")
40+
.build();
41+
Assert.assertNotNull(config);
42+
Assert.assertEquals(EncryptionConfig.Scheme.JWE, config.getScheme());
43+
Assert.assertEquals(TestUtils.getTestEncryptionCertificate().getPublicKey(), config.getEncryptionKey());
44+
Assert.assertEquals("encryptedPayload", config.getEncryptedValueFieldName());
45+
Assert.assertEquals(Collections.singletonMap("$", "$"), config.getEncryptionPaths());
46+
}
47+
3448
@Test
3549
public void testBuild_EncryptionKeyFromCertificate() throws Exception {
3650
EncryptionConfig config = JweConfigBuilder.aJweEncryptionConfig()
@@ -102,7 +116,7 @@ public void testBuild_ShouldFallbackToDefaults() throws Exception {
102116
@Test
103117
public void testBuild_ShouldThrowIllegalArgumentException_WhenMissingDecryptionKey() throws Exception {
104118
expectedException.expect(IllegalArgumentException.class);
105-
expectedException.expectMessage("You must include at least an encryption certificate or a decryption key");
119+
expectedException.expectMessage("You must include at least an encryption key/certificate or a decryption key");
106120
JweConfigBuilder.aJweEncryptionConfig()
107121
.build();
108122
}

0 commit comments

Comments
 (0)