Skip to content

Commit 67c71d5

Browse files
authored
fix and update test (#52)
1 parent a6d4c26 commit 67c71d5

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

nifi-tdf-processors/src/test/java/io/opentdf/nifi/ConvertFromZTDFTest.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.opentdf.nifi;
22

3+
import com.nimbusds.jose.JOSEException;
4+
import io.opentdf.platform.policy.kasregistry.KeyAccessServerRegistryServiceGrpc;
35
import io.opentdf.platform.sdk.*;
6+
import io.opentdf.platform.sdk.Config;
47
import io.opentdf.platform.sdk.TDF.Reader;
58
import nl.altindag.ssl.util.KeyStoreUtils;
9+
import org.apache.commons.codec.DecoderException;
610
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
711
import org.apache.nifi.ssl.SSLContextService;
812
import org.apache.nifi.util.MockFlowFile;
@@ -14,11 +18,17 @@
1418

1519
import java.io.File;
1620
import java.io.FileOutputStream;
21+
import java.io.IOException;
1722
import java.io.OutputStream;
23+
import java.lang.reflect.Field;
24+
import java.net.URISyntaxException;
1825
import java.nio.ByteBuffer;
1926
import java.nio.channels.SeekableByteChannel;
2027
import java.nio.file.Files;
28+
import java.security.NoSuchAlgorithmException;
29+
import java.text.ParseException;
2130
import java.util.*;
31+
import java.util.concurrent.ExecutionException;
2232
import java.util.concurrent.atomic.AtomicInteger;
2333

2434
import static org.junit.jupiter.api.Assertions.*;
@@ -63,18 +73,24 @@ void testConvertFromTDF() throws Exception {
6373

6474

6575
runner.assertValid();
66-
76+
String platformEndpoint = "http://platform";
6777
SDK.Services mockServices = mock(SDK.Services.class);
6878
SDK.KAS mockKAS = mock(SDK.KAS.class);
6979
when(mockSDK.getServices()).thenReturn(mockServices);
7080
when(mockServices.kas()).thenReturn(mockKAS);
71-
when(mockSDKBuilder.platformEndpoint("http://platform")).thenReturn(mockSDKBuilder);
81+
when(mockSDK.getPlatformUrl()).thenReturn(platformEndpoint);
82+
when(mockSDKBuilder.platformEndpoint(platformEndpoint)).thenReturn(mockSDKBuilder);
7283
when(mockSDKBuilder.clientSecret("my-client", "123-456")).thenReturn(mockSDKBuilder);
7384
when(mockSDKBuilder.sslFactoryFromKeyStore(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)).thenReturn(mockSDKBuilder);
7485
when(mockSDKBuilder.build()).thenReturn(mockSDK);
7586

7687
ArgumentCaptor<SeekableByteChannel> seekableByteChannelArgumentCaptor = ArgumentCaptor.forClass(SeekableByteChannel.class);
7788
ArgumentCaptor<SDK.KAS> kasArgumentCaptor = ArgumentCaptor.forClass(SDK.KAS.class);
89+
ArgumentCaptor<Config.TDFReaderConfig> tdfReaderConfigArgumentCaptor = ArgumentCaptor.forClass(Config.TDFReaderConfig.class);
90+
ArgumentCaptor<KeyAccessServerRegistryServiceGrpc.KeyAccessServerRegistryServiceFutureStub> keyAccessServerRegistryServiceGrpcArgumentCaptor =
91+
ArgumentCaptor.forClass(KeyAccessServerRegistryServiceGrpc.KeyAccessServerRegistryServiceFutureStub.class);
92+
ArgumentCaptor<String> platformUrlCaptor = ArgumentCaptor.forClass(String.class);
93+
7894
Reader mockReader = mock(Reader.class);
7995

8096
ArgumentCaptor<OutputStream> outputStreamArgumentCaptor = ArgumentCaptor.forClass(OutputStream.class);
@@ -96,7 +112,10 @@ void testConvertFromTDF() throws Exception {
96112
assertSame(mockKAS, kas, "Expected KAS passed in");
97113
return mockReader;
98114
}).when(mockTDF).loadTDF(seekableByteChannelArgumentCaptor.capture(),
99-
kasArgumentCaptor.capture()
115+
kasArgumentCaptor.capture(),
116+
tdfReaderConfigArgumentCaptor.capture(),
117+
keyAccessServerRegistryServiceGrpcArgumentCaptor.capture(),
118+
platformUrlCaptor.capture()
100119
);
101120
MockFlowFile messageOne = runner.enqueue("message one".getBytes());
102121
MockFlowFile messageTwo = runner.enqueue("message two".getBytes());
@@ -112,6 +131,13 @@ void testConvertFromTDF() throws Exception {
112131

113132
assertTrue(messages.contains("message one"));
114133
assertTrue(messages.contains("message two"));
134+
135+
assertEquals(platformEndpoint, platformUrlCaptor.getValue());
136+
// disableAssertionVerification is a private field
137+
Field field = Config.TDFReaderConfig.class.getDeclaredField("disableAssertionVerification");
138+
field.setAccessible(true);
139+
boolean disableAssertionVerification = (boolean) field.get(tdfReaderConfigArgumentCaptor.getValue());
140+
assertTrue(disableAssertionVerification);
115141
}
116142

117143
public static class MockRunner extends ConvertFromZTDF {

nifi-tdf-processors/src/test/java/io/opentdf/nifi/ConvertToZTDFTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.opentdf.platform.policy.attributes.AttributesServiceGrpc;
55
import io.opentdf.platform.sdk.*;
66
import io.opentdf.platform.sdk.Config;
7+
import org.apache.commons.codec.DecoderException;
78
import org.apache.commons.io.IOUtils;
89
import org.apache.nifi.key.service.api.PrivateKeyService;
910
import org.apache.nifi.processor.ProcessContext;
@@ -146,7 +147,7 @@ void testToTDF_WithAssertionsOn_And_Assertions_Provided() throws Exception {
146147
assertEquals(1, flowFileList.size(), "one success flow file");
147148
}
148149

149-
private Captures commonProcessorTestSetup(TestRunner runner) throws IOException, JOSEException, ExecutionException, InterruptedException {
150+
private Captures commonProcessorTestSetup(TestRunner runner) throws IOException, JOSEException, ExecutionException, InterruptedException, DecoderException {
150151
((ConvertToZTDFTest.MockRunner) runner.getProcessor()).mockSDK = mockSDK;
151152
((ConvertToZTDFTest.MockRunner) runner.getProcessor()).mockTDF = mockTDF;
152153
runner.setProperty(ConvertToZTDF.KAS_URL, "https://kas1");

0 commit comments

Comments
 (0)