mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 13:38:38 +00:00
Passing all files api testing
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="261" name="TypeScript" />
|
||||
<language minSize="743" name="TypeScript" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
# Currently in Development
|
||||
This project is currently in development, and not ready for deployment yet.
|
||||
|
||||
---
|
||||
|
||||
// LOGO OR BANNER GOES HERE
|
||||
|
||||
## What is this?
|
||||
|
||||
@@ -0,0 +1,569 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,120 +0,0 @@
|
||||
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("Get protected folder - without password", () => {
|
||||
cy.request({
|
||||
method: "GET",
|
||||
url: `/api/files/${ids.protectedFolder}`,
|
||||
}).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/${ids.protectedFolder}`,
|
||||
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/${ids.protectedFolder}`,
|
||||
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,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,16 @@ export default function Footer() {
|
||||
return (
|
||||
<div className='flex w-full items-center justify-center gap-2 py-1'>
|
||||
<span className='text-xs font-semibold'>
|
||||
{currentYear} - {siteConfig.footerText} ❤️
|
||||
{currentYear} {siteConfig.footerText} - Powered by{" "}
|
||||
<a
|
||||
className={"link"}
|
||||
href={"https://www.github.com/mbaharip/gudora-index"}
|
||||
target={"blank"}
|
||||
rel={"noreferrer noopener"}
|
||||
>
|
||||
gudora-index
|
||||
</a>{" "}
|
||||
❤️
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ export default async function handler(
|
||||
|
||||
// Check for password file
|
||||
const validatePassword = await validateProtected(
|
||||
parentsArray[0].id,
|
||||
parentsArray,
|
||||
(headerHash as string) || (hash as string),
|
||||
);
|
||||
if (validatePassword.isProtected && !validatePassword.valid) {
|
||||
|
||||
@@ -55,7 +55,7 @@ export default async function handler(
|
||||
|
||||
// Check for password file
|
||||
const validatePassword = await validateProtected(
|
||||
parentsArray[0].id,
|
||||
parentsArray,
|
||||
(headerHash as string) || (hash as string),
|
||||
);
|
||||
if (validatePassword.isProtected && !validatePassword.valid) {
|
||||
|
||||
Reference in New Issue
Block a user