Skip to content

Commit 68c9acb

Browse files
authored
Fix failures in passing or converting permissions (Azure#22712)
1 parent d51125a commit 68c9acb

File tree

5 files changed

+113
-112
lines changed

5 files changed

+113
-112
lines changed

sdk/storage/storage-file-datalake/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
- Added support for encryption scopes.
1010
- Added support for encryption scope SAS.
1111

12+
### Bugs Fixed
13+
14+
- Correted permission string parsing in DataLakePathClient.setPermissions() and DataLakePathClient.getAccessControl().
15+
1216
## 12.10.0 (2022-07-08)
1317

1418
### Features Added

sdk/storage/storage-file-datalake/recordings/node/datalakepathclient_nodejs_only/recording_setpermissions.js

Lines changed: 82 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/storage-file-datalake/src/transforms.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ export function toPathGetAccessControlResponse(
213213
};
214214
}
215215

216-
export function toRolePermissions(
217-
permissionsString: string,
218-
allowStickyBit: boolean = false
219-
): RolePermissions {
216+
export function toRolePermissions(permissionsString: string): RolePermissions {
220217
const error = new RangeError(
221218
`toRolePermissions() Invalid role permissions string ${permissionsString}`
222219
);
@@ -243,12 +240,6 @@ export function toRolePermissions(
243240
let execute = false;
244241
if (permissionsString[2] === "x") {
245242
execute = true;
246-
} else if (allowStickyBit) {
247-
if (permissionsString[2] === "t") {
248-
execute = true;
249-
} else if (permissionsString[2] !== "-") {
250-
throw error;
251-
}
252243
} else if (permissionsString[2] !== "-") {
253244
throw error;
254245
}
@@ -265,14 +256,22 @@ export function toPermissions(permissionsString?: string): PathPermissions | und
265256
throw RangeError(`toPermissions() Invalid permissions string ${permissionsString}`);
266257
}
267258

268-
// Case insensitive
269-
permissionsString = permissionsString.toLowerCase();
270-
271259
let stickyBit = false;
272260
if (permissionsString[8] === "t") {
273261
stickyBit = true;
262+
const firstPart = permissionsString.substr(0, 8);
263+
const lastPart = permissionsString.substr(9);
264+
permissionsString = firstPart + "x" + lastPart;
265+
} else if (permissionsString[8] === "T") {
266+
stickyBit = true;
267+
const firstPart = permissionsString.substr(0, 8);
268+
const lastPart = permissionsString.substr(9);
269+
permissionsString = firstPart + "-" + lastPart;
274270
}
275271

272+
// Case insensitive
273+
permissionsString = permissionsString.toLowerCase();
274+
276275
let extendedAcls = false;
277276
if (permissionsString.length === 10) {
278277
if (permissionsString[9] === "+") {
@@ -284,9 +283,9 @@ export function toPermissions(permissionsString?: string): PathPermissions | und
284283
}
285284
}
286285

287-
const owner = toRolePermissions(permissionsString.substr(0, 3), false);
288-
const group = toRolePermissions(permissionsString.substr(3, 3), false);
289-
const other = toRolePermissions(permissionsString.substr(6, 3), true);
286+
const owner = toRolePermissions(permissionsString.substr(0, 3));
287+
const group = toRolePermissions(permissionsString.substr(3, 3));
288+
const other = toRolePermissions(permissionsString.substr(6, 3));
290289

291290
return {
292291
owner,
@@ -432,7 +431,9 @@ export function toAclString(acl: PathAccessControlItem[]): string {
432431
}
433432

434433
export function toRolePermissionsString(p: RolePermissions, stickyBit: boolean = false): string {
435-
return `${p.read ? "r" : "-"}${p.write ? "w" : "-"}${stickyBit ? "t" : p.execute ? "x" : "-"}`;
434+
return `${p.read ? "r" : "-"}${p.write ? "w" : "-"}${
435+
stickyBit ? (p.execute ? "t" : "T") : p.execute ? "x" : "-"
436+
}`;
436437
}
437438

438439
export function toPermissionsString(permissions: PathPermissions): string {

sdk/storage/storage-file-datalake/test/node/pathclient.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ describe("DataLakePathClient Node.js only", () => {
540540
permissions: {
541541
read: false,
542542
write: true,
543-
execute: true,
543+
execute: false,
544544
},
545545
},
546546
];
@@ -571,10 +571,7 @@ describe("DataLakePathClient Node.js only", () => {
571571

572572
assert.deepStrictEqual(response.owner, "$superuser");
573573
assert.deepStrictEqual(response.group, "$superuser");
574-
assert.deepStrictEqual(response.permissions, {
575-
...permissions,
576-
other: { ...permissions.other, execute: true },
577-
});
574+
assert.deepStrictEqual(response.permissions, permissions);
578575
assert.deepStrictEqual(response.acl, acl);
579576
});
580577

@@ -628,7 +625,7 @@ describe("DataLakePathClient Node.js only", () => {
628625
other: {
629626
read: false,
630627
write: true,
631-
execute: false,
628+
execute: true,
632629
},
633630
};
634631

0 commit comments

Comments
 (0)