|
29 | 29 | import org.junit.runners.Parameterized; |
30 | 30 |
|
31 | 31 | import org.apache.hadoop.conf.Configuration; |
| 32 | +import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException; |
| 33 | +import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode; |
32 | 34 | import org.apache.hadoop.fs.azurebfs.services.AbfsClient; |
33 | 35 | import org.apache.hadoop.fs.CommonConfigurationKeysPublic; |
34 | 36 | import org.apache.hadoop.fs.azurebfs.constants.FileSystemUriSchemes; |
@@ -81,18 +83,33 @@ public void testClientUrlScheme() throws Exception { |
81 | 83 | Configuration config = getRawConfiguration(); |
82 | 84 | config.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsUrl.toString()); |
83 | 85 | config.setBoolean(FS_AZURE_ALWAYS_USE_HTTPS, alwaysUseHttps); |
84 | | - |
85 | | - AbfsClient client = this.getFileSystem(config).getAbfsClient(); |
| 86 | + // HTTP is enabled only when "abfs://XXX" is used and FS_AZURE_ALWAYS_USE_HTTPS |
| 87 | + // is set as false, otherwise HTTPS should be used. |
| 88 | + boolean expectHttpConnection = !useSecureScheme && !alwaysUseHttps; |
| 89 | + |
| 90 | + AbfsClient client = null; |
| 91 | + try { |
| 92 | + client = this.getFileSystem(config).getAbfsClient(); |
| 93 | + } catch (AbfsRestOperationException e) { |
| 94 | + if (AzureServiceErrorCode.ACCOUNT_REQUIRES_HTTPS.equals(e.getErrorCode()) |
| 95 | + && expectHttpConnection) { |
| 96 | + // if we get here, the error message was the account supports HTTPS only |
| 97 | + // and this parameterized test is trying to create an HTTP one. |
| 98 | + // we can implicitly infer that the scheme setup went through, |
| 99 | + // otherwise it would not have been rejected at the far end |
| 100 | + return; |
| 101 | + } else { |
| 102 | + throw e; |
| 103 | + } |
| 104 | + } |
86 | 105 |
|
87 | 106 | Field baseUrlField = AbfsClient.class. |
88 | 107 | getDeclaredField("baseUrl"); |
89 | 108 | baseUrlField.setAccessible(true); |
90 | 109 |
|
91 | 110 | String url = ((URL) baseUrlField.get(client)).toString(); |
92 | 111 |
|
93 | | - // HTTP is enabled only when "abfs://XXX" is used and FS_AZURE_ALWAYS_USE_HTTPS |
94 | | - // is set as false, otherwise HTTPS should be used. |
95 | | - if (!useSecureScheme && !alwaysUseHttps) { |
| 112 | + if (expectHttpConnection) { |
96 | 113 | Assert.assertTrue(url.startsWith(FileSystemUriSchemes.HTTP_SCHEME)); |
97 | 114 | } else { |
98 | 115 | Assert.assertTrue(url.startsWith(FileSystemUriSchemes.HTTPS_SCHEME)); |
|
0 commit comments