Revert "AAE-30882 Replace superagent (#11134)" (#11210)

* Revert "AAE-30882 Replace superagent (#11134)"

This reverts commit a347b20f20.

* AAE-0000 - Fixed lock for cli and adf
This commit is contained in:
Vito Albano
2025-09-19 12:44:06 +01:00
committed by GitHub
parent ef29bafc75
commit 91d6b80965
57 changed files with 3074 additions and 1051 deletions

View File

@@ -18,7 +18,6 @@
import assert from 'assert';
import { EcmAuthMock, BpmAuthMock, NodeMock, ProfileMock } from './mockObjects';
import { NodesApi, UserProfileApi, AlfrescoApi } from '../src';
import nock from 'nock';
const NOOP = () => {
/* empty */
@@ -26,6 +25,10 @@ const NOOP = () => {
const ECM_HOST = 'https://127.0.0.1:8080';
const BPM_HOST = 'https://127.0.0.1:9999';
interface ErrorResponse {
status: number;
}
describe('Auth', () => {
describe('ECM Provider config', () => {
let authResponseEcmMock: EcmAuthMock;
@@ -33,7 +36,6 @@ describe('Auth', () => {
let nodesApi: NodesApi;
beforeEach(() => {
nock.cleanAll();
authResponseEcmMock = new EcmAuthMock(ECM_HOST);
nodeMock = new NodeMock(ECM_HOST);
});
@@ -41,7 +43,6 @@ describe('Auth', () => {
afterEach(() => {
authResponseEcmMock.cleanAll();
nodeMock.cleanAll();
nock.cleanAll();
});
describe('With Authentication', () => {
@@ -63,14 +64,13 @@ describe('Auth', () => {
assert.equal(data, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
});
it('should return an error if wrong credential are used 403 the login fails', async () => {
it('should return an error if wrong credential are used 403 the login fails', (done) => {
authResponseEcmMock.get403Response();
try {
await alfrescoJsApi.login('wrong', 'name');
} catch (error) {
alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => {
assert.equal(error.status, 403);
}
done();
});
});
});
@@ -85,7 +85,7 @@ describe('Auth', () => {
it('should return false if the api is logged out', async () => {
authResponseEcmMock.get201Response();
await alfrescoJsApi.login('admin', 'admin').catch(NOOP);
alfrescoJsApi.login('admin', 'admin').catch(NOOP);
authResponseEcmMock.get204ResponseLogout();
@@ -134,17 +134,9 @@ describe('Auth', () => {
});
describe('With Ticket Authentication', () => {
it('should Ticket login be validate against the server if is valid', async () => {
const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
authResponseEcmMock.get200ValidTicket(ticket);
const data = await alfrescoJsApi.loginTicket(ticket, null);
assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, ticket);
assert.equal(data, ticket);
});
it('should Ticket be present in the client', () => {
authResponseEcmMock.get400Response();
const api = new AlfrescoApi({
ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
hostEcm: ECM_HOST
@@ -153,16 +145,26 @@ describe('Auth', () => {
assert.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', api.contentClient.authentications.basicAuth.password);
});
it('should Ticket login be validate against the server is NOT valid', async () => {
it('should Ticket login be validate against the server if is valid', (done) => {
const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
authResponseEcmMock.get400ResponseGET();
try {
await alfrescoJsApi.loginTicket(ticket, null);
assert.fail('Expected loginTicket to throw an error');
} catch (error) {
assert.equal(error.response.data.error.briefSummary, '05160045 Invalid login details.');
}
authResponseEcmMock.get200ValidTicket(ticket);
alfrescoJsApi.loginTicket(ticket, null).then((data: string) => {
assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, ticket);
assert.equal(data, ticket);
done();
});
});
it('should Ticket login be validate against the server d is NOT valid', (done) => {
const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
authResponseEcmMock.get400Response();
alfrescoJsApi.loginTicket(ticket, null).then(NOOP, () => {
done();
});
});
});
@@ -172,46 +174,49 @@ describe('Auth', () => {
await alfrescoJsApi.login('admin', 'admin');
});
it('should Ticket be absent in the client and the resolve promise should be called', async () => {
it('should Ticket be absent in the client and the resolve promise should be called', (done) => {
authResponseEcmMock.get204ResponseLogout();
await alfrescoJsApi.logout();
assert.equal(alfrescoJsApi.config.ticket, undefined);
alfrescoJsApi.logout().then(() => {
assert.equal(alfrescoJsApi.config.ticket, undefined);
done();
});
});
it('should Logout be rejected if the Ticket is already expired', async () => {
it('should Logout be rejected if the Ticket is already expired', (done) => {
authResponseEcmMock.get404ResponseLogout();
try {
await alfrescoJsApi.logout();
} catch (error) {
assert.equal(error.response.data.error.briefSummary.toString(), 'Not Found');
}
alfrescoJsApi.logout().then(NOOP, (error: any) => {
assert.equal(error.error.toString(), 'Error: Not Found');
done();
});
});
});
describe('Unauthorized', () => {
beforeEach(async () => {
beforeEach((done) => {
authResponseEcmMock.get201Response('TICKET_22d7a5a83d78b9cc9666ec4e412475e5455b33bd');
await alfrescoJsApi.login('admin', 'admin');
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
});
it('should 401 invalidate the ticket', async () => {
it('should 401 invalidate the ticket', (done) => {
nodeMock.get401CreationFolder();
try {
await nodesApi.createFolder('newFolder', null, null);
} catch {
nodesApi.createFolder('newFolder', null, null).then(NOOP, () => {
assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, null);
}
done();
});
});
it('should 401 invalidate the session and logout', async () => {
it('should 401 invalidate the session and logout', (done) => {
nodeMock.get401CreationFolder();
try {
await nodesApi.createFolder('newFolder', null, null);
} catch {
nodesApi.createFolder('newFolder', null, null).then(NOOP, () => {
assert.equal(alfrescoJsApi.isLoggedIn(), false);
}
done();
});
});
it('should emit an error event if a failing call is executed', (done) => {
@@ -247,41 +252,46 @@ describe('Auth', () => {
describe('With Authentication', () => {
describe('login', () => {
it('should return the Ticket if all is ok', async () => {
it('should return the Ticket if all is ok', (done) => {
authResponseBpmMock.get200Response();
const data = await alfrescoJsApi.login('admin', 'admin');
assert.equal(data, 'Basic YWRtaW46YWRtaW4=');
alfrescoJsApi.login('admin', 'admin').then((data: string) => {
assert.equal(data, 'Basic YWRtaW46YWRtaW4=');
done();
});
});
it('should return an error if wrong credential are used 401 the login fails', async () => {
it('should return an error if wrong credential are used 401 the login fails', (done) => {
authResponseBpmMock.get401Response();
try {
await alfrescoJsApi.login('wrong', 'name');
} catch (error) {
alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => {
assert.equal(error.status, 401);
}
done();
});
});
});
describe('isLoggedIn', () => {
it('should return true if the api is logged in', async () => {
it('should return true if the api is logged in', (done) => {
authResponseBpmMock.get200Response();
await alfrescoJsApi.login('admin', 'admin');
assert.equal(alfrescoJsApi.isLoggedIn(), true);
alfrescoJsApi.login('admin', 'admin').then(() => {
assert.equal(alfrescoJsApi.isLoggedIn(), true);
done();
}, NOOP);
});
it('should return false if the api is logged out', async () => {
it('should return false if the api is logged out', (done) => {
authResponseBpmMock.get200Response();
await alfrescoJsApi.login('admin', 'admin');
alfrescoJsApi.login('admin', 'admin');
authResponseBpmMock.get200ResponseLogout();
await alfrescoJsApi.logout();
assert.equal(alfrescoJsApi.isLoggedIn(), false);
alfrescoJsApi.logout().then(() => {
assert.equal(alfrescoJsApi.isLoggedIn(), false);
done();
}, NOOP);
});
});
@@ -335,24 +345,25 @@ describe('Auth', () => {
});
});
it('should 401 invalidate the ticket', async () => {
it('should 401 invalidate the ticket', (done) => {
profileMock.get401getProfile();
try {
await profileApi.getProfile();
assert.fail('Expected getProfile to throw an error');
} catch {
profileApi.getProfile().then(NOOP, () => {
assert.equal(alfrescoJsApi.processAuth.authentications.basicAuth.ticket, null);
}
done();
});
});
it('should 401 invalidate the session and logout', async () => {
it('should 401 invalidate the session and logout', (done) => {
profileMock.get401getProfile();
try {
await profileApi.getProfile();
assert.fail('Expected getProfile to throw an error');
} catch {
assert.equal(alfrescoJsApi.isLoggedIn(), false);
}
profileApi.getProfile().then(
() => NOOP,
() => {
assert.equal(alfrescoJsApi.isLoggedIn(), false);
done();
}
);
});
});
});
@@ -395,75 +406,75 @@ describe('Auth', () => {
});
describe('login', () => {
it('should return the Ticket if all is ok', async () => {
it('should return the Ticket if all is ok', (done) => {
authResponseBpmMock.get200Response();
authResponseEcmMock.get201Response();
const data = await alfrescoJsApi.login('admin', 'admin');
assert.equal(data[0], 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
assert.equal(data[1], 'Basic YWRtaW46YWRtaW4=');
alfrescoJsApi.login('admin', 'admin').then((data: string[]) => {
assert.equal(data[0], 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
assert.equal(data[1], 'Basic YWRtaW46YWRtaW4=');
done();
});
});
it('should fail if only ECM fail', async () => {
it('should fail if only ECM fail', (done) => {
authResponseBpmMock.get200Response();
authResponseEcmMock.get401Response();
try {
await alfrescoJsApi.login('admin', 'admin');
assert.fail('Expected login to throw an error');
} catch {
authResponseEcmMock.cleanAll();
}
alfrescoJsApi.login('admin', 'admin').then(NOOP, () => {
done();
});
authResponseEcmMock.cleanAll();
});
it('should fail if only BPM fail', async () => {
it('should fail if only BPM fail', (done) => {
authResponseBpmMock.get401Response();
authResponseEcmMock.get201Response();
try {
await alfrescoJsApi.login('admin', 'admin');
assert.fail('Expected login to throw an error');
} catch {
authResponseBpmMock.cleanAll();
}
alfrescoJsApi.login('admin', 'admin').then(NOOP, () => {
done();
});
authResponseBpmMock.cleanAll();
});
});
describe('isLoggedIn', () => {
it('should return false if the api is logged out', async () => {
it('should return false if the api is logged out', (done) => {
authResponseBpmMock.get200Response();
authResponseEcmMock.get201Response();
await alfrescoJsApi.login('admin', 'admin');
alfrescoJsApi.login('admin', 'admin');
authResponseBpmMock.get200ResponseLogout();
authResponseEcmMock.get204ResponseLogout();
await alfrescoJsApi.logout();
assert.equal(alfrescoJsApi.isLoggedIn(), false);
alfrescoJsApi.logout().then(() => {
assert.equal(alfrescoJsApi.isLoggedIn(), false);
done();
});
});
it('should return an error if wrong credential are used 401 the login fails', async () => {
it('should return an error if wrong credential are used 401 the login fails', (done) => {
authResponseBpmMock.get401Response();
authResponseEcmMock.get401Response();
try {
await alfrescoJsApi.login('wrong', 'name');
assert.fail('Expected login to throw an error');
} catch (error) {
alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => {
assert.equal(error.status, 401);
}
done();
});
});
});
it('should return true if the api is logged in', async () => {
it('should return true if the api is logged in', (done) => {
authResponseBpmMock.get200Response();
authResponseEcmMock.get201Response();
await alfrescoJsApi.login('admin', 'admin');
assert.equal(alfrescoJsApi.isLoggedIn(), true);
alfrescoJsApi.login('admin', 'admin').then(() => {
assert.equal(alfrescoJsApi.isLoggedIn(), true);
done();
});
});
describe('Events ', () => {