🐛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 (id === "shared_with_me") return "read";
|
||||||
|
|
||||||
//If it is my personal folder, I have full access
|
//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 (id === "user_" + context.user?.id) return "manage";
|
||||||
if (await isCompanyApplication(context)) return "manage";
|
if (await isCompanyApplication(context)) return "manage";
|
||||||
|
return "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
let publicToken = context.public_token;
|
let publicToken = context.public_token;
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import {ResourceUpdateResponse, Workspace} from "../../../src/utils/types";
|
import { ResourceUpdateResponse, Workspace } from "../../../src/utils/types";
|
||||||
import {File} from "../../../src/services/files/entities/file";
|
import { File } from "../../../src/services/files/entities/file";
|
||||||
import {deserialize} from "class-transformer";
|
import { deserialize } from "class-transformer";
|
||||||
import formAutoContent from "form-auto-content";
|
import formAutoContent from "form-auto-content";
|
||||||
import {TestPlatform, User} from "../setup";
|
import { TestPlatform, User } from "../setup";
|
||||||
import {v1 as uuidv1} from "uuid";
|
import { v1 as uuidv1 } from "uuid";
|
||||||
import {TestDbService} from "../utils.prepare.db";
|
import { TestDbService } from "../utils.prepare.db";
|
||||||
import {DriveFile} from "../../../src/services/documents/entities/drive-file";
|
import { DriveFile } from "../../../src/services/documents/entities/drive-file";
|
||||||
import {FileVersion} from "../../../src/services/documents/entities/file-version";
|
import { FileVersion } from "../../../src/services/documents/entities/file-version";
|
||||||
import { DriveItemDetailsMockClass, SearchResultMockClass } from "./entities/mock_entities";
|
import { AccessTokenMockClass, DriveItemDetailsMockClass, SearchResultMockClass } from "./entities/mock_entities";
|
||||||
import {logger} from "../../../src/core/platform/framework";
|
import { logger } from "../../../src/core/platform/framework";
|
||||||
|
import { expect } from "@jest/globals";
|
||||||
|
import { publicAccessLevel } from "../../../src/services/documents/types";
|
||||||
|
|
||||||
export default class TestHelpers {
|
export default class TestHelpers {
|
||||||
|
|
||||||
@@ -56,10 +58,6 @@ export default class TestHelpers {
|
|||||||
return helpers;
|
return helpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadFiles(parent_id = "root") {
|
|
||||||
return Promise.all(TestHelpers.ALL_FILES.map(f => this.uploadFile(f)));
|
|
||||||
}
|
|
||||||
|
|
||||||
async uploadRandomFile() {
|
async uploadRandomFile() {
|
||||||
return await this.uploadFile(TestHelpers.ALL_FILES[Math.floor((Math.random()*TestHelpers.ALL_FILES.length))])
|
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;
|
return files;
|
||||||
};
|
};
|
||||||
|
|
||||||
async createDocument(
|
async createDirectory(parent = "root") {
|
||||||
platform: TestPlatform,
|
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>,
|
item: Partial<DriveFile>,
|
||||||
version: Partial<FileVersion>
|
version: Partial<FileVersion>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
return await platform.app.inject({
|
const response = await this.platform.app.inject({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: `${TestHelpers.DOC_URL}/companies/${platform.workspace.company_id}/item`,
|
url: `${TestHelpers.DOC_URL}/companies/${this.platform.workspace.company_id}/item`,
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `Bearer ${this.jwt}`,
|
authorization: `Bearer ${this.jwt}`,
|
||||||
},
|
},
|
||||||
@@ -134,6 +145,68 @@ export default class TestHelpers {
|
|||||||
version,
|
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(
|
async createDocumentFromFile(
|
||||||
@@ -155,8 +228,7 @@ export default class TestHelpers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.createDocument(this.platform, item, version);
|
return await this.createDocument(item, version);
|
||||||
return deserialize<DriveFile>(DriveFile, response.body);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async updateDocument(
|
async updateDocument(
|
||||||
@@ -208,16 +280,23 @@ export default class TestHelpers {
|
|||||||
response.body)
|
response.body)
|
||||||
};
|
};
|
||||||
|
|
||||||
async getDocument(platform: TestPlatform, id: string | "root" | "trash" | "shared_with_me") {
|
async getDocument(id: string | "root" | "trash" | "shared_with_me") {
|
||||||
return await platform.app.inject({
|
return await this.platform.app.inject({
|
||||||
method: "GET",
|
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: {
|
headers: {
|
||||||
authorization: `Bearer ${this.jwt}`,
|
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 (
|
async sharedWithMeDocuments (
|
||||||
payload: Record<string, any>
|
payload: Record<string, any>
|
||||||
){
|
){
|
||||||
|
|||||||
@@ -42,4 +42,15 @@ export class DriveItemDetailsMockClass {
|
|||||||
|
|
||||||
export class SearchResultMockClass {
|
export class SearchResultMockClass {
|
||||||
entities: DriveFileMockClass[];
|
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 { deserialize } from "class-transformer";
|
||||||
import { File } from "../../../src/services/files/entities/file";
|
import { File } from "../../../src/services/files/entities/file";
|
||||||
import { ResourceUpdateResponse } from "../../../src/utils/types";
|
import { ResourceUpdateResponse } from "../../../src/utils/types";
|
||||||
@@ -236,7 +236,6 @@ describe("the Drive feature", () => {
|
|||||||
|
|
||||||
//then::
|
//then::
|
||||||
expect(searchResponse.entities?.length).toEqual(1);
|
expect(searchResponse.entities?.length).toEqual(1);
|
||||||
const actual = searchResponse.entities[0];
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("did search for an item that doesn't exist", async () => {
|
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 () => {
|
it("did search by mime type", async () => {
|
||||||
jest.setTimeout(10000);
|
jest.setTimeout(10000);
|
||||||
// given:: all the sample files uploaded and documents for them created
|
// given:: all the sample files uploaded and documents for them created
|
||||||
await Promise.all(
|
await currentUser.uploadAllFilesOneByOne();
|
||||||
(await currentUser.uploadFiles()).map(f => currentUser.createDocumentFromFile(f)),
|
|
||||||
);
|
|
||||||
|
|
||||||
const filters = {
|
const filters = {
|
||||||
mime_type: "application/pdf",
|
mime_type: "application/pdf",
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { DriveFileAccessLevel, DriveItemDetails } from "../../../src/services/do
|
|||||||
import { init, TestPlatform } from "../setup";
|
import { init, TestPlatform } from "../setup";
|
||||||
import { TestDbService } from "../utils.prepare.db";
|
import { TestDbService } from "../utils.prepare.db";
|
||||||
import { e2e_createDocument, e2e_updateDocument } from "./utils";
|
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";
|
const url = "/internal/services/documents/v1";
|
||||||
|
|
||||||
@@ -22,17 +24,6 @@ describe("the public links feature", () => {
|
|||||||
access_info: AccessInformation;
|
access_info: AccessInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
class AccessTokenMockClass {
|
|
||||||
access_token: {
|
|
||||||
time: 0;
|
|
||||||
expiration: number;
|
|
||||||
refresh_expiration: number;
|
|
||||||
value: string;
|
|
||||||
refresh: string;
|
|
||||||
type: "Bearer";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class FullDriveInfoMockClass {
|
class FullDriveInfoMockClass {
|
||||||
path: DriveFile[];
|
path: DriveFile[];
|
||||||
item?: DriveFile;
|
item?: DriveFile;
|
||||||
@@ -71,221 +62,251 @@ describe("the public links feature", () => {
|
|||||||
platform = null;
|
platform = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
const createItem = async (): Promise<DriveFileMockClass> => {
|
|
||||||
await TestDbService.getInstance(platform, true);
|
|
||||||
|
|
||||||
const item = {
|
describe("Basic Flow", () => {
|
||||||
name: "public file",
|
|
||||||
parent_id: "root",
|
const createItem = async (): Promise<DriveFileMockClass> => {
|
||||||
company_id: platform.workspace.company_id,
|
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);
|
it("did create the drive item", async () => {
|
||||||
return deserialize<DriveFileMockClass>(DriveFileMockClass, response.body);
|
const result = await createItem();
|
||||||
};
|
publicFile = result;
|
||||||
|
|
||||||
let publicFile: DriveFileMockClass;
|
expect(result).toBeDefined();
|
||||||
|
expect(result.name).toEqual("public file");
|
||||||
it("did create the drive item", async () => {
|
expect(result.added).toBeDefined();
|
||||||
const result = await createItem();
|
expect(result.access_info).toBeDefined();
|
||||||
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(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 () => {
|
expect(res.statusCode).toBe(401);
|
||||||
const res = await e2e_updateDocument(platform, publicFile.id, {
|
});
|
||||||
...publicFile,
|
|
||||||
access_info: {
|
it("should access public file", async () => {
|
||||||
...publicFile.access_info,
|
const res = await e2e_updateDocument(platform, publicFile.id, {
|
||||||
public: {
|
...publicFile,
|
||||||
...publicFile.access_info.public!,
|
access_info: {
|
||||||
level: "read",
|
...publicFile.access_info,
|
||||||
|
public: {
|
||||||
|
...publicFile.access_info.public!,
|
||||||
|
level: "read",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
expect(res.statusCode).toBe(200);
|
||||||
expect(res.statusCode).toBe(200);
|
const file = deserialize<DriveFileMockClass>(DriveFileMockClass, res.body);
|
||||||
const file = deserialize<DriveFileMockClass>(DriveFileMockClass, res.body);
|
expect(file.access_info.public?.level).toBe("read");
|
||||||
expect(file.access_info.public?.level).toBe("read");
|
|
||||||
|
|
||||||
const accessRes = await platform.app.inject({
|
const accessRes = await platform.app.inject({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
||||||
headers: {},
|
headers: {},
|
||||||
payload: {
|
payload: {
|
||||||
company_id: publicFile.company_id,
|
company_id: publicFile.company_id,
|
||||||
document_id: publicFile.id,
|
document_id: publicFile.id,
|
||||||
token: publicFile.access_info.public?.token,
|
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 { access_token } = deserialize<AccessTokenMockClass>(
|
||||||
|
AccessTokenMockClass,
|
||||||
|
accessRes.body,
|
||||||
|
);
|
||||||
|
expect(access_token).toBeDefined();
|
||||||
|
|
||||||
const accessRes = await platform.app.inject({
|
const resPublicRaw = await platform.app.inject({
|
||||||
method: "POST",
|
method: "GET",
|
||||||
url: `${url}/companies/${publicFile.company_id}/anonymous/token`,
|
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
||||||
headers: {},
|
headers: {
|
||||||
payload: {
|
Authorization: `Bearer ${access_token.value}`,
|
||||||
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 resPublic = deserialize<DriveItemDetails>(FullDriveInfoMockClass, resPublicRaw.body);
|
||||||
|
expect(resPublicRaw.statusCode).toBe(200);
|
||||||
|
expect(resPublic.item?.id).toBe(publicFile.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
resPublicRaw = await platform.app.inject({
|
it("unable to access expired public file link", async () => {
|
||||||
method: "GET",
|
await e2e_updateDocument(platform, publicFile.id, {
|
||||||
url: `${url}/companies/${publicFile.company_id}/item/${publicFile.id}`,
|
...publicFile,
|
||||||
headers: {
|
access_info: {
|
||||||
authorization: `Bearer ${access_token.value}`,
|
...publicFile.access_info,
|
||||||
},
|
public: {
|
||||||
});
|
...publicFile.access_info.public!,
|
||||||
expect(resPublicRaw.statusCode).toBe(401);
|
level: "read",
|
||||||
|
expiration: Date.now() + 1000 * 60, //In the future
|
||||||
await e2e_updateDocument(platform, publicFile.id, {
|
},
|
||||||
...publicFile,
|
|
||||||
access_info: {
|
|
||||||
...publicFile.access_info,
|
|
||||||
public: {
|
|
||||||
...publicFile.access_info.public!,
|
|
||||||
level: "read",
|
|
||||||
expiration: 0, //Reset to default
|
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
|
|
||||||
|
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 () => {
|
describe("Share file from My Drive", () => {
|
||||||
await e2e_updateDocument(platform, publicFile.id, {
|
|
||||||
...publicFile,
|
it("Share file from some folder", async () => {
|
||||||
access_info: {
|
const user = await TestHelpers.getInstance(platform, true);
|
||||||
...publicFile.access_info,
|
const anotherUser = await TestHelpers.getInstance(platform, true);
|
||||||
public: {
|
|
||||||
...publicFile.access_info.public!,
|
//create directory in "My Drive" and upload a file
|
||||||
level: "read",
|
const directory = await user.createDirectory("user_" + user.user.id);
|
||||||
password: "abcdef",
|
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 { FileVersion } from "../../../src/services/documents/entities/file-version";
|
||||||
import { TestPlatform } from "../setup";
|
import { TestPlatform } from "../setup";
|
||||||
import formAutoContent from "form-auto-content";
|
import formAutoContent from "form-auto-content";
|
||||||
import fs from "fs";
|
import * as fs from "fs";
|
||||||
|
|
||||||
const url = "/internal/services/documents/v1";
|
const url = "/internal/services/documents/v1";
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ export const e2e_searchDocument = async (
|
|||||||
) => {
|
) => {
|
||||||
const token = await platform.auth.getJWTToken();
|
const token = await platform.auth.getJWTToken();
|
||||||
|
|
||||||
const response = await platform.app.inject({
|
return await platform.app.inject({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: `${url}/companies/${platform.workspace.company_id}/search`,
|
url: `${url}/companies/${platform.workspace.company_id}/search`,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -81,8 +81,6 @@ export const e2e_searchDocument = async (
|
|||||||
},
|
},
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const e2e_createVersion = async (
|
export const e2e_createVersion = async (
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ class Login extends Observable {
|
|||||||
this.cookies.remove('pending-redirect');
|
this.cookies.remove('pending-redirect');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.location.href = redirectUrl;
|
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) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
this.signinIn = true;
|
this.signinIn = true;
|
||||||
|
this.logger.log("Sign in in console");
|
||||||
ConsoleAPIClient.login(
|
ConsoleAPIClient.login(
|
||||||
{
|
{
|
||||||
email: params.username,
|
email: params.username,
|
||||||
|
|||||||
Reference in New Issue
Block a user