Skip to content

Commit f712d0d

Browse files
committed
ITestAbfsCustomEncryption can still work with non hns config, proper guardrail to assert that fs init would fail
1 parent 2d3a5dd commit f712d0d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AzureBlobFileSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ public void initialize(URI uri, Configuration configuration)
231231
|| StringUtils.isNotEmpty(
232232
abfsConfiguration.getEncodedClientProvidedEncryptionKey()))) {
233233
close();
234-
throw new PathIOException(
235-
"Non HNS account " + uri.getPath() + " can not have CPK configs enabled.");
234+
throw new PathIOException(uri.getPath(),
235+
"Non HNS account can not have CPK configs enabled.");
236236
}
237237

238238
LOG.trace("Initiate check for delegation token manager");

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsCustomEncryption.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,43 @@ public static Iterable<Object[]> params() {
171171
}
172172

173173
public ITestAbfsCustomEncryption() throws Exception {
174-
Assume.assumeTrue("Account should be HNS enabled for CPK",
175-
getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT,
176-
false));
177174
new Random().nextBytes(cpk);
178175
cpkSHAEncoded = EncodingHelper.getBase64EncodedString(
179176
EncodingHelper.getSHA256Hash(cpk));
180177
}
181178

182179
@Test
183180
public void testCustomEncryptionCombinations() throws Exception {
184-
AzureBlobFileSystem fs = getOrCreateFS();
181+
final AzureBlobFileSystem fs;
182+
try {
183+
fs = getOrCreateFS();
184+
} catch (PathIOException ex) {
185+
if (ex.getMessage()
186+
.contains("Non HNS account can not have CPK configs enabled.")) {
187+
return;
188+
} else {
189+
throw ex;
190+
}
191+
}
185192
Path testPath = path("/testFile");
186193
String relativePath = fs.getAbfsStore().getRelativePath(testPath);
187-
MockEncryptionContextProvider ecp =
188-
(MockEncryptionContextProvider) createEncryptedFile(testPath);
194+
final MockEncryptionContextProvider ecp;
195+
try {
196+
ecp = (MockEncryptionContextProvider) createEncryptedFile(testPath);
197+
} catch (PathIOException ex) {
198+
if (ex.getMessage()
199+
.contains("Non HNS account can not have CPK configs enabled.")) {
200+
return;
201+
} else {
202+
throw ex;
203+
}
204+
}
205+
Assertions.assertThat(
206+
getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT,
207+
false))
208+
.describedAs(
209+
"Encryption tests should run only on namespace enabled account")
210+
.isTrue();
189211
AbfsRestOperation op = callOperation(fs, new Path(relativePath), ecp);
190212
if (op == null) {
191213
return;

0 commit comments

Comments
 (0)