Skip to content

Commit

Permalink
temporary fix for issue Azure#11505
Browse files Browse the repository at this point in the history
  • Loading branch information
ljian3377 committed Oct 9, 2020
1 parent 7ea23a5 commit 5e27c23
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 24 additions & 9 deletions sdk/storage/storage-file-share/src/Clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,15 +1132,26 @@ export class ShareClient extends StorageClient {
};

for (const identifier of response) {
let accessPolicy: any = undefined;
if (identifier.accessPolicy) {
accessPolicy = {
permissions: identifier.accessPolicy.permissions
};

if (identifier.accessPolicy.expiresOn) {
accessPolicy.expiresOn = new Date(identifier.accessPolicy.expiresOn);
}

if (identifier.accessPolicy.startsOn) {
accessPolicy.startsOn = new Date(identifier.accessPolicy.startsOn);
}
}

res.signedIdentifiers.push({
accessPolicy: {
expiresOn: new Date(identifier.accessPolicy!.expiresOn!),
permissions: identifier.accessPolicy!.permissions!,
startsOn: new Date(identifier.accessPolicy!.startsOn!)
},
accessPolicy,
id: identifier.id
});
}
}

return res;
} catch (e) {
Expand Down Expand Up @@ -1182,9 +1193,13 @@ export class ShareClient extends StorageClient {
for (const identifier of shareAcl || []) {
acl.push({
accessPolicy: {
expiresOn: truncatedISO8061Date(identifier.accessPolicy.expiresOn),
permissions: identifier.accessPolicy.permissions,
startsOn: truncatedISO8061Date(identifier.accessPolicy.startsOn)
expiresOn: identifier.accessPolicy?.expiresOn
? truncatedISO8061Date(identifier.accessPolicy.expiresOn)
: undefined,
permissions: identifier.accessPolicy?.permissions,
startsOn: identifier.accessPolicy?.startsOn
? truncatedISO8061Date(identifier.accessPolicy.startsOn)
: undefined
},
id: identifier.id
});
Expand Down
14 changes: 14 additions & 0 deletions sdk/storage/storage-file-share/test/node/shareclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ describe("ShareClient Node.js only", () => {
done();
});

it("setAccessPolicy and getAccessPolicy with empty SignedIdentifier", async () => {
const identifiers: any = [
{
id: "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
];

await shareClient.setAccessPolicy(identifiers);
const getAccessPolicyResponse = await shareClient.getAccessPolicy();

assert.equal(getAccessPolicyResponse.signedIdentifiers[0].id, identifiers[0].id);
assert.deepStrictEqual(getAccessPolicyResponse.signedIdentifiers[0].accessPolicy, undefined);
});

it("can be created with a url and a credential", async () => {
const factories = (shareClient as any).pipeline.factories;
const credential = factories[factories.length - 1] as StorageSharedKeyCredential;
Expand Down

0 comments on commit 5e27c23

Please sign in to comment.