Skip to content

Commit

Permalink
[Storage] BlobSASSignatureValues could use BlobSASPermissions type fo…
Browse files Browse the repository at this point in the history
…r `permissions` instead of string (#5626)

* BlobSASSignatureValues could use BlobSASPermissions type for permissions

* updating the tests
  • Loading branch information
HarshaNalluru authored Oct 18, 2019
1 parent 7187c1f commit efbcb75
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 63 deletions.
10 changes: 5 additions & 5 deletions sdk/storage/storage-blob/src/AccountSASSignatureValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export interface AccountSASSignatureValues {
* Specifies which operations the SAS user may perform. Please refer to {@link AccountSASPermissions} for help
* constructing the permissions string.
*
* @type {string}
* @type {AccountSASPermissions}
* @memberof AccountSASSignatureValues
*/
permissions: string;
permissions: AccountSASPermissions;

/**
* Optional. IP range allowed.
Expand Down Expand Up @@ -118,8 +118,8 @@ export function generateAccountSASQueryParameters(
: SERVICE_VERSION;

const parsedPermissions = AccountSASPermissions.parse(
accountSASSignatureValues.permissions
).toString();
accountSASSignatureValues.permissions.toString()
);
const parsedServices = AccountSASServices.parse(accountSASSignatureValues.services).toString();
const parsedResourceTypes = AccountSASResourceTypes.parse(
accountSASSignatureValues.resourceTypes
Expand All @@ -145,7 +145,7 @@ export function generateAccountSASQueryParameters(
return new SASQueryParameters(
version,
signature,
parsedPermissions,
parsedPermissions.toString(),
parsedServices,
parsedResourceTypes,
accountSASSignatureValues.protocol,
Expand Down
22 changes: 14 additions & 8 deletions sdk/storage/storage-blob/src/BlobSASSignatureValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export interface BlobSASSignatureValues {
* Please refer to either {@link ContainerSASPermissions} or {@link BlobSASPermissions} depending on the resource
* being accessed for help constructing the permissions string.
*
* @type {string}
* @type {BlobSASPermissions}
* @memberof BlobSASSignatureValues
*/
permissions?: string;
permissions?: BlobSASPermissions;

/**
* Optional. IP ranges allowed in this SAS.
Expand Down Expand Up @@ -359,11 +359,13 @@ function generateBlobSASQueryParameters20150405(
// Calling parse and toString guarantees the proper ordering and throws on invalid characters.
if (blobSASSignatureValues.permissions) {
if (blobSASSignatureValues.blobName) {
verifiedPermissions = BlobSASPermissions.parse(blobSASSignatureValues.permissions).toString();
verifiedPermissions = BlobSASPermissions.parse(
blobSASSignatureValues.permissions.toString()
).toString();
resource = "b";
} else {
verifiedPermissions = ContainerSASPermissions.parse(
blobSASSignatureValues.permissions
blobSASSignatureValues.permissions.toString()
).toString();
}
}
Expand Down Expand Up @@ -456,14 +458,16 @@ function generateBlobSASQueryParameters20181109(
// Calling parse and toString guarantees the proper ordering and throws on invalid characters.
if (blobSASSignatureValues.permissions) {
if (blobSASSignatureValues.blobName) {
verifiedPermissions = BlobSASPermissions.parse(blobSASSignatureValues.permissions).toString();
verifiedPermissions = BlobSASPermissions.parse(
blobSASSignatureValues.permissions.toString()
).toString();
resource = "b";
if (blobSASSignatureValues.snapshotTime) {
resource = "bs";
}
} else {
verifiedPermissions = ContainerSASPermissions.parse(
blobSASSignatureValues.permissions
blobSASSignatureValues.permissions.toString()
).toString();
}
}
Expand Down Expand Up @@ -553,14 +557,16 @@ function generateBlobSASQueryParametersUDK20181109(
// Calling parse and toString guarantees the proper ordering and throws on invalid characters.
if (blobSASSignatureValues.permissions) {
if (blobSASSignatureValues.blobName) {
verifiedPermissions = BlobSASPermissions.parse(blobSASSignatureValues.permissions).toString();
verifiedPermissions = BlobSASPermissions.parse(
blobSASSignatureValues.permissions.toString()
).toString();
resource = "b";
if (blobSASSignatureValues.snapshotTime) {
resource = "bs";
}
} else {
verifiedPermissions = ContainerSASPermissions.parse(
blobSASSignatureValues.permissions
blobSASSignatureValues.permissions.toString()
).toString();
}
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/test/node/appendblobclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe("AppendBlobClient Node.js only", () => {
expiryTime,
containerName,
blobName: blockBlobName,
permissions: BlobSASPermissions.parse("r").toString()
permissions: BlobSASPermissions.parse("r")
},
credential
);
Expand Down Expand Up @@ -162,7 +162,7 @@ describe("AppendBlobClient Node.js only", () => {
expiryTime,
containerName,
blobName: blockBlobName,
permissions: BlobSASPermissions.parse("r").toString()
permissions: BlobSASPermissions.parse("r")
},
credential
);
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/test/node/blobclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe("BlobClient Node.js only", () => {
const sas = generateBlobSASQueryParameters(
{
expiryTime,
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
containerName,
blobName
},
Expand Down
11 changes: 8 additions & 3 deletions sdk/storage/storage-blob/test/node/containerclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as assert from "assert";

import { getBSU, getConnectionStringFromEnvironment } from "../utils";
import { PublicAccessType } from "../../src/generated/src/models/index";
import { ContainerClient, newPipeline, SharedKeyCredential } from "../../src";
import {
ContainerClient,
newPipeline,
SharedKeyCredential,
ContainerSASPermissions
} from "../../src";
import { TokenCredential } from "@azure/core-http";
import { assertClientUsesTokenCredential } from "../utils/assert";
import { record } from "../utils/recorder";
Expand Down Expand Up @@ -41,7 +46,7 @@ describe("ContainerClient Node.js only", () => {
{
accessPolicy: {
expiry: new Date("2018-12-31T11:22:33.4567890Z"),
permissions: "rwd",
permissions: ContainerSASPermissions.parse("rwd").toString(),
start: new Date("2017-12-31T11:22:33.4567890Z")
},
id: "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
Expand All @@ -59,7 +64,7 @@ describe("ContainerClient Node.js only", () => {
const containerAcl = [
{
accessPolicy: {
permissions: "rwd"
permissions: ContainerSASPermissions.parse("rwd").toString()
},
id: "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/test/node/pageblobclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe("PageBlobClient Node.js only", () => {
expiryTime,
containerName,
blobName: blockBlobName,
permissions: BlobSASPermissions.parse("r").toString()
permissions: BlobSASPermissions.parse("r")
},
sharedKeyCredential as SharedKeyCredential
);
Expand Down Expand Up @@ -259,7 +259,7 @@ describe("PageBlobClient Node.js only", () => {
expiryTime,
containerName,
blobName: blockBlobName,
permissions: BlobSASPermissions.parse("r").toString()
permissions: BlobSASPermissions.parse("r")
},
credential
);
Expand Down
26 changes: 13 additions & 13 deletions sdk/storage/storage-blob/test/node/sas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
{
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: AccountSASPermissions.parse("rwdlacup").toString(),
permissions: AccountSASPermissions.parse("rwdlacup"),
protocol: SASProtocol.HttpsAndHttp,
resourceTypes: AccountSASResourceTypes.parse("sco").toString(),
services: AccountSASServices.parse("btqf").toString(),
Expand Down Expand Up @@ -77,7 +77,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
const sas = generateAccountSASQueryParameters(
{
expiryTime: tmr,
permissions: AccountSASPermissions.parse("wdlcup").toString(),
permissions: AccountSASPermissions.parse("wdlcup"),
resourceTypes: AccountSASResourceTypes.parse("sco").toString(),
services: AccountSASServices.parse("btqf").toString()
},
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
const sas = generateAccountSASQueryParameters(
{
expiryTime: tmr,
permissions: AccountSASPermissions.parse("rwdlacup").toString(),
permissions: AccountSASPermissions.parse("rwdlacup"),
resourceTypes: AccountSASResourceTypes.parse("sco").toString(),
services: AccountSASServices.parse("tqf").toString()
},
Expand Down Expand Up @@ -146,7 +146,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
{
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: AccountSASPermissions.parse("rwdlacup").toString(),
permissions: AccountSASPermissions.parse("rwdlacup"),
protocol: SASProtocol.HttpsAndHttp,
resourceTypes: AccountSASResourceTypes.parse("co").toString(),
services: AccountSASServices.parse("btqf").toString(),
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
containerName: containerClient.containerName,
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: ContainerSASPermissions.parse("racwdl").toString(),
permissions: ContainerSASPermissions.parse("racwdl"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now,
version: "2016-05-31"
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
contentType: "content-type-override",
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now,
version: "2016-05-31"
Expand Down Expand Up @@ -300,7 +300,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
contentType: "content-type-override",
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now
},
Expand Down Expand Up @@ -356,7 +356,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
contentType: "content-type-override",
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now,
snapshotTime: response.snapshot
Expand Down Expand Up @@ -413,7 +413,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
contentType: "content-type-override",
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now,
version: "2016-05-31"
Expand Down Expand Up @@ -514,7 +514,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
containerName: containerClient.containerName,
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: ContainerSASPermissions.parse("racwdl").toString(),
permissions: ContainerSASPermissions.parse("racwdl"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now,
version: "2019-02-02"
Expand Down Expand Up @@ -569,7 +569,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
{
containerName: containerClient.containerName,
expiryTime: tmr,
permissions: ContainerSASPermissions.parse("racwdl").toString()
permissions: ContainerSASPermissions.parse("racwdl")
},
userDelegationKey,
accountName
Expand Down Expand Up @@ -636,7 +636,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
contentType: "content-type-override",
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now
},
Expand Down Expand Up @@ -707,7 +707,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
contentType: "content-type-override",
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: BlobSASPermissions.parse("racwd").toString(),
permissions: BlobSASPermissions.parse("racwd"),
protocol: SASProtocol.HttpsAndHttp,
startTime: now,
snapshotTime: response.snapshot
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/test/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function getSASConnectionStringFromEnvironment(): string {
{
expiryTime: tmr,
ipRange: { start: "0.0.0.0", end: "255.255.255.255" },
permissions: AccountSASPermissions.parse("rwdlacup").toString(),
permissions: AccountSASPermissions.parse("rwdlacup"),
protocol: SASProtocol.HttpsAndHttp,
resourceTypes: AccountSASResourceTypes.parse("sco").toString(),
services: AccountSASServices.parse("btqf").toString(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/storage-file/src/AccountSASSignatureValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export interface AccountSASSignatureValues {
* Specifies which operations the SAS user may perform. Please refer to {@link AccountSASPermissions} for help
* constructing the permissions string.
*
* @type {string}
* @type {AccountSASPermissions}
* @memberof AccountSASSignatureValues
*/
permissions: string;
permissions: AccountSASPermissions;

/**
* Optional. IP range allowed.
Expand Down Expand Up @@ -118,7 +118,7 @@ export function generateAccountSASQueryParameters(
: SERVICE_VERSION;

const parsedPermissions = AccountSASPermissions.parse(
accountSASSignatureValues.permissions
accountSASSignatureValues.permissions.toString()
).toString();
const parsedServices = AccountSASServices.parse(accountSASSignatureValues.services).toString();
const parsedResourceTypes = AccountSASResourceTypes.parse(
Expand Down
10 changes: 6 additions & 4 deletions sdk/storage/storage-file/src/FileSASSignatureValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export interface FileSASSignatureValues {
* Please refer to either {@link ShareSASPermissions} or {@link FileSASPermissions} depending on the resource
* being accessed for help constructing the permissions string.
*
* @type {string}
* @type {FileSASPermissions}
* @memberof FileSASSignatureValues
*/
permissions?: string;
permissions?: FileSASPermissions;

/**
* Optional. IP ranges allowed in this SAS.
Expand Down Expand Up @@ -174,11 +174,13 @@ export function generateFileSASQueryParameters(
// Calling parse and toString guarantees the proper ordering and throws on invalid characters.
if (fileSASSignatureValues.permissions) {
if (fileSASSignatureValues.filePath) {
verifiedPermissions = FileSASPermissions.parse(fileSASSignatureValues.permissions).toString();
verifiedPermissions = FileSASPermissions.parse(
fileSASSignatureValues.permissions.toString()
).toString();
resource = "f";
} else {
verifiedPermissions = ShareSASPermissions.parse(
fileSASSignatureValues.permissions
fileSASSignatureValues.permissions.toString()
).toString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-file/test/node/fileclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe("FileClient Node.js only", () => {
expiryTime,
shareName,
filePath: `${dirName}/${fileName}`,
permissions: FileSASPermissions.parse("r").toString()
permissions: FileSASPermissions.parse("r")
},
credential
);
Expand Down
Loading

0 comments on commit efbcb75

Please sign in to comment.