Skip to content

Commit 84aeb3d

Browse files
authored
[Storage] port PR Azure#24953 from storage/stable branch (Azure#26279)
Azure#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
1 parent c6d7472 commit 84aeb3d

File tree

9 files changed

+255
-6
lines changed

9 files changed

+255
-6
lines changed

sdk/storage/storage-blob/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "js",
44
"TagPrefix": "js/storage/storage-blob",
5-
"Tag": "js/storage/storage-blob_5d5a32b74a"
5+
"Tag": "js/storage/storage-blob_8c8488b395"
66
}

sdk/storage/storage-blob/test/node/sas.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
797797

798798
// NOTICE: Azure Storage Server will replace "\" with "/" in the blob names
799799
const blobName = recorder.variable(
800-
"////Upper/blob/empty /another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'",
800+
"////Upper/blob/empty /adir/./adir1/../another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'",
801801
getUniqueName(
802802
"////Upper/blob/empty /another 汉字 ру́сский язы́к ру́сский язы́к عربي/عربى にっぽんご/にほんご . special ~!@#$%^&*()_+`1234567890-={}|[]\\:\";'<>?,/'"
803803
)

sdk/storage/storage-blob/test/specialnaming.spec.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
// Licensed under the MIT license.
33

44
import { BlockBlobClient, BlobServiceClient } from "../src";
5-
import { getBSU, getRecorderUniqueVariable, recorderEnvSetup, uriSanitizers } from "./utils/index";
5+
import {
6+
getBSU,
7+
getRecorderUniqueVariable,
8+
getUniqueName,
9+
recorderEnvSetup,
10+
uriSanitizers,
11+
} from "./utils/index";
612
import { assert } from "chai";
713
import { appendToURLPath, EscapePath } from "../src/utils/utils.common";
814
import { Recorder } from "@azure-tools/test-recorder";
@@ -125,6 +131,32 @@ describe("Special Naming Tests", () => {
125131
assert.notDeepEqual(response.segment.blobItems.length, 0);
126132
});
127133

134+
it("Should work with special container and blob names with dots in blobname", async () => {
135+
const blobName: string = recorder.variable(
136+
"blobNameWithDots",
137+
getUniqueName("/blobname/./blobname1/../blobname2/blobname3")
138+
);
139+
const blockBlobClient = new BlockBlobClient(
140+
appendToURLPath(containerClient.url, blobName),
141+
(containerClient as any).pipeline
142+
);
143+
144+
await blockBlobClient.upload("A", 1);
145+
await blockBlobClient.getProperties();
146+
147+
const prefix = "/blobname/blobname2/blobname3";
148+
const response = (
149+
await containerClient
150+
.listBlobsFlat({
151+
prefix: prefix,
152+
})
153+
.byPage()
154+
.next()
155+
).value;
156+
157+
assert.notDeepEqual(response.segment.blobItems.length, 0);
158+
});
159+
128160
it("Should work with special container and blob names uppercase in URL string", async function () {
129161
const blobName: string = getRecorderUniqueVariable(recorder, "////Upper/blob/empty /another");
130162
const blockBlobClient = new BlockBlobClient(

sdk/storage/storage-file-datalake/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "js",
44
"TagPrefix": "js/storage/storage-file-datalake",
5-
"Tag": "js/storage/storage-file-datalake_a9bfdb9d50"
5+
"Tag": "js/storage/storage-file-datalake_2407e32cf2"
66
}

sdk/storage/storage-file-datalake/test/filesystemclient.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,43 @@ describe("DataLakeFileSystemClient with soft delete", () => {
10291029
await directoryUndeleteResponse.pathClient.delete();
10301030
});
10311031

1032+
it("Undelete file and directory - with directory dots", async () => {
1033+
const fileBaseName = recorder.variable("file", getUniqueName(`file`));
1034+
const fileClient = fileSystemClient.getFileClient(fileBaseName);
1035+
await fileClient.create();
1036+
const fileDeleteResponse = await fileClient.delete();
1037+
assert.ok(fileDeleteResponse.deletionId);
1038+
1039+
const fileNameWithDirDots = "./adir/.././anotherdir/./../" + fileBaseName;
1040+
1041+
const fileundeleteResponse = await fileSystemClient.undeletePath(
1042+
fileNameWithDirDots,
1043+
fileDeleteResponse.deletionId ?? ""
1044+
);
1045+
1046+
assert.ok(fileundeleteResponse.pathClient instanceof DataLakeFileClient);
1047+
1048+
assert.ok(await fileundeleteResponse.pathClient.exists());
1049+
await fileundeleteResponse.pathClient.delete();
1050+
1051+
const directoryBaseName = recorder.variable("directory", getUniqueName(`directory`));
1052+
const directoryClient = fileSystemClient.getDirectoryClient(directoryBaseName);
1053+
await directoryClient.create();
1054+
const directoryDeleteResponse = await directoryClient.delete();
1055+
assert.ok(directoryDeleteResponse.deletionId);
1056+
1057+
const directoryNameWithDirDots = "./adir/.././anotherdir/./../" + directoryBaseName;
1058+
const directoryUndeleteResponse = await fileSystemClient.undeletePath(
1059+
directoryNameWithDirDots,
1060+
directoryDeleteResponse.deletionId ?? ""
1061+
);
1062+
1063+
assert.ok(directoryUndeleteResponse.pathClient instanceof DataLakeDirectoryClient);
1064+
1065+
assert.ok(await directoryUndeleteResponse.pathClient.exists());
1066+
await directoryUndeleteResponse.pathClient.delete();
1067+
});
1068+
10321069
it("Undelete file and directory - recreate and delete path and undelete the path with first deletionid", async () => {
10331070
const fileName = recorder.variable(`file`, getUniqueName(`file`));
10341071
const fileClient = fileSystemClient.getFileClient(fileName);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => {
484484
const fileName = recorder.variable(
485485
"uniqueName",
486486
getUniqueName(
487-
"Upper file empty another 汉字 ру́сский язы́к ру́сский язы́к عرعربى にっぽんごにほんご . special ~!@#$%^&*()_+`1234567890-={}|[]:\";'<>?,'"
487+
"./a/../Upper file empty another 汉字 ру́сский язы́к ру́сский язы́к عرعربى にっぽんごにほんご . special ~!@#$%^&*()_+`1234567890-={}|[]:\";'<>?,'"
488488
)
489489
);
490490
const fileClient = fileSystemClient.getFileClient(fileName);

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

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,112 @@ describe("DataLakePathClient", () => {
5050
await recorder.stop();
5151
});
5252

53+
it("DataLakeFileClient create file path with directory dots", async () => {
54+
const fileBaseName = recorder.variable("filename", getUniqueName("filename"));
55+
const fileNameWithDots = "./adir/../anotherdir/.././" + fileBaseName;
56+
57+
const fileClientWithDirDots = fileSystemClient.getFileClient(fileNameWithDots);
58+
await fileClientWithDirDots.create();
59+
60+
let foundFile: boolean = false;
61+
for await (const listedFile of fileSystemClient.listPaths()) {
62+
if (listedFile.name === fileBaseName && !listedFile.isDirectory) {
63+
foundFile = true;
64+
}
65+
}
66+
67+
assert.ok(foundFile, "The file should have been created.");
68+
});
69+
70+
it("DataLakeDirectoryClient create directory path with directory dots", async () => {
71+
const subDirName = recorder.variable("dirname", getUniqueName("dirname"));
72+
const subDirNameWithDots = "./adir/.././anotherdir/.././" + subDirName;
73+
const subDirClient = fileSystemClient.getDirectoryClient(subDirNameWithDots);
74+
await subDirClient.create();
75+
76+
let foundSubDir: boolean = false;
77+
78+
for await (const listedFile of fileSystemClient.listPaths()) {
79+
if (listedFile.name === subDirName && listedFile.isDirectory) {
80+
foundSubDir = true;
81+
}
82+
}
83+
84+
assert.ok(foundSubDir, "The directory should have been created.");
85+
});
86+
87+
it("DataLakeFileClient create file path with directory dots under a dir", async () => {
88+
const dirName = recorder.variable("dirname", getUniqueName("dirname"));
89+
const dirClient = fileSystemClient.getDirectoryClient(dirName);
90+
await dirClient.create();
91+
92+
const fileBaseName = recorder.variable("filename", getUniqueName("filename"));
93+
const fileNameWithDots = "./adir/../anotherdir/.././" + fileBaseName;
94+
95+
const fileClientWithDirDots = dirClient.getFileClient(fileNameWithDots);
96+
await fileClientWithDirDots.create();
97+
98+
let foundFile: boolean = false;
99+
for await (const listedFile of fileSystemClient.listPaths({ path: dirName })) {
100+
if (listedFile.name === `${dirName}/${fileBaseName}` && !listedFile.isDirectory) {
101+
foundFile = true;
102+
}
103+
}
104+
105+
assert.ok(foundFile, "The file should have been created.");
106+
107+
const fileUnderRootDirBaseName = recorder.variable("filename1", getUniqueName("filename1"));
108+
const fileUnderRootDir = "./adir/../../anotherdir/.././" + fileUnderRootDirBaseName;
109+
110+
const fileUnderRootDirClient = dirClient.getFileClient(fileUnderRootDir);
111+
await fileUnderRootDirClient.create();
112+
113+
foundFile = false;
114+
for await (const listedFile of fileSystemClient.listPaths()) {
115+
if (listedFile.name === fileUnderRootDirBaseName && !listedFile.isDirectory) {
116+
foundFile = true;
117+
}
118+
}
119+
120+
assert.ok(foundFile, "The file should have been created.");
121+
});
122+
123+
it("DataLakeDirectoryClient create directory path with directory dots under a dir", async () => {
124+
const dirName = recorder.variable("dirname", getUniqueName("dirname"));
125+
const dirClient = fileSystemClient.getDirectoryClient(dirName);
126+
await dirClient.create();
127+
128+
const subDirBaseName = recorder.variable("subdirname", getUniqueName("subdirname"));
129+
const subDirNameWithDots = "./adir/../anotherdir/.././" + subDirBaseName;
130+
131+
const dirClientWithDirDots = dirClient.getSubdirectoryClient(subDirNameWithDots);
132+
await dirClientWithDirDots.create();
133+
134+
let foundSubDir: boolean = false;
135+
for await (const listedFile of fileSystemClient.listPaths({ path: dirName })) {
136+
if (listedFile.name === `${dirName}/${subDirBaseName}` && listedFile.isDirectory) {
137+
foundSubDir = true;
138+
}
139+
}
140+
141+
assert.ok(foundSubDir, "The directory should have been created.");
142+
143+
const dirUnderRootDirBaseName = recorder.variable("subdirname1", getUniqueName("subdirname1"));
144+
const dirUnderRootDir = "./adir/../../anotherdir/.././" + dirUnderRootDirBaseName;
145+
146+
const fileUnderRootDirClient = dirClient.getSubdirectoryClient(dirUnderRootDir);
147+
await fileUnderRootDirClient.create();
148+
149+
foundSubDir = false;
150+
for await (const listedFile of fileSystemClient.listPaths()) {
151+
if (listedFile.name === dirUnderRootDirBaseName && listedFile.isDirectory) {
152+
foundSubDir = true;
153+
}
154+
}
155+
156+
assert.ok(foundSubDir, "The directory should have been created.");
157+
});
158+
53159
it("DataLakeFileClient create with meta data", async () => {
54160
const testFileName = recorder.variable("testfile", getUniqueName("testfile"));
55161
const testFileClient = fileSystemClient.getFileClient(testFileName);

sdk/storage/storage-file-share/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "js",
44
"TagPrefix": "js/storage/storage-file-share",
5-
"Tag": "js/storage/storage-file-share_82dfdd1fcb"
5+
"Tag": "js/storage/storage-file-share_cc9d0fc982"
66
}

sdk/storage/storage-file-share/test/fileclient.spec.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,80 @@ describe("FileClient", () => {
177177
await fileClient.uploadRange(content, fileSize - content.length, content.length);
178178
});
179179

180+
it("create file - name with directory dots", async () => {
181+
const fileBaseName = recorder.variable("filename", getUniqueName("filename"));
182+
const fileNameWithDots = "./a/../" + fileBaseName;
183+
const fileClientWithDirDots = dirClient.getFileClient(fileNameWithDots);
184+
await fileClientWithDirDots.create(content.length);
185+
186+
let foundFile = false;
187+
for await (const fileItem of dirClient.listFilesAndDirectories({ prefix: fileBaseName })) {
188+
if (fileItem.name === fileBaseName && fileItem.kind === "file") {
189+
foundFile = true;
190+
}
191+
}
192+
193+
assert.ok(foundFile, "The file should have been created.");
194+
195+
await fileClientWithDirDots.delete();
196+
197+
const fileShouldInRootDir = "./a/../../" + fileBaseName;
198+
const fileClientShouldInRootDir = shareClient
199+
.getDirectoryClient("anydir")
200+
.getFileClient(fileShouldInRootDir);
201+
await fileClientShouldInRootDir.create(content.length);
202+
203+
foundFile = false;
204+
for await (const fileItem of shareClient
205+
.getDirectoryClient("")
206+
.listFilesAndDirectories({ prefix: fileBaseName })) {
207+
if (fileItem.name === fileBaseName && fileItem.kind === "file") {
208+
foundFile = true;
209+
}
210+
}
211+
212+
assert.ok(foundFile, "The file should have been created.");
213+
214+
await fileClientShouldInRootDir.delete();
215+
});
216+
217+
it("create directory - name with directory dots", async () => {
218+
const dirBaseName = recorder.variable("dirname1", getUniqueName("dirname1"));
219+
const dirNameWithDots = "./a/../" + dirBaseName;
220+
const dirClientWithDirDots = dirClient.getDirectoryClient(dirNameWithDots);
221+
await dirClientWithDirDots.create();
222+
223+
let foundDir = false;
224+
for await (const fileItem of dirClient.listFilesAndDirectories({ prefix: dirBaseName })) {
225+
if (fileItem.name === dirBaseName && fileItem.kind === "directory") {
226+
foundDir = true;
227+
}
228+
}
229+
230+
assert.ok(foundDir, "The directory should have been created.");
231+
232+
await dirClientWithDirDots.delete();
233+
234+
const dirShouldInRootDir = "./a/../../" + dirBaseName;
235+
const dirClientShouldInRootDir = shareClient
236+
.getDirectoryClient("anydir")
237+
.getDirectoryClient(dirShouldInRootDir);
238+
await dirClientShouldInRootDir.create();
239+
240+
foundDir = false;
241+
for await (const fileItem of shareClient
242+
.getDirectoryClient("")
243+
.listFilesAndDirectories({ prefix: dirBaseName })) {
244+
if (fileItem.name === dirBaseName && fileItem.kind === "directory") {
245+
foundDir = true;
246+
}
247+
}
248+
249+
assert.ok(foundDir, "The file should have been created.");
250+
251+
await dirClientShouldInRootDir.delete();
252+
});
253+
180254
it("setProperties with default parameters", async function () {
181255
await fileClient.create(content.length);
182256
await fileClient.setProperties();

0 commit comments

Comments
 (0)