mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 20:01:36 +00:00
570 lines
20 KiB
TypeScript
570 lines
20 KiB
TypeScript
const hash = require("../../src/utils/hashHelper");
|
|
|
|
const ids: { [key: string]: string } = {
|
|
file: "1K_KyC8B54En7UaD3_o7zubxwG4jtXTVK",
|
|
folder: "12fKI0g0Uvkubk1sSHCd_SDErLyc9TlWe",
|
|
protectedFolder: "1p6znx1BKPsqFnyOPw49uhoc8FNglfYnD",
|
|
protectedFile: "1NK-J1QIf0vuGnDIEHXBG2-9jXP6sKCuN",
|
|
protectedSubFolder: "1_N87OSlhPYfC3L1fGfE546LoJnCK8zBX",
|
|
protectedSubFile: "1CSKTtgXunrSHYRRp8FyMXYpNP6xK1iju",
|
|
protectedInsideProtected: "1VMU0sQOkuI06icRRJFof-6V-NLyBWlp5",
|
|
protectedFileInsideProtected: "1wXsNhp8JxOc8iBRyb98PkR1G_MijE2e0",
|
|
};
|
|
|
|
describe("Files API", () => {
|
|
it("Get root files", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: "/api/files",
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(false);
|
|
expect(response.body.passwordValidated).to.satisfy(
|
|
(key: any) => key === true || key === undefined,
|
|
);
|
|
expect(response.body.protectedId).to.eq(undefined);
|
|
expect(response.body.folders).to.have.length.at.least(0);
|
|
expect(response.body.files).to.have.length.at.least(0);
|
|
expect(response.body.readmeExists).to.be.a("boolean");
|
|
expect(response.body.nextPageToken).to.satisfy(
|
|
(key: any) => typeof key === "string" || key === undefined,
|
|
);
|
|
});
|
|
});
|
|
|
|
it("Get file", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${ids.file}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(false);
|
|
expect(response.body.passwordValidated).to.satisfy(
|
|
(key: any) => key === true || key === undefined,
|
|
);
|
|
expect(response.body.protectedId).to.eq(undefined);
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.file).to.have.property("id");
|
|
});
|
|
});
|
|
|
|
it("Get folder", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${ids.folder}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(false);
|
|
expect(response.body.passwordValidated).to.satisfy(
|
|
(key: any) => key === true || key === undefined,
|
|
);
|
|
expect(response.body.protectedId).to.eq(undefined);
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.folders).to.have.length.at.least(0);
|
|
expect(response.body.files).to.have.length.at.least(0);
|
|
expect(response.body.readmeExists).to.be.a("boolean");
|
|
expect(response.body.nextPageToken).to.satisfy(
|
|
(key: any) => typeof key === "string" || key === undefined,
|
|
);
|
|
});
|
|
});
|
|
|
|
it("View file", () => {
|
|
// Test if file returning a binary
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${ids.file}/view`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
expect(response.headers)
|
|
.have.property("content-disposition")
|
|
.contains("inline");
|
|
});
|
|
});
|
|
|
|
it("Download file", () => {
|
|
// Test if file returning a binary
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${ids.file}/download`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
expect(response.headers)
|
|
.have.property("content-disposition")
|
|
.contains("attachment");
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Protected files API", () => {
|
|
const folder = ids.protectedFolder;
|
|
const file = ids.protectedFile;
|
|
it("Get protected folder - without password", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected folder - wrong password", () => {
|
|
const hashPassword = hash.hashToken("wrong password");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected folder - with password", () => {
|
|
const hashPassword = hash.hashToken("loremipsum");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(true);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.folders).to.have.length.at.least(0);
|
|
expect(response.body.files).to.have.length.at.least(0);
|
|
expect(response.body.readmeExists).to.be.a("boolean");
|
|
expect(response.body.nextPageToken).to.satisfy(
|
|
(key: any) => typeof key === "string" || key === undefined,
|
|
);
|
|
});
|
|
});
|
|
|
|
it("Get protected file - without password", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected file - wrong password", () => {
|
|
const hashPassword = hash.hashToken("wrong password");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected file - with password", () => {
|
|
const hashPassword = hash.hashToken("loremipsum");
|
|
// The file is in a protected folder, so the password is the same
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(true);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.file).to.have.property("id");
|
|
});
|
|
});
|
|
|
|
it("View protected file - without token", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
});
|
|
it("View protected file - with wrong token", () => {
|
|
const hashPassword = hash.hashToken("wrongpassword");
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view?hash=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/download?hash=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
});
|
|
it("View protected file - with token", () => {
|
|
const hashPassword = hash.hashToken("loremipsum");
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view?token=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
// expect(response.headers)
|
|
// .have.property("content-disposition")
|
|
// .contains("inline");
|
|
});
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/download?token=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
// expect(response.headers)
|
|
// .have.property("content-disposition")
|
|
// .contains("attachment");
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Protected files sub folder API", () => {
|
|
const folder = ids.protectedSubFolder;
|
|
const file = ids.protectedSubFile;
|
|
it("Get protected folder - without password", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected folder - wrong password", () => {
|
|
const hashPassword = hash.hashToken("wrong password");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected folder - with password", () => {
|
|
const hashPassword = hash.hashToken("loremipsum");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(true);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.folders).to.have.length.at.least(0);
|
|
expect(response.body.files).to.have.length.at.least(0);
|
|
expect(response.body.readmeExists).to.be.a("boolean");
|
|
expect(response.body.nextPageToken).to.satisfy(
|
|
(key: any) => typeof key === "string" || key === undefined,
|
|
);
|
|
});
|
|
});
|
|
|
|
it("Get protected file - without password", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected file - wrong password", () => {
|
|
const hashPassword = hash.hashToken("wrong password");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected file - with password", () => {
|
|
const hashPassword = hash.hashToken("loremipsum");
|
|
// The file is in a protected folder, so the password is the same
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(true);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.file).to.have.property("id");
|
|
});
|
|
});
|
|
|
|
it("View protected file - without token", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
});
|
|
it("View protected file - with wrong token", () => {
|
|
const hashPassword = hash.hashToken("wrongpassword");
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view?hash=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/download?hash=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
});
|
|
it("View protected file - with token", () => {
|
|
const hashPassword = hash.hashToken("loremipsum");
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view?token=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
// expect(response.headers)
|
|
// .have.property("content-disposition")
|
|
// .contains("inline");
|
|
});
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/download?token=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
// expect(response.headers)
|
|
// .have.property("content-disposition")
|
|
// .contains("attachment");
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Protected files inside protected API", () => {
|
|
const folder = ids.protectedInsideProtected;
|
|
const file = ids.protectedFileInsideProtected;
|
|
it("Get protected folder - without password", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected folder - wrong password", () => {
|
|
const hashPassword = hash.hashToken("wrong password");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected folder - with password", () => {
|
|
const hashPassword = hash.hashToken("123");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${folder}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(true);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.folders).to.have.length.at.least(0);
|
|
expect(response.body.files).to.have.length.at.least(0);
|
|
expect(response.body.readmeExists).to.be.a("boolean");
|
|
expect(response.body.nextPageToken).to.satisfy(
|
|
(key: any) => typeof key === "string" || key === undefined,
|
|
);
|
|
});
|
|
});
|
|
|
|
it("Get protected file - without password", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected file - wrong password", () => {
|
|
const hashPassword = hash.hashToken("wrong password");
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
});
|
|
});
|
|
it("Get protected file - with password", () => {
|
|
const hashPassword = hash.hashToken("123");
|
|
// The file is in a protected folder, so the password is the same
|
|
cy.request({
|
|
method: "GET",
|
|
url: `/api/files/${file}`,
|
|
headers: {
|
|
Authorization: `Bearer ${hashPassword}`,
|
|
},
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(true);
|
|
expect(response.body.protectedId).to.be.a("string");
|
|
expect(response.body.parents).to.have.length.at.least(0);
|
|
expect(response.body.file).to.have.property("id");
|
|
});
|
|
});
|
|
|
|
it("View protected file - without token", () => {
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
});
|
|
it("View protected file - with wrong token", () => {
|
|
const hashPassword = hash.hashToken("wrongpassword");
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view?hash=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/download?hash=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.passwordRequired).to.eq(true);
|
|
expect(response.body.passwordValidated).to.eq(false);
|
|
});
|
|
});
|
|
it("View protected file - with token", () => {
|
|
const hashPassword = hash.hashToken("123");
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/view?token=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
// expect(response.headers)
|
|
// .have.property("content-disposition")
|
|
// .contains("inline");
|
|
});
|
|
cy.request({
|
|
method: "GET",
|
|
encoding: "binary",
|
|
url: `/api/files/${file}/download?token=${hashPassword}`,
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers).have.property("content-type");
|
|
// expect(response.headers)
|
|
// .have.property("content-disposition")
|
|
// .contains("attachment");
|
|
});
|
|
});
|
|
});
|