35
35
import org .apache .hadoop .fs .azurebfs .services .AbfsClientUtils ;
36
36
import org .apache .hadoop .fs .azurebfs .utils .TracingContext ;
37
37
import org .assertj .core .api .Assertions ;
38
+ import org .assertj .core .api .Assumptions ;
38
39
import org .junit .Test ;
39
40
import org .junit .runner .RunWith ;
40
41
import org .junit .runners .Parameterized ;
59
60
import org .apache .hadoop .test .LambdaTestUtils ;
60
61
import org .apache .hadoop .util .Lists ;
61
62
63
+ import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT ;
62
64
import static org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys .FS_AZURE_ENCRYPTION_CONTEXT_PROVIDER_TYPE ;
63
65
import static org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys .FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY ;
64
66
import static org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys .FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA ;
@@ -177,36 +179,11 @@ public ITestAbfsCustomEncryption() throws Exception {
177
179
178
180
@ Test
179
181
public void testCustomEncryptionCombinations () throws Exception {
180
- final AzureBlobFileSystem fs ;
181
- try {
182
- fs = getOrCreateFS ();
183
- } catch (PathIOException ex ) {
184
- if (ex .getMessage ()
185
- .contains ("Non HNS account can not have CPK configs enabled." )) {
186
- return ;
187
- } else {
188
- throw ex ;
189
- }
190
- }
182
+ AzureBlobFileSystem fs = getOrCreateFS ();
191
183
Path testPath = path ("/testFile" );
192
184
String relativePath = fs .getAbfsStore ().getRelativePath (testPath );
193
- final MockEncryptionContextProvider ecp ;
194
- try {
195
- ecp = (MockEncryptionContextProvider ) createEncryptedFile (testPath );
196
- } catch (PathIOException ex ) {
197
- if (ex .getMessage ()
198
- .contains ("Non HNS account can not have CPK configs enabled." )) {
199
- return ;
200
- } else {
201
- throw ex ;
202
- }
203
- }
204
- Assertions .assertThat (
205
- getConfiguration ().getBoolean (FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT ,
206
- false ))
207
- .describedAs (
208
- "Encryption tests should run only on namespace enabled account" )
209
- .isTrue ();
185
+ MockEncryptionContextProvider ecp
186
+ = (MockEncryptionContextProvider ) createEncryptedFile (testPath );
210
187
AbfsRestOperation op = callOperation (fs , new Path (relativePath ), ecp );
211
188
if (op == null ) {
212
189
return ;
@@ -396,9 +373,7 @@ private AzureBlobFileSystem getECProviderEnabledFS() throws Exception {
396
373
+ getAccountName ());
397
374
configuration .unset (FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA + "."
398
375
+ getAccountName ());
399
- AzureBlobFileSystem fs = (AzureBlobFileSystem ) FileSystem .newInstance (configuration );
400
- fileSystemsOpenedInTest .add (fs );
401
- return fs ;
376
+ return getAzureBlobFileSystem (configuration );
402
377
}
403
378
404
379
private AzureBlobFileSystem getCPKEnabledFS () throws IOException {
@@ -411,9 +386,34 @@ private AzureBlobFileSystem getCPKEnabledFS() throws IOException {
411
386
conf .set (FS_AZURE_ENCRYPTION_ENCODED_CLIENT_PROVIDED_KEY_SHA + "."
412
387
+ getAccountName (), cpkEncodedSHA );
413
388
conf .unset (FS_AZURE_ENCRYPTION_CONTEXT_PROVIDER_TYPE );
414
- AzureBlobFileSystem fs = (AzureBlobFileSystem ) FileSystem .newInstance (conf );
415
- fileSystemsOpenedInTest .add (fs );
416
- return fs ;
389
+ return getAzureBlobFileSystem (conf );
390
+ }
391
+
392
+ private AzureBlobFileSystem getAzureBlobFileSystem (final Configuration conf ) {
393
+ try {
394
+ AzureBlobFileSystem fs = (AzureBlobFileSystem ) FileSystem .newInstance (
395
+ conf );
396
+ fileSystemsOpenedInTest .add (fs );
397
+ Assertions .assertThat (
398
+ getConfiguration ().getBoolean (FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT ,
399
+ false ))
400
+ .describedAs ("Encryption tests should run only on namespace enabled account" )
401
+ .isTrue ();
402
+ return fs ;
403
+ } catch (IOException ex ) {
404
+ Assertions .assertThat (ex .getMessage ())
405
+ .describedAs ("Exception message should contain the expected message" )
406
+ .contains (FS_INIT_FAILED_CPK_CONFIG_IN_NON_HNS_ACCOUNT );
407
+ Assertions .assertThat (
408
+ getConfiguration ().getBoolean (FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT ,
409
+ false ))
410
+ .describedAs ("Encryption tests should run only on namespace enabled account" )
411
+ .isFalse ();
412
+
413
+ //Skip the test
414
+ Assumptions .assumeThat (true ).isFalse ();
415
+ return null ;
416
+ }
417
417
}
418
418
419
419
private AzureBlobFileSystem getOrCreateFS () throws Exception {
0 commit comments