Skip to content

Commit

Permalink
[Storage] port PR #24953 from storage/stable branch (#26279)
Browse files Browse the repository at this point in the history
#24953

- port tests. source changes are not needed any more as we no longer use
`URLBuilder`, but switched to `URL`
- add recordings for new tests
  • Loading branch information
jeremymeng authored Jun 22, 2023
1 parent c6d7472 commit 84aeb3d
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/storage/storage-blob",
"Tag": "js/storage/storage-blob_5d5a32b74a"
"Tag": "js/storage/storage-blob_8c8488b395"
}
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/test/node/sas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {

// NOTICE: Azure Storage Server will replace "\" with "/" in the blob names
const blobName = recorder.variable(
"////Upper/blob/empty /another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'",
"////Upper/blob/empty /adir/./adir1/../another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'",
getUniqueName(
"////Upper/blob/empty /another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'"
)
Expand Down
34 changes: 33 additions & 1 deletion sdk/storage/storage-blob/test/specialnaming.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// Licensed under the MIT license.

import { BlockBlobClient, BlobServiceClient } from "../src";
import { getBSU, getRecorderUniqueVariable, recorderEnvSetup, uriSanitizers } from "./utils/index";
import {
getBSU,
getRecorderUniqueVariable,
getUniqueName,
recorderEnvSetup,
uriSanitizers,
} from "./utils/index";
import { assert } from "chai";
import { appendToURLPath, EscapePath } from "../src/utils/utils.common";
import { Recorder } from "@azure-tools/test-recorder";
Expand Down Expand Up @@ -125,6 +131,32 @@ describe("Special Naming Tests", () => {
assert.notDeepEqual(response.segment.blobItems.length, 0);
});

it("Should work with special container and blob names with dots in blobname", async () => {
const blobName: string = recorder.variable(
"blobNameWithDots",
getUniqueName("/blobname/./blobname1/../blobname2/blobname3")
);
const blockBlobClient = new BlockBlobClient(
appendToURLPath(containerClient.url, blobName),
(containerClient as any).pipeline
);

await blockBlobClient.upload("A", 1);
await blockBlobClient.getProperties();

const prefix = "/blobname/blobname2/blobname3";
const response = (
await containerClient
.listBlobsFlat({
prefix: prefix,
})
.byPage()
.next()
).value;

assert.notDeepEqual(response.segment.blobItems.length, 0);
});

it("Should work with special container and blob names uppercase in URL string", async function () {
const blobName: string = getRecorderUniqueVariable(recorder, "////Upper/blob/empty /another");
const blockBlobClient = new BlockBlobClient(
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-file-datalake/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/storage/storage-file-datalake",
"Tag": "js/storage/storage-file-datalake_a9bfdb9d50"
"Tag": "js/storage/storage-file-datalake_2407e32cf2"
}
37 changes: 37 additions & 0 deletions sdk/storage/storage-file-datalake/test/filesystemclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,43 @@ describe("DataLakeFileSystemClient with soft delete", () => {
await directoryUndeleteResponse.pathClient.delete();
});

it("Undelete file and directory - with directory dots", async () => {
const fileBaseName = recorder.variable("file", getUniqueName(`file`));
const fileClient = fileSystemClient.getFileClient(fileBaseName);
await fileClient.create();
const fileDeleteResponse = await fileClient.delete();
assert.ok(fileDeleteResponse.deletionId);

const fileNameWithDirDots = "./adir/.././anotherdir/./../" + fileBaseName;

const fileundeleteResponse = await fileSystemClient.undeletePath(
fileNameWithDirDots,
fileDeleteResponse.deletionId ?? ""
);

assert.ok(fileundeleteResponse.pathClient instanceof DataLakeFileClient);

assert.ok(await fileundeleteResponse.pathClient.exists());
await fileundeleteResponse.pathClient.delete();

const directoryBaseName = recorder.variable("directory", getUniqueName(`directory`));
const directoryClient = fileSystemClient.getDirectoryClient(directoryBaseName);
await directoryClient.create();
const directoryDeleteResponse = await directoryClient.delete();
assert.ok(directoryDeleteResponse.deletionId);

const directoryNameWithDirDots = "./adir/.././anotherdir/./../" + directoryBaseName;
const directoryUndeleteResponse = await fileSystemClient.undeletePath(
directoryNameWithDirDots,
directoryDeleteResponse.deletionId ?? ""
);

assert.ok(directoryUndeleteResponse.pathClient instanceof DataLakeDirectoryClient);

assert.ok(await directoryUndeleteResponse.pathClient.exists());
await directoryUndeleteResponse.pathClient.delete();
});

it("Undelete file and directory - recreate and delete path and undelete the path with first deletionid", async () => {
const fileName = recorder.variable(`file`, getUniqueName(`file`));
const fileClient = fileSystemClient.getFileClient(fileName);
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-file-datalake/test/node/sas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
const fileName = recorder.variable(
"uniqueName",
getUniqueName(
"Upper file empty another 汉字 ру́сский язы́к ру́сский язы́к عرعربى にっぽんごにほんご . special ~!@#$%^&*()_+`1234567890-={}|[]:\";'<>?,'"
"./a/../Upper file empty another 汉字 ру́сский язы́к ру́сский язы́к عرعربى にっぽんごにほんご . special ~!@#$%^&*()_+`1234567890-={}|[]:\";'<>?,'"
)
);
const fileClient = fileSystemClient.getFileClient(fileName);
Expand Down
106 changes: 106 additions & 0 deletions sdk/storage/storage-file-datalake/test/pathclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,112 @@ describe("DataLakePathClient", () => {
await recorder.stop();
});

it("DataLakeFileClient create file path with directory dots", async () => {
const fileBaseName = recorder.variable("filename", getUniqueName("filename"));
const fileNameWithDots = "./adir/../anotherdir/.././" + fileBaseName;

const fileClientWithDirDots = fileSystemClient.getFileClient(fileNameWithDots);
await fileClientWithDirDots.create();

let foundFile: boolean = false;
for await (const listedFile of fileSystemClient.listPaths()) {
if (listedFile.name === fileBaseName && !listedFile.isDirectory) {
foundFile = true;
}
}

assert.ok(foundFile, "The file should have been created.");
});

it("DataLakeDirectoryClient create directory path with directory dots", async () => {
const subDirName = recorder.variable("dirname", getUniqueName("dirname"));
const subDirNameWithDots = "./adir/.././anotherdir/.././" + subDirName;
const subDirClient = fileSystemClient.getDirectoryClient(subDirNameWithDots);
await subDirClient.create();

let foundSubDir: boolean = false;

for await (const listedFile of fileSystemClient.listPaths()) {
if (listedFile.name === subDirName && listedFile.isDirectory) {
foundSubDir = true;
}
}

assert.ok(foundSubDir, "The directory should have been created.");
});

it("DataLakeFileClient create file path with directory dots under a dir", async () => {
const dirName = recorder.variable("dirname", getUniqueName("dirname"));
const dirClient = fileSystemClient.getDirectoryClient(dirName);
await dirClient.create();

const fileBaseName = recorder.variable("filename", getUniqueName("filename"));
const fileNameWithDots = "./adir/../anotherdir/.././" + fileBaseName;

const fileClientWithDirDots = dirClient.getFileClient(fileNameWithDots);
await fileClientWithDirDots.create();

let foundFile: boolean = false;
for await (const listedFile of fileSystemClient.listPaths({ path: dirName })) {
if (listedFile.name === `${dirName}/${fileBaseName}` && !listedFile.isDirectory) {
foundFile = true;
}
}

assert.ok(foundFile, "The file should have been created.");

const fileUnderRootDirBaseName = recorder.variable("filename1", getUniqueName("filename1"));
const fileUnderRootDir = "./adir/../../anotherdir/.././" + fileUnderRootDirBaseName;

const fileUnderRootDirClient = dirClient.getFileClient(fileUnderRootDir);
await fileUnderRootDirClient.create();

foundFile = false;
for await (const listedFile of fileSystemClient.listPaths()) {
if (listedFile.name === fileUnderRootDirBaseName && !listedFile.isDirectory) {
foundFile = true;
}
}

assert.ok(foundFile, "The file should have been created.");
});

it("DataLakeDirectoryClient create directory path with directory dots under a dir", async () => {
const dirName = recorder.variable("dirname", getUniqueName("dirname"));
const dirClient = fileSystemClient.getDirectoryClient(dirName);
await dirClient.create();

const subDirBaseName = recorder.variable("subdirname", getUniqueName("subdirname"));
const subDirNameWithDots = "./adir/../anotherdir/.././" + subDirBaseName;

const dirClientWithDirDots = dirClient.getSubdirectoryClient(subDirNameWithDots);
await dirClientWithDirDots.create();

let foundSubDir: boolean = false;
for await (const listedFile of fileSystemClient.listPaths({ path: dirName })) {
if (listedFile.name === `${dirName}/${subDirBaseName}` && listedFile.isDirectory) {
foundSubDir = true;
}
}

assert.ok(foundSubDir, "The directory should have been created.");

const dirUnderRootDirBaseName = recorder.variable("subdirname1", getUniqueName("subdirname1"));
const dirUnderRootDir = "./adir/../../anotherdir/.././" + dirUnderRootDirBaseName;

const fileUnderRootDirClient = dirClient.getSubdirectoryClient(dirUnderRootDir);
await fileUnderRootDirClient.create();

foundSubDir = false;
for await (const listedFile of fileSystemClient.listPaths()) {
if (listedFile.name === dirUnderRootDirBaseName && listedFile.isDirectory) {
foundSubDir = true;
}
}

assert.ok(foundSubDir, "The directory should have been created.");
});

it("DataLakeFileClient create with meta data", async () => {
const testFileName = recorder.variable("testfile", getUniqueName("testfile"));
const testFileClient = fileSystemClient.getFileClient(testFileName);
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-file-share/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/storage/storage-file-share",
"Tag": "js/storage/storage-file-share_82dfdd1fcb"
"Tag": "js/storage/storage-file-share_cc9d0fc982"
}
74 changes: 74 additions & 0 deletions sdk/storage/storage-file-share/test/fileclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,80 @@ describe("FileClient", () => {
await fileClient.uploadRange(content, fileSize - content.length, content.length);
});

it("create file - name with directory dots", async () => {
const fileBaseName = recorder.variable("filename", getUniqueName("filename"));
const fileNameWithDots = "./a/../" + fileBaseName;
const fileClientWithDirDots = dirClient.getFileClient(fileNameWithDots);
await fileClientWithDirDots.create(content.length);

let foundFile = false;
for await (const fileItem of dirClient.listFilesAndDirectories({ prefix: fileBaseName })) {
if (fileItem.name === fileBaseName && fileItem.kind === "file") {
foundFile = true;
}
}

assert.ok(foundFile, "The file should have been created.");

await fileClientWithDirDots.delete();

const fileShouldInRootDir = "./a/../../" + fileBaseName;
const fileClientShouldInRootDir = shareClient
.getDirectoryClient("anydir")
.getFileClient(fileShouldInRootDir);
await fileClientShouldInRootDir.create(content.length);

foundFile = false;
for await (const fileItem of shareClient
.getDirectoryClient("")
.listFilesAndDirectories({ prefix: fileBaseName })) {
if (fileItem.name === fileBaseName && fileItem.kind === "file") {
foundFile = true;
}
}

assert.ok(foundFile, "The file should have been created.");

await fileClientShouldInRootDir.delete();
});

it("create directory - name with directory dots", async () => {
const dirBaseName = recorder.variable("dirname1", getUniqueName("dirname1"));
const dirNameWithDots = "./a/../" + dirBaseName;
const dirClientWithDirDots = dirClient.getDirectoryClient(dirNameWithDots);
await dirClientWithDirDots.create();

let foundDir = false;
for await (const fileItem of dirClient.listFilesAndDirectories({ prefix: dirBaseName })) {
if (fileItem.name === dirBaseName && fileItem.kind === "directory") {
foundDir = true;
}
}

assert.ok(foundDir, "The directory should have been created.");

await dirClientWithDirDots.delete();

const dirShouldInRootDir = "./a/../../" + dirBaseName;
const dirClientShouldInRootDir = shareClient
.getDirectoryClient("anydir")
.getDirectoryClient(dirShouldInRootDir);
await dirClientShouldInRootDir.create();

foundDir = false;
for await (const fileItem of shareClient
.getDirectoryClient("")
.listFilesAndDirectories({ prefix: dirBaseName })) {
if (fileItem.name === dirBaseName && fileItem.kind === "directory") {
foundDir = true;
}
}

assert.ok(foundDir, "The file should have been created.");

await dirClientShouldInRootDir.delete();
});

it("setProperties with default parameters", async function () {
await fileClient.create(content.length);
await fileClient.setProperties();
Expand Down

0 comments on commit 84aeb3d

Please sign in to comment.