NIFI-6727 Fixed the MockProcessContext decrypt bug and added unit test.

This closes #3773.

Signed-off-by: Andy LoPresto <alopresto@apache.org>
This commit is contained in:
Alessandro D'Armiento 2019-09-28 10:11:23 +02:00 committed by Andy LoPresto
parent 8abf330328
commit 39a258dc38
No known key found for this signature in database
GPG Key ID: 6EC293152D90B61D
3 changed files with 13 additions and 2 deletions

View File

@ -399,7 +399,7 @@ public class MockProcessContext extends MockControllerServiceLookup implements P
@Override
public String decrypt(final String encrypted) {
if (encrypted.startsWith("enc{") && encrypted.endsWith("}")) {
return encrypted.substring(4, encrypted.length() - 2);
return encrypted.substring(4, encrypted.length() - 1);
}
return encrypted;
}

View File

@ -75,6 +75,17 @@ public class TestMockProcessContext {
assertEquals(2, proc.getUpdateCount(DummyProcessor.DEFAULTED_PROP));
}
@Test
public void testFakeEncryptionAndDecryption() {
final DummyProcessor proc = new DummyProcessor();
final MockProcessContext context = new MockProcessContext(proc);
String subject = "foo";
String encrypted = context.encrypt(subject);
assertEquals(encrypted, "enc{foo}");
String decrypted = context.decrypt(encrypted);
assertEquals(decrypted, subject);
}
private static class DummyProcessor extends AbstractProcessor {
static final PropertyDescriptor REQUIRED_PROP = new PropertyDescriptor.Builder()
.name("required")

View File

@ -172,7 +172,7 @@
<root level="INFO">
<appender-ref ref="APP_FILE"/>
<appender-ref ref="APP_FILE"/>MockProcessContext
</root>
</configuration>