🐛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:
@@ -160,9 +160,10 @@ export const getAccessLevel = async (
|
||||
if (id === "shared_with_me") return "read";
|
||||
|
||||
//If it is my personal folder, I have full access
|
||||
if (context?.user?.id && id.startsWith("user_")) {
|
||||
if (id.startsWith("user_")) {
|
||||
if (id === "user_" + context.user?.id) return "manage";
|
||||
if (await isCompanyApplication(context)) return "manage";
|
||||
return "none";
|
||||
}
|
||||
|
||||
let publicToken = context.public_token;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
// @ts-ignore
|
||||
import fs from "fs";
|
||||
import {ResourceUpdateResponse, Workspace} from "../../../src/utils/types";
|
||||
import {File} from "../../../src/services/files/entities/file";
|
||||
import {deserialize} from "class-transformer";
|
||||
import { ResourceUpdateResponse, Workspace } from "../../../src/utils/types";
|
||||
import { File } from "../../../src/services/files/entities/file";
|
||||
import { deserialize } from "class-transformer";
|
||||
import formAutoContent from "form-auto-content";
|
||||
import {TestPlatform, User} from "../setup";
|
||||
import {v1 as uuidv1} from "uuid";
|
||||
import {TestDbService} from "../utils.prepare.db";
|
||||
import {DriveFile} from "../../../src/services/documents/entities/drive-file";
|
||||
import {FileVersion} from "../../../src/services/documents/entities/file-version";
|
||||
import { DriveItemDetailsMockClass, SearchResultMockClass } from "./entities/mock_entities";
|
||||
import {logger} from "../../../src/core/platform/framework";
|
||||
import { TestPlatform, User } from "../setup";
|
||||
import { v1 as uuidv1 } from "uuid";
|
||||
import { TestDbService } from "../utils.prepare.db";
|
||||
import { DriveFile } from "../../../src/services/documents/entities/drive-file";
|
||||
import { FileVersion } from "../../../src/services/documents/entities/file-version";
|
||||
import { AccessTokenMockClass, DriveItemDetailsMockClass, SearchResultMockClass } from "./entities/mock_entities";
|
||||
import { logger } from "../../../src/core/platform/framework";
|
||||
import { expect } from "@jest/globals";
|
||||
import { publicAccessLevel } from "../../../src/services/documents/types";
|
||||
|
||||
export default class TestHelpers {
|
||||
|
||||
@@ -56,10 +58,6 @@ export default class TestHelpers {
|
||||
return helpers;
|
||||
}
|
||||
|
||||
async uploadFiles(parent_id = "root") {
|
||||
return Promise.all(TestHelpers.ALL_FILES.map(f => this.uploadFile(f)));
|
||||
}
|
||||
|
||||
async uploadRandomFile() {
|
||||
return await this.uploadFile(TestHelpers.ALL_FILES[Math.floor((Math.random()*TestHelpers.ALL_FILES.length))])
|
||||
}
|
||||
@@ -117,15 +115,28 @@ export default class TestHelpers {
|
||||
return files;
|
||||
};
|
||||
|
||||
async createDocument(
|
||||
platform: TestPlatform,
|
||||
async createDirectory(parent = "root") {
|
||||
const directory = await this.createDocument({
|
||||
company_id: this.platform.workspace.company_id,
|
||||
name: "Test Folder Name",
|
||||
parent_id: parent,
|
||||
is_directory: true,
|
||||
}, {});
|
||||
expect(directory).toBeDefined();
|
||||
expect(directory).not.toBeNull();
|
||||
expect(directory.id).toBeDefined()
|
||||
expect(directory.id).not.toBeNull();
|
||||
return directory;
|
||||
}
|
||||
|
||||
private async createDocument(
|
||||
item: Partial<DriveFile>,
|
||||
version: Partial<FileVersion>
|
||||
) {
|
||||
|
||||
return await platform.app.inject({
|
||||
const response = await this.platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${TestHelpers.DOC_URL}/companies/${platform.workspace.company_id}/item`,
|
||||
url: `${TestHelpers.DOC_URL}/companies/${this.platform.workspace.company_id}/item`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`,
|
||||
},
|
||||
@@ -134,6 +145,68 @@ export default class TestHelpers {
|
||||
version,
|
||||
},
|
||||
});
|
||||
return deserialize<DriveFile>(DriveFile, response.body);
|
||||
};
|
||||
|
||||
async shareWithPublicLink(doc: Partial<DriveFile>, accessLevel: publicAccessLevel) {
|
||||
return await this.updateDocument(doc.id, {
|
||||
...doc,
|
||||
access_info: {
|
||||
...doc.access_info,
|
||||
public: {
|
||||
...doc.access_info.public!,
|
||||
level: accessLevel,
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getPublicLinkAccessToken(doc: Partial<DriveFile>) {
|
||||
const accessRes = await this.platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${TestHelpers.DOC_URL}/companies/${doc.company_id}/anonymous/token`,
|
||||
headers: {},
|
||||
payload: {
|
||||
company_id: doc.company_id,
|
||||
document_id: doc.id,
|
||||
token: doc.access_info.public?.token,
|
||||
},
|
||||
});
|
||||
const { access_token } = deserialize<AccessTokenMockClass>(
|
||||
AccessTokenMockClass,
|
||||
accessRes.body,
|
||||
);
|
||||
expect(access_token).toBeDefined();
|
||||
|
||||
return access_token;
|
||||
}
|
||||
|
||||
async createRandomDocument(
|
||||
parent_id = "root",
|
||||
) {
|
||||
const file = await this.uploadRandomFile();
|
||||
const item = {
|
||||
name: file.metadata.name,
|
||||
parent_id: parent_id,
|
||||
company_id: file.company_id,
|
||||
};
|
||||
|
||||
const version = {
|
||||
file_metadata: {
|
||||
name: file.metadata.name,
|
||||
size: file.upload_data?.size,
|
||||
thumbnails: [],
|
||||
external_id: file.id
|
||||
}
|
||||
}
|
||||
|
||||
const doc = await this.createDocument(item, version);
|
||||
|
||||
expect(doc).toBeDefined();
|
||||
expect(doc).not.toBeNull();
|
||||
expect(doc.parent_id).toEqual(parent_id)
|
||||
|
||||
return doc;
|
||||
};
|
||||
|
||||
async createDocumentFromFile(
|
||||
@@ -155,8 +228,7 @@ export default class TestHelpers {
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.createDocument(this.platform, item, version);
|
||||
return deserialize<DriveFile>(DriveFile, response.body);
|
||||
return await this.createDocument(item, version);
|
||||
};
|
||||
|
||||
async updateDocument(
|
||||
@@ -208,16 +280,23 @@ export default class TestHelpers {
|
||||
response.body)
|
||||
};
|
||||
|
||||
async getDocument(platform: TestPlatform, id: string | "root" | "trash" | "shared_with_me") {
|
||||
return await platform.app.inject({
|
||||
async getDocument(id: string | "root" | "trash" | "shared_with_me") {
|
||||
return await this.platform.app.inject({
|
||||
method: "GET",
|
||||
url: `${TestHelpers.DOC_URL}/companies/${platform.workspace.company_id}/item/${id}`,
|
||||
url: `${TestHelpers.DOC_URL}/companies/${this.platform.workspace.company_id}/item/${id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
async getDocumentOKCheck(id: string | "root" | "trash" | "shared_with_me") {
|
||||
const response = await this.getDocument(id);
|
||||
expect(response.statusCode).toBe(200);
|
||||
const doc = deserialize<DriveItemDetailsMockClass>(DriveItemDetailsMockClass, response.body);
|
||||
expect(doc.item?.id).toBe(id);
|
||||
};
|
||||
|
||||
async sharedWithMeDocuments (
|
||||
payload: Record<string, any>
|
||||
){
|
||||
|
||||
@@ -42,4 +42,15 @@ export class DriveItemDetailsMockClass {
|
||||
|
||||
export class SearchResultMockClass {
|
||||
entities: DriveFileMockClass[];
|
||||
}
|
||||
|
||||
export class AccessTokenMockClass {
|
||||
access_token: {
|
||||
time: 0;
|
||||
expiration: number;
|
||||
refresh_expiration: number;
|
||||
value: string;
|
||||
refresh: string;
|
||||
type: "Bearer";
|
||||
};
|
||||
}
|
||||
@@ -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 (
|
||||
|
||||
@@ -89,10 +89,10 @@ class Login extends Observable {
|
||||
this.cookies.remove('pending-redirect');
|
||||
setTimeout(() => {
|
||||
document.location.href = redirectUrl;
|
||||
}, 500);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
this.updateUser((err, user) => this.logger.debug('User is updated', err, user));
|
||||
await this.updateUser((err, user) => this.logger.debug('User is updated', err, user));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ export default class InternalAuthProviderService
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.signinIn = true;
|
||||
|
||||
this.logger.log("Sign in in console");
|
||||
ConsoleAPIClient.login(
|
||||
{
|
||||
email: params.username,
|
||||
|
||||
Reference in New Issue
Block a user