Skip to content

Commit 1d9c92a

Browse files
- Fixing bug where encryption key couldn't be added without decryption key
1 parent 2a186f6 commit 1d9c92a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
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: 14 additions & 0 deletions
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()

0 commit comments

Comments
 (0)