diff --git a/sdk/storage/storage-file-share/recordings/node/shareclient_nodejs_only/recording_setaccesspolicy_and_getaccesspolicy_with_empty_signedidentifier.js b/sdk/storage/storage-file-share/recordings/node/shareclient_nodejs_only/recording_setaccesspolicy_and_getaccesspolicy_with_empty_signedidentifier.js new file mode 100644 index 000000000000..0b0d257f39b3 --- /dev/null +++ b/sdk/storage/storage-file-share/recordings/node/shareclient_nodejs_only/recording_setaccesspolicy_and_getaccesspolicy_with_empty_signedidentifier.js @@ -0,0 +1,95 @@ +let nock = require('nock'); + +module.exports.hash = "3ebabd40f7e1e2d99e8708a8b72d7c1c"; + +module.exports.testInfo = {"uniqueName":{"share":"share160224079312107686"},"newDate":{}} + +nock('https://fakestorageaccount.file.core.windows.net:443', {"encodedQueryParams":true}) + .put('/share160224079312107686') + .query(true) + .reply(201, "", [ + 'Content-Length', + '0', + 'Last-Modified', + 'Fri, 09 Oct 2020 10:53:14 GMT', + 'ETag', + '"0x8D86C4185BA2A5B"', + 'Server', + 'Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'e574a944-401a-002d-6b2a-9eddd5000000', + 'x-ms-client-request-id', + 'eb2a5911-6380-4442-864a-6c70df597eae', + 'x-ms-version', + '2020-02-10', + 'Date', + 'Fri, 09 Oct 2020 10:53:14 GMT' +]); + +nock('https://fakestorageaccount.file.core.windows.net:443', {"encodedQueryParams":true}) + .put('/share160224079312107686', "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=") + .query(true) + .reply(200, "", [ + 'Content-Length', + '0', + 'Last-Modified', + 'Fri, 09 Oct 2020 10:53:14 GMT', + 'ETag', + '"0x8D86C4185ED2986"', + 'Server', + 'Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'e574a947-401a-002d-6c2a-9eddd5000000', + 'x-ms-client-request-id', + '84e0844e-b5b0-4d78-bfe3-cc5d25692a35', + 'x-ms-version', + '2020-02-10', + 'Date', + 'Fri, 09 Oct 2020 10:53:14 GMT' +]); + +nock('https://fakestorageaccount.file.core.windows.net:443', {"encodedQueryParams":true}) + .get('/share160224079312107686') + .query(true) + .reply(200, "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=", [ + 'Transfer-Encoding', + 'chunked', + 'Content-Type', + 'application/xml', + 'Last-Modified', + 'Fri, 09 Oct 2020 10:53:14 GMT', + 'ETag', + '"0x8D86C4185ED2986"', + 'Server', + 'Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'e574a949-401a-002d-6e2a-9eddd5000000', + 'x-ms-client-request-id', + '147051c4-d43f-4e80-acd0-724b355fa4e2', + 'x-ms-version', + '2020-02-10', + 'Access-Control-Expose-Headers', + 'x-ms-request-id,x-ms-client-request-id,Server,x-ms-version,Last-Modified,ETag,Content-Length,Date,Transfer-Encoding', + 'Access-Control-Allow-Origin', + '*', + 'Date', + 'Fri, 09 Oct 2020 10:53:15 GMT' +]); + +nock('https://fakestorageaccount.file.core.windows.net:443', {"encodedQueryParams":true}) + .delete('/share160224079312107686') + .query(true) + .reply(202, "", [ + 'Content-Length', + '0', + 'Server', + 'Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'e574a94b-401a-002d-6f2a-9eddd5000000', + 'x-ms-client-request-id', + 'a5f5debb-fc04-44c8-81a9-4d15a428c3de', + 'x-ms-version', + '2020-02-10', + 'Date', + 'Fri, 09 Oct 2020 10:53:15 GMT' +]); diff --git a/sdk/storage/storage-file-share/src/Clients.ts b/sdk/storage/storage-file-share/src/Clients.ts index acd06bd6c049..70d2b16694f1 100644 --- a/sdk/storage/storage-file-share/src/Clients.ts +++ b/sdk/storage/storage-file-share/src/Clients.ts @@ -1132,12 +1132,23 @@ 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 }); } @@ -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 }); diff --git a/sdk/storage/storage-file-share/test/node/shareclient.spec.ts b/sdk/storage/storage-file-share/test/node/shareclient.spec.ts index 2018cc066817..773be116b382 100644 --- a/sdk/storage/storage-file-share/test/node/shareclient.spec.ts +++ b/sdk/storage/storage-file-share/test/node/shareclient.spec.ts @@ -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;