1
1
package io .opentdf .nifi ;
2
2
3
+ import com .nimbusds .jose .JOSEException ;
4
+ import io .opentdf .platform .policy .kasregistry .KeyAccessServerRegistryServiceGrpc ;
3
5
import io .opentdf .platform .sdk .*;
6
+ import io .opentdf .platform .sdk .Config ;
4
7
import io .opentdf .platform .sdk .TDF .Reader ;
5
8
import nl .altindag .ssl .util .KeyStoreUtils ;
9
+ import org .apache .commons .codec .DecoderException ;
6
10
import org .apache .commons .compress .utils .SeekableInMemoryByteChannel ;
7
11
import org .apache .nifi .ssl .SSLContextService ;
8
12
import org .apache .nifi .util .MockFlowFile ;
14
18
15
19
import java .io .File ;
16
20
import java .io .FileOutputStream ;
21
+ import java .io .IOException ;
17
22
import java .io .OutputStream ;
23
+ import java .lang .reflect .Field ;
24
+ import java .net .URISyntaxException ;
18
25
import java .nio .ByteBuffer ;
19
26
import java .nio .channels .SeekableByteChannel ;
20
27
import java .nio .file .Files ;
28
+ import java .security .NoSuchAlgorithmException ;
29
+ import java .text .ParseException ;
21
30
import java .util .*;
31
+ import java .util .concurrent .ExecutionException ;
22
32
import java .util .concurrent .atomic .AtomicInteger ;
23
33
24
34
import static org .junit .jupiter .api .Assertions .*;
@@ -63,18 +73,24 @@ void testConvertFromTDF() throws Exception {
63
73
64
74
65
75
runner .assertValid ();
66
-
76
+ String platformEndpoint = "http://platform" ;
67
77
SDK .Services mockServices = mock (SDK .Services .class );
68
78
SDK .KAS mockKAS = mock (SDK .KAS .class );
69
79
when (mockSDK .getServices ()).thenReturn (mockServices );
70
80
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 );
72
83
when (mockSDKBuilder .clientSecret ("my-client" , "123-456" )).thenReturn (mockSDKBuilder );
73
84
when (mockSDKBuilder .sslFactoryFromKeyStore (TRUST_STORE_PATH , TRUST_STORE_PASSWORD )).thenReturn (mockSDKBuilder );
74
85
when (mockSDKBuilder .build ()).thenReturn (mockSDK );
75
86
76
87
ArgumentCaptor <SeekableByteChannel > seekableByteChannelArgumentCaptor = ArgumentCaptor .forClass (SeekableByteChannel .class );
77
88
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
+
78
94
Reader mockReader = mock (Reader .class );
79
95
80
96
ArgumentCaptor <OutputStream > outputStreamArgumentCaptor = ArgumentCaptor .forClass (OutputStream .class );
@@ -96,7 +112,10 @@ void testConvertFromTDF() throws Exception {
96
112
assertSame (mockKAS , kas , "Expected KAS passed in" );
97
113
return mockReader ;
98
114
}).when (mockTDF ).loadTDF (seekableByteChannelArgumentCaptor .capture (),
99
- kasArgumentCaptor .capture ()
115
+ kasArgumentCaptor .capture (),
116
+ tdfReaderConfigArgumentCaptor .capture (),
117
+ keyAccessServerRegistryServiceGrpcArgumentCaptor .capture (),
118
+ platformUrlCaptor .capture ()
100
119
);
101
120
MockFlowFile messageOne = runner .enqueue ("message one" .getBytes ());
102
121
MockFlowFile messageTwo = runner .enqueue ("message two" .getBytes ());
@@ -112,6 +131,13 @@ void testConvertFromTDF() throws Exception {
112
131
113
132
assertTrue (messages .contains ("message one" ));
114
133
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 );
115
141
}
116
142
117
143
public static class MockRunner extends ConvertFromZTDF {
0 commit comments