17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
19
import static org .mockito .ArgumentMatchers .any ;
20
- import static software .amazon .awssdk .core .HttpChecksumConstant .HTTP_CHECKSUM_VALUE ;
21
20
22
21
import io .reactivex .Flowable ;
23
22
import java .io .IOException ;
28
27
import java .util .Set ;
29
28
import java .util .concurrent .CompletableFuture ;
30
29
import java .util .stream .Collectors ;
31
- import org .junit .After ;
32
30
import org .junit .Before ;
33
31
import org .junit .Test ;
34
32
import org .mockito .ArgumentCaptor ;
38
36
import software .amazon .awssdk .awscore .client .builder .AwsClientBuilder ;
39
37
import software .amazon .awssdk .awscore .client .builder .AwsSyncClientBuilder ;
40
38
import software .amazon .awssdk .core .checksums .Algorithm ;
41
- import software .amazon .awssdk .core .interceptor .Context ;
42
- import software .amazon .awssdk .core .interceptor .ExecutionAttributes ;
43
- import software .amazon .awssdk .core .interceptor .ExecutionInterceptor ;
44
39
import software .amazon .awssdk .http .ExecutableHttpRequest ;
45
40
import software .amazon .awssdk .http .HttpExecuteRequest ;
46
41
import software .amazon .awssdk .http .HttpExecuteResponse ;
@@ -103,11 +98,6 @@ public void setup() throws IOException {
103
98
});
104
99
}
105
100
106
- @ After
107
- public void clear () {
108
- CaptureChecksumValueInterceptor .reset ();
109
- }
110
-
111
101
@ Test
112
102
public void sync_json_nonStreaming_unsignedPayload_with_Sha1_in_header () {
113
103
// jsonClient.flexibleCheckSumOperationWithShaChecksum(r -> r.stringMember("Hello world"));
@@ -118,9 +108,6 @@ public void sync_json_nonStreaming_unsignedPayload_with_Sha1_in_header() {
118
108
assertThat (getSyncRequest ().firstMatchingHeader ("x-amz-checksum-sha1" )).hasValue ("M68rRwFal7o7B3KEMt3m0w39TaA=" );
119
109
// Assertion to make sure signer was not executed
120
110
assertThat (getSyncRequest ().firstMatchingHeader ("x-amz-content-sha256" )).isNotPresent ();
121
-
122
- assertThat (CaptureChecksumValueInterceptor .interceptorComputedChecksum ).isEqualTo ("M68rRwFal7o7B3KEMt3m0w39TaA=" );
123
-
124
111
}
125
112
126
113
@ Test
@@ -133,9 +120,6 @@ public void aync_json_nonStreaming_unsignedPayload_with_Sha1_in_header() {
133
120
assertThat (getAsyncRequest ().firstMatchingHeader ("x-amz-checksum-sha1" )).hasValue ("M68rRwFal7o7B3KEMt3m0w39TaA=" );
134
121
// Assertion to make sure signer was not executed
135
122
assertThat (getAsyncRequest ().firstMatchingHeader ("x-amz-content-sha256" )).isNotPresent ();
136
- assertThat (CaptureChecksumValueInterceptor .interceptorComputedChecksum ).isEqualTo ("M68rRwFal7o7B3KEMt3m0w39TaA=" );
137
-
138
-
139
123
}
140
124
141
125
@ Test
@@ -148,9 +132,6 @@ public void sync_xml_nonStreaming_unsignedPayload_with_Sha1_in_header() {
148
132
assertThat (getSyncRequest ().firstMatchingHeader ("x-amz-checksum-sha1" )).hasValue ("FB/utBbwFLbIIt5ul3Ojuy5dKgU=" );
149
133
// Assertion to make sure signer was not executed
150
134
assertThat (getSyncRequest ().firstMatchingHeader ("x-amz-content-sha256" )).isNotPresent ();
151
-
152
- assertThat (CaptureChecksumValueInterceptor .interceptorComputedChecksum ).isEqualTo ("FB/utBbwFLbIIt5ul3Ojuy5dKgU=" );
153
-
154
135
}
155
136
156
137
@ Test
@@ -169,9 +150,6 @@ public void sync_xml_nonStreaming_unsignedEmptyPayload_with_Sha1_in_header() {
169
150
170
151
// Assertion to make sure signer was not executed
171
152
assertThat (getSyncRequest ().firstMatchingHeader ("x-amz-content-sha256" )).isNotPresent ();
172
-
173
- assertThat (CaptureChecksumValueInterceptor .interceptorComputedChecksum ).isNull ();
174
-
175
153
}
176
154
177
155
@ Test
@@ -185,8 +163,6 @@ public void aync_xml_nonStreaming_unsignedPayload_with_Sha1_in_header() {
185
163
assertThat (getAsyncRequest ().firstMatchingHeader ("x-amz-checksum-sha1" )).hasValue ("FB/utBbwFLbIIt5ul3Ojuy5dKgU=" );
186
164
// Assertion to make sure signer was not executed
187
165
assertThat (getAsyncRequest ().firstMatchingHeader ("x-amz-content-sha256" )).isNotPresent ();
188
- assertThat (CaptureChecksumValueInterceptor .interceptorComputedChecksum ).isEqualTo ("FB/utBbwFLbIIt5ul3Ojuy5dKgU=" );
189
-
190
166
}
191
167
192
168
@ Test
@@ -206,8 +182,6 @@ public void aync_xml_nonStreaming_unsignedEmptyPayload_with_Sha1_in_header() {
206
182
assertThat (getAsyncRequest ().firstMatchingHeader ("x-amz-checksum-sha1" )).isNotPresent ();
207
183
// Assertion to make sure signer was not executed
208
184
assertThat (getAsyncRequest ().firstMatchingHeader ("x-amz-content-sha256" )).isNotPresent ();
209
- assertThat (CaptureChecksumValueInterceptor .interceptorComputedChecksum ).isNull ();
210
-
211
185
}
212
186
213
187
private SdkHttpRequest getSyncRequest () {
@@ -224,32 +198,15 @@ private SdkHttpRequest getAsyncRequest() {
224
198
225
199
226
200
private <T extends AwsSyncClientBuilder <T , ?> & AwsClientBuilder <T , ?>> T initializeSync (T syncClientBuilder ) {
227
- return initialize (syncClientBuilder .httpClient (httpClient )
228
- .overrideConfiguration (o -> o .addExecutionInterceptor (new CaptureChecksumValueInterceptor ())));
201
+ return initialize (syncClientBuilder .httpClient (httpClient ));
229
202
}
230
203
231
204
private <T extends AwsAsyncClientBuilder <T , ?> & AwsClientBuilder <T , ?>> T initializeAsync (T asyncClientBuilder ) {
232
- return initialize (asyncClientBuilder .httpClient (httpAsyncClient )
233
- .overrideConfiguration (o -> o .addExecutionInterceptor (new CaptureChecksumValueInterceptor ())));
205
+ return initialize (asyncClientBuilder .httpClient (httpAsyncClient ));
234
206
}
235
207
236
208
private <T extends AwsClientBuilder <T , ?>> T initialize (T clientBuilder ) {
237
209
return clientBuilder .credentialsProvider (AnonymousCredentialsProvider .create ())
238
210
.region (Region .US_WEST_2 );
239
211
}
240
-
241
-
242
- private static class CaptureChecksumValueInterceptor implements ExecutionInterceptor {
243
- private static String interceptorComputedChecksum ;
244
-
245
- private static void reset () {
246
- interceptorComputedChecksum = null ;
247
- }
248
-
249
- @ Override
250
- public void beforeTransmission (Context .BeforeTransmission context , ExecutionAttributes executionAttributes ) {
251
- interceptorComputedChecksum = executionAttributes .getAttribute (HTTP_CHECKSUM_VALUE );
252
-
253
- }
254
- }
255
212
}
0 commit comments