-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-17397: ABFS: SAS Test updates for version and permission update #2504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ | |
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException; | ||
| import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.Assume; | ||
| import org.junit.Test; | ||
|
|
@@ -94,13 +96,16 @@ public void testCheckAccess() throws Exception { | |
| final AzureBlobFileSystem fs = getFileSystem(); | ||
|
|
||
| Path rootPath = new Path("/"); | ||
| fs.setOwner(rootPath, MockDelegationSASTokenProvider.TEST_OWNER, null); | ||
| fs.setPermission(rootPath, new FsPermission(FsAction.ALL, FsAction.READ_EXECUTE, FsAction.EXECUTE)); | ||
| FileStatus rootStatus = fs.getFileStatus(rootPath); | ||
| assertEquals("The directory permissions are not expected.", "rwxr-x--x", rootStatus.getPermission().toString()); | ||
| assertEquals("The directory owner is not expected.", | ||
| MockDelegationSASTokenProvider.TEST_OWNER, | ||
| rootStatus.getOwner()); | ||
|
|
||
| Path dirPath = new Path(UUID.randomUUID().toString()); | ||
| fs.mkdirs(dirPath); | ||
| fs.setOwner(dirPath, MockDelegationSASTokenProvider.TEST_OWNER, null); | ||
|
|
||
| Path filePath = new Path(dirPath, "file1"); | ||
| fs.create(filePath).close(); | ||
|
|
@@ -324,8 +329,10 @@ public void testRootPath() throws Exception { | |
| final AzureBlobFileSystem fs = getFileSystem(); | ||
| Path rootPath = new Path(AbfsHttpConstants.ROOT_PATH); | ||
|
|
||
| fs.setOwner(rootPath, MockDelegationSASTokenProvider.TEST_OWNER, null); | ||
| FileStatus status = fs.getFileStatus(rootPath); | ||
| assertEquals("rwxr-x---", status.getPermission().toString()); | ||
| assertEquals(MockDelegationSASTokenProvider.TEST_OWNER, status.getOwner()); | ||
| assertTrue(status.isDirectory()); | ||
|
|
||
| AclStatus acl = fs.getAclStatus(rootPath); | ||
|
|
@@ -410,4 +417,64 @@ public void testSignatureMaskOnExceptionMessage() throws Exception { | |
| .renamePath("testABC/test.xt", "testABC/abc.txt", null)); | ||
| } | ||
|
|
||
| @Test | ||
| // SetPermission should fail when saoid is not the owner and succeed when it is. | ||
| public void testSetPermissionForNonOwner() throws Exception { | ||
| final AzureBlobFileSystem fs = getFileSystem(); | ||
|
|
||
| Path rootPath = new Path("/"); | ||
| FileStatus rootStatus = fs.getFileStatus(rootPath); | ||
| assertEquals("The permissions are not expected.", | ||
| "rwxr-x---", | ||
| rootStatus.getPermission().toString()); | ||
| assertNotEquals("The owner is not expected.", | ||
| MockDelegationSASTokenProvider.TEST_OWNER, | ||
| rootStatus.getOwner()); | ||
|
|
||
| // Attempt to set permission without being the owner. | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intercept(()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @steveloughran for the heads up regarding the intercept helper. I'll wait for a review from a member next time. By the way, the DelegationSASGenerator.java file demonstrates the minimal permissions required for each operation, and is used by some as a guide for implementing a SASTokenProvider. If anyone picked up the previous change for HADOOP-17397, they should pick up this fix too since the previous commit introduced an elevation of privilege bug. |
||
| fs.setPermission(rootPath, new FsPermission(FsAction.ALL, | ||
| FsAction.READ_EXECUTE, FsAction.EXECUTE)); | ||
| assertTrue("Set permission should fail because saoid is not the owner.", false); | ||
| } catch (AbfsRestOperationException ex) { | ||
| // Should fail with permission mismatch | ||
| assertEquals(AzureServiceErrorCode.AUTHORIZATION_PERMISSION_MISS_MATCH, | ||
| ex.getErrorCode()); | ||
| } | ||
|
|
||
| // Attempt to set permission as the owner. | ||
| fs.setOwner(rootPath, MockDelegationSASTokenProvider.TEST_OWNER, null); | ||
| fs.setPermission(rootPath, new FsPermission(FsAction.ALL, | ||
| FsAction.READ_EXECUTE, FsAction.EXECUTE)); | ||
| rootStatus = fs.getFileStatus(rootPath); | ||
| assertEquals("The permissions are not expected.", | ||
| "rwxr-x--x", | ||
| rootStatus.getPermission().toString()); | ||
| assertEquals("The directory owner is not expected.", | ||
| MockDelegationSASTokenProvider.TEST_OWNER, | ||
| rootStatus.getOwner()); | ||
| } | ||
|
|
||
| @Test | ||
| // Without saoid or suoid, setPermission should succeed with sp=p for a non-owner. | ||
| public void testSetPermissionWithoutAgentForNonOwner() throws Exception { | ||
| final AzureBlobFileSystem fs = getFileSystem(); | ||
| Path path = new Path(MockDelegationSASTokenProvider.NO_AGENT_PATH); | ||
| fs.create(path).close(); | ||
|
|
||
| FileStatus status = fs.getFileStatus(path); | ||
| assertEquals("The permissions are not expected.", | ||
| "rw-r--r--", | ||
| status.getPermission().toString()); | ||
| assertNotEquals("The owner is not expected.", | ||
| TestConfigurationKeys.FS_AZURE_TEST_APP_SERVICE_PRINCIPAL_OBJECT_ID, | ||
| status.getOwner()); | ||
|
|
||
| fs.setPermission(path, new FsPermission(FsAction.READ, FsAction.READ, FsAction.NONE)); | ||
|
|
||
| FileStatus fileStatus = fs.getFileStatus(path); | ||
| assertEquals("The permissions are not expected.", | ||
| "r--r-----", | ||
| fileStatus.getPermission().toString()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import placement/ordering