|
24 | 24 |
|
25 | 25 | import org.junit.Assume; |
26 | 26 | import org.junit.Test; |
| 27 | +import org.mockito.Mockito; |
27 | 28 | import org.slf4j.Logger; |
28 | 29 | import org.slf4j.LoggerFactory; |
29 | 30 |
|
|
35 | 36 | import org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys; |
36 | 37 | import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException; |
37 | 38 | import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode; |
| 39 | +import org.apache.hadoop.fs.azurebfs.security.ContextEncryptionAdapter; |
| 40 | +import org.apache.hadoop.fs.azurebfs.services.AbfsBlobClient; |
38 | 41 | import org.apache.hadoop.fs.azurebfs.services.AuthType; |
39 | 42 | import org.apache.hadoop.fs.azurebfs.utils.TracingContext; |
40 | 43 | import org.apache.hadoop.io.IOUtils; |
|
47 | 50 | import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_BLOB_DATA_READER_CLIENT_SECRET; |
48 | 51 | import static org.apache.hadoop.fs.contract.ContractTestUtils.assertPathDoesNotExist; |
49 | 52 | import static org.apache.hadoop.fs.contract.ContractTestUtils.assertPathExists; |
| 53 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; |
50 | 54 |
|
51 | 55 | /** |
52 | 56 | * Test Azure Oauth with Blob Data contributor role and Blob Data Reader role. |
@@ -167,6 +171,36 @@ public void testBlobDataReader() throws Exception { |
167 | 171 |
|
168 | 172 | } |
169 | 173 |
|
| 174 | + /* |
| 175 | + * GetPathStatus with Blob Data Reader role should not throw an exception when marker creation fails due to permission issues. |
| 176 | + * */ |
| 177 | + @Test |
| 178 | + public void testGetPathStatusWithReader() throws Exception { |
| 179 | + String clientId = this.getConfiguration().get(FS_AZURE_BLOB_DATA_READER_CLIENT_ID); |
| 180 | + Assume.assumeTrue("Reader client id not provided", clientId != null); |
| 181 | + String secret = this.getConfiguration().get(FS_AZURE_BLOB_DATA_READER_CLIENT_SECRET); |
| 182 | + Assume.assumeTrue("Reader client secret not provided", secret != null); |
| 183 | + |
| 184 | + Path existedFolderPath = path(EXISTED_FOLDER_PATH); |
| 185 | + createAzCopyFolder(existedFolderPath); |
| 186 | + final AzureBlobFileSystem fs = Mockito.spy(getBlobReader()); |
| 187 | + |
| 188 | + // Use abfsStore in this test to verify the ERROR code in AbfsRestOperationException |
| 189 | + AzureBlobFileSystemStore abfsStore = Mockito.spy(fs.getAbfsStore()); |
| 190 | + Mockito.doReturn(abfsStore).when(fs).getAbfsStore(); |
| 191 | + AbfsBlobClient abfsClient = Mockito.spy(abfsStore.getClientHandler().getBlobClient()); |
| 192 | + Mockito.doReturn(abfsClient).when(abfsStore).getClient(); |
| 193 | + TracingContext tracingContext = getTestTracingContext(fs, true); |
| 194 | + |
| 195 | + // GETPATHSTATUS marker creation fail should not be propagated to the caller. |
| 196 | + assertThatCode(() -> abfsStore.getPathStatus(existedFolderPath, tracingContext)) |
| 197 | + .as("Expected getPathStatus to complete without throwing an exception") |
| 198 | + .doesNotThrowAnyException(); |
| 199 | + Mockito.verify(abfsClient, Mockito.times(1)).createMarkerAtPath(Mockito.anyString(), Mockito.nullable(String.class), |
| 200 | + Mockito.nullable(ContextEncryptionAdapter.class), |
| 201 | + Mockito.nullable(TracingContext.class)); |
| 202 | + } |
| 203 | + |
170 | 204 | private void prepareFiles(Path existedFilePath, Path existedFolderPath) throws IOException { |
171 | 205 | // create test files/folders to verify access control diff between |
172 | 206 | // Blob data contributor and Blob data reader |
|
0 commit comments