🐛Sharing files doesn't work for the files and folders from "My Drive" (#143)
🐛small fix on the token expiration also
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, beforeEach, afterEach, it, expect, afterAll } from "@jest/globals";
|
||||
import { describe, beforeEach, it, expect, afterAll } from "@jest/globals";
|
||||
import { deserialize } from "class-transformer";
|
||||
import { File } from "../../../src/services/files/entities/file";
|
||||
import { ResourceUpdateResponse } from "../../../src/utils/types";
|
||||
@@ -236,7 +236,6 @@ describe("the Drive feature", () => {
|
||||
|
||||
//then::
|
||||
expect(searchResponse.entities?.length).toEqual(1);
|
||||
const actual = searchResponse.entities[0];
|
||||
})
|
||||
|
||||
it("did search for an item that doesn't exist", async () => {
|
||||
@@ -280,9 +279,7 @@ describe("the Drive feature", () => {
|
||||
it("did search by mime type", async () => {
|
||||
jest.setTimeout(10000);
|
||||
// given:: all the sample files uploaded and documents for them created
|
||||
await Promise.all(
|
||||
(await currentUser.uploadFiles()).map(f => currentUser.createDocumentFromFile(f)),
|
||||
);
|
||||
await currentUser.uploadAllFilesOneByOne();
|
||||
|
||||
const filters = {
|
||||
mime_type: "application/pdf",
|
||||
|
||||
@@ -6,6 +6,8 @@ import { DriveFileAccessLevel, DriveItemDetails } from "../../../src/services/do
|
||||
import { init, TestPlatform } from "../setup";
|
||||
import { TestDbService } from "../utils.prepare.db";
|
||||
import { e2e_createDocument, e2e_updateDocument } from "./utils";
|
||||
import TestHelpers from "../common/common_test_helpers";
|
||||
import { AccessTokenMockClass } from "../common/entities/mock_entities";
|
||||
|
||||
const url = "/internal/services/documents/v1";
|
||||
|
||||
@@ -22,17 +24,6 @@ describe("the public links feature", () => {
|
||||
access_info: AccessInformation;
|
||||
}
|
||||
|
||||
class AccessTokenMockClass {
|
||||
access_token: {
|
||||
time: 0;
|
||||
expiration: number;
|
||||
refresh_expiration: number;
|
||||
value: string;
|
||||
refresh: string;
|
||||
type: "Bearer";
|
||||
};
|
||||
}
|
||||
|
||||
class FullDriveInfoMockClass {
|
||||
path: DriveFile[];
|
||||
item?: DriveFile;
|
||||
@@ -71,221 +62,251 @@ describe("the public links feature", () => {
|
||||
platform = null;
|
||||
});
|
||||
|
||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
|
||||
const item = {
|
||||
name: "public file",
|
||||
parent_id: "root",
|
||||
company_id: platform.workspace.company_id,
|
||||
describe("Basic Flow", () => {
|
||||
|
||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
|
||||
const item = {
|
||||
name: "public file",
|
||||
parent_id: "root",
|
||||
company_id: platform.workspace.company_id,
|
||||
};
|
||||
|
||||
const version = {};
|
||||
|
||||
const response = await e2e_createDocument(platform, item, version);
|
||||
return deserialize<DriveFileMockClass>(DriveFileMockClass, response.body);
|
||||
};
|
||||
|
||||
const version = {};
|
||||
let publicFile: DriveFileMockClass;
|
||||
|
||||
const response = await e2e_createDocument(platform, item, version);
|
||||
return deserialize<DriveFileMockClass>(DriveFileMockClass, response.body);
|
||||
};
|
||||
it("did create the drive item", async () => {
|
||||
const result = await createItem();
|
||||
publicFile = result;
|
||||
|
||||
let publicFile: DriveFileMockClass;
|
||||
|
||||
it("did create the drive item", async () => {
|
||||
const result = await createItem();
|
||||
publicFile = result;
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.name).toEqual("public file");
|
||||
expect(result.added).toBeDefined();
|
||||
expect(result.access_info).toBeDefined();
|
||||
});
|
||||
|
||||
it("unable to access non public file", async () => {
|
||||
const res = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}?public_token=${publicFile.access_info.public?.token}`,
|
||||
headers: {},
|
||||
expect(result).toBeDefined();
|
||||
expect(result.name).toEqual("public file");
|
||||
expect(result.added).toBeDefined();
|
||||
expect(result.access_info).toBeDefined();
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
it("unable to access non public file", async () => {
|
||||
const res = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}?public_token=${publicFile.access_info.public?.token}`,
|
||||
headers: {},
|
||||
});
|
||||
|
||||
it("should access public file", async () => {
|
||||
const res = await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
|
||||
it("should access public file", async () => {
|
||||
const res = await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const file = deserialize<DriveFileMockClass>(DriveFileMockClass, res.body);
|
||||
expect(file.access_info.public?.level).toBe("read");
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const file = deserialize<DriveFileMockClass>(DriveFileMockClass, res.body);
|
||||
expect(file.access_info.public?.level).toBe("read");
|
||||
|
||||
const accessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
},
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
expect(access_token).toBeDefined();
|
||||
|
||||
const resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
const resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
});
|
||||
|
||||
it("unable to access expired public file link", async () => {
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expiration: Date.now() + 1000 * 60, //In the future
|
||||
const accessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
expect(access_token).toBeDefined();
|
||||
|
||||
const accessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
},
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
|
||||
let resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
const resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expiration: 123, //In the past
|
||||
const resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
const resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
});
|
||||
|
||||
resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
expect(resPublicRaw.statusCode).toBe(401);
|
||||
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expiration: 0, //Reset to default
|
||||
it("unable to access expired public file link", async () => {
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expiration: Date.now() + 1000 * 60, //In the future
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const accessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
},
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
|
||||
let resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
const resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expiration: 123, //In the past
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
expect(resPublicRaw.statusCode).toBe(401);
|
||||
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
expiration: 0, //Reset to default
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("access public file link with password", async () => {
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
password: "abcdef",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const badAccessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
},
|
||||
});
|
||||
expect(badAccessRes.statusCode).toBe(401);
|
||||
|
||||
const accessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
token_password: "abcdef",
|
||||
},
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
|
||||
let resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
let resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
password: "",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("access public file link with password", async () => {
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
password: "abcdef",
|
||||
},
|
||||
},
|
||||
describe("Share file from My Drive", () => {
|
||||
|
||||
it("Share file from some folder", async () => {
|
||||
const user = await TestHelpers.getInstance(platform, true);
|
||||
const anotherUser = await TestHelpers.getInstance(platform, true);
|
||||
|
||||
//create directory in "My Drive" and upload a file
|
||||
const directory = await user.createDirectory("user_" + user.user.id);
|
||||
const doc = await user.createRandomDocument(directory.id);
|
||||
|
||||
//check that another user doesn't see any file
|
||||
expect((await anotherUser.getDocument(doc.id)).statusCode).toBe(401);
|
||||
|
||||
//share file with the public link
|
||||
await user.shareWithPublicLink(doc, "read");
|
||||
|
||||
const token = await anotherUser.getPublicLinkAccessToken(doc);
|
||||
|
||||
anotherUser.jwt = token.value;
|
||||
await anotherUser.getDocumentOKCheck(doc.id);
|
||||
|
||||
});
|
||||
|
||||
const badAccessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
},
|
||||
});
|
||||
expect(badAccessRes.statusCode).toBe(401);
|
||||
|
||||
const accessRes = await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: publicFile.company_id,
|
||||
document_id: publicFile.id,
|
||||
token: publicFile.access_info.public?.token,
|
||||
token_password: "abcdef",
|
||||
},
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
|
||||
let resPublicRaw = await platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||
headers: {
|
||||
Authorization: `Bearer ${access_token.value}`,
|
||||
},
|
||||
});
|
||||
let resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||
expect(resPublicRaw.statusCode).toBe(200);
|
||||
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||
|
||||
await e2e_updateDocument(platform, publicFile.id, {
|
||||
...publicFile,
|
||||
access_info: {
|
||||
...publicFile.access_info,
|
||||
public: {
|
||||
...publicFile.access_info.public!,
|
||||
level: "read",
|
||||
password: "",
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DriveFile } from "../../../src/services/documents/entities/drive-file";
|
||||
import { FileVersion } from "../../../src/services/documents/entities/file-version";
|
||||
import { TestPlatform } from "../setup";
|
||||
import formAutoContent from "form-auto-content";
|
||||
import fs from "fs";
|
||||
import * as fs from "fs";
|
||||
|
||||
const url = "/internal/services/documents/v1";
|
||||
|
||||
@@ -73,7 +73,7 @@ export const e2e_searchDocument = async (
|
||||
) => {
|
||||
const token = await platform.auth.getJWTToken();
|
||||
|
||||
const response = await platform.app.inject({
|
||||
return await platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${url}/companies/${platform.workspace.company_id}/search`,
|
||||
headers: {
|
||||
@@ -81,8 +81,6 @@ export const e2e_searchDocument = async (
|
||||
},
|
||||
payload,
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export const e2e_createVersion = async (
|
||||
|
||||
Reference in New Issue
Block a user