✨Added support of the session editing key for the OnlyOffice connector
This commit is contained in:
committed by
Eric Doughty-Papassideris
parent
b6be90f825
commit
c66123f450
@@ -409,6 +409,36 @@ export default class UserApi {
|
||||
});
|
||||
}
|
||||
|
||||
async endEditingDocument(
|
||||
editingSessionKey: string
|
||||
): Promise<Response> {
|
||||
const fullPath = `${__dirname}/assets/${UserApi.ALL_FILES[0]}`;
|
||||
const readable= Readable.from(fs.createReadStream(fullPath));
|
||||
const form = formAutoContent({ file: readable });
|
||||
form.headers["authorization"] = `Bearer ${this.jwt}`;
|
||||
|
||||
return await this.platform.app.inject({
|
||||
method: "POST",
|
||||
url: `${UserApi.DOC_URL}/companies/${this.platform.workspace.company_id}/item/editing_session/${editingSessionKey}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`
|
||||
},
|
||||
...form,
|
||||
});
|
||||
}
|
||||
|
||||
async cancelEditingDocument(
|
||||
editingSessionKey: string,
|
||||
): Promise<Response> {
|
||||
return await this.platform.app.inject({
|
||||
method: "DELETE",
|
||||
url: `${UserApi.DOC_URL}/companies/${this.platform.workspace.company_id}/item/editing_session/${editingSessionKey}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${this.jwt}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async beginEditingDocumentExpectOk(
|
||||
driveFileId: string,
|
||||
editorApplicationId: string,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// import { OidcJwtVerifier } from "../../../src/services/console/clients/remote-jwks-verifier";
|
||||
//
|
||||
// export class UserAuthorization {
|
||||
// /**
|
||||
// * Just send the login requests without any validation and login response assertion
|
||||
// */
|
||||
// public async login(session?: string) {
|
||||
// if (session !== undefined) {
|
||||
// this.session = session;
|
||||
// } else {
|
||||
// this.session = uuidv1();
|
||||
// }
|
||||
// const payload = {
|
||||
// claims: {
|
||||
// sub: this.user.id,
|
||||
// first_name: this.user.first_name,
|
||||
// sid: this.session,
|
||||
// },
|
||||
// };
|
||||
// const verifierMock = jest.spyOn(OidcJwtVerifier.prototype, "verifyIdToken");
|
||||
// verifierMock.mockImplementation(() => {
|
||||
// return Promise.resolve(payload); // Return the predefined payload
|
||||
// });
|
||||
// return await this.api.post("/internal/services/console/v1/login", {
|
||||
// oidc_id_token: "sample_oidc_token",
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public async logout() {
|
||||
// const payload = {
|
||||
// claims: {
|
||||
// iss: "tdrive_lemonldap",
|
||||
// sub: this.user.id,
|
||||
// sid: this.session,
|
||||
// aud: "your-audience",
|
||||
// iat: Math.floor(Date.now() / 1000),
|
||||
// jti: "jwt-id",
|
||||
// events: {
|
||||
// "http://schemas.openid.net/event/backchannel-logout": {},
|
||||
// },
|
||||
// }
|
||||
// };
|
||||
// const verifierMock = jest.spyOn(OidcJwtVerifier.prototype, "verifyLogoutToken");
|
||||
// verifierMock.mockImplementation(() => {
|
||||
// return Promise.resolve(payload); // Return the predefined payload
|
||||
// });
|
||||
//
|
||||
// return await this.api.post("/internal/services/console/v1/backchannel_logout", {
|
||||
// logout_token: "logout_token_rsa256",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
@@ -4,6 +4,7 @@ import { init, TestPlatform } from "../setup";
|
||||
import UserApi from "../common/user-api";
|
||||
|
||||
import { DriveFile, TYPE as DriveFileType } from "../../../src/services/documents/entities/drive-file";
|
||||
import exp = require("node:constants");
|
||||
|
||||
describe("the Drive's documents' editing session kind-of-lock", () => {
|
||||
let platform: TestPlatform | null;
|
||||
@@ -110,8 +111,28 @@ describe("the Drive's documents' editing session kind-of-lock", () => {
|
||||
expect(temporaryDocument.id).toBe(foundDocumentResult.json().id);
|
||||
});
|
||||
|
||||
it('can end an editing session on a document only once with the right key', async () => {
|
||||
it('can cancel an editing session on a document only once with the right key', async () => {
|
||||
//given
|
||||
const editingSessionKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
|
||||
//when
|
||||
const response = await currentUser.cancelEditingDocument(editingSessionKey);
|
||||
//then
|
||||
expect(response.statusCode).toBe(200);
|
||||
const newSessionKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
expect(newSessionKey).not.toEqual(editingSessionKey);
|
||||
});
|
||||
|
||||
it('can end editing with a new version of document', async () => {
|
||||
//given
|
||||
const editingSessionKey = await currentUser.beginEditingDocumentExpectOk(temporaryDocument.id, 'e2e_testing');
|
||||
//when
|
||||
const response = await currentUser.endEditingDocument(editingSessionKey);
|
||||
|
||||
//then
|
||||
expect(response.statusCode).toBe(200);
|
||||
const document = await currentUser.getDocumentOKCheck(temporaryDocument.id);
|
||||
expect(document.versions.length).toEqual(2);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user