mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
* chore: migrate to Angular 20, TypeScript 5.9, and supporting packages chore: migrate to Angular 20, TypeScript 5.9, and supporting packages This commit migrates the Nx monorepo from Angular 19 to Angular 20 and updates all related dependencies to their compatible versions. - @angular/core: 19.2.18 → 20.3.9 - @angular/material: 19.2.19 → 20.2.14 - @angular/cdk: 19.2.19 → 20.2.14 - @angular/material-date-fns-adapter: 19.2.19 → 20.2.14 - typescript: 5.8.3 → 5.9.3 - ng-packagr: 19.2.2 → 20.3.2 - @angular-devkit/build-angular: 19.2.19 → 20.3.16 - @angular-devkit/architect: 0.1902.19 → 0.2003.16 - @angular-devkit/core: 19.2.19 → 20.3.16 - @angular-devkit/schematics: 19.2.19 → 20.3.16 - @schematics/angular: 19.2.7 → 20.3.16 - @angular-eslint/eslint-plugin: 19.3.0 → 20.7.0 - @angular-eslint/eslint-plugin-template: 19.3.0 → 20.7.0 - @angular-eslint/template-parser: 19.3.0 → 20.7.0 - @typescript-eslint/eslint-plugin: 6.21.0 → 8.55.0 - @typescript-eslint/parser: 6.21.0 → 8.55.0 - @typescript-eslint/typescript-estree: 8.41.0 → 8.55.0 - @typescript-eslint/utils: ^8.51.0 → 8.55.0 - nx: 22.4.1 → 22.5.1 - @nx/angular: 22.1.3 → 22.5.1 - @nx/eslint-plugin: 22.3.3 → 22.5.1 - @nx/js: 22.1.3 → 22.5.1 - @nx/node: 22.1.3 → 22.5.1 - @nx/storybook: ^20.8.4 → 22.5.1 - @nx/workspace: 22.4.5 → 22.5.1 - @nx/webpack: 22.3.3 → 22.5.1 - storybook: ^10.2.0 → 10.2.8 - @storybook/angular: ^10.2.0 → 10.2.8 - @storybook/addon-themes: ^10.2.0 → 10.2.8 1. **PortalInjector Removal (Angular CDK 20)** - Replaced PortalInjector usage with Injector.create() - Updated context-menu-overlay.service.ts to use new API 2. **ESLint Configuration** - Removed deprecated @typescript-eslint/brace-style rule - This rule was removed in @typescript-eslint v8 All libraries build successfully: - ✅ js-api - ✅ extensions - ✅ core - ✅ content-services - ✅ process-services - ✅ process-services-cloud - ✅ insights Dependencies were installed using npm install --legacy-peer-deps due to peer dependency conflicts with @mat-datetimepicker/core which requires Angular CDK ^19.0.0 but we are using 20.2.14. - ESLint warnings about @angular-eslint/prefer-inject are expected - this is a new recommendation in Angular 20 to use inject() function instead of constructor injection. These can be addressed in a follow-up PR. chore: migrate to Angular 20, TypeScript 5.9, and supporting packages This commit migrates the Nx monorepo from Angular 19 to Angular 20 and updates all related dependencies to their compatible versions. - @angular/core: 19.2.18 → 20.3.9 - @angular/material: 19.2.19 → 20.2.14 - @angular/cdk: 19.2.19 → 20.2.14 - @angular/material-date-fns-adapter: 19.2.19 → 20.2.14 - typescript: 5.8.3 → 5.9.3 - ng-packagr: 19.2.2 → 20.3.2 - @angular-devkit/build-angular: 19.2.19 → 20.3.16 - @angular-devkit/architect: 0.1902.19 → 0.2003.16 - @angular-devkit/core: 19.2.19 → 20.3.16 - @angular-devkit/schematics: 19.2.19 → 20.3.16 - @schematics/angular: 19.2.7 → 20.3.16 - @angular-eslint/eslint-plugin: 19.3.0 → 20.7.0 - @angular-eslint/eslint-plugin-template: 19.3.0 → 20.7.0 - @angular-eslint/template-parser: 19.3.0 → 20.7.0 - @typescript-eslint/eslint-plugin: 6.21.0 → 8.55.0 - @typescript-eslint/parser: 6.21.0 → 8.55.0 - @typescript-eslint/typescript-estree: 8.41.0 → 8.55.0 - @typescript-eslint/utils: ^8.51.0 → 8.55.0 - nx: 22.4.1 → 22.5.1 - @nx/angular: 22.1.3 → 22.5.1 - @nx/eslint-plugin: 22.3.3 → 22.5.1 - @nx/js: 22.1.3 → 22.5.1 - @nx/node: 22.1.3 → 22.5.1 - @nx/storybook: ^20.8.4 → 22.5.1 - @nx/workspace: 22.4.5 → 22.5.1 - @nx/webpack: 22.3.3 → 22.5.1 - storybook: ^10.2.0 → 10.2.8 - @storybook/angular: ^10.2.0 → 10.2.8 - @storybook/addon-themes: ^10.2.0 → 10.2.8 1. **PortalInjector Removal (Angular CDK 20)** - Replaced PortalInjector usage with Injector.create() - Updated context-menu-overlay.service.ts to use new API 2. **ESLint Configuration** - Removed deprecated @typescript-eslint/brace-style rule - This rule was removed in @typescript-eslint v8 All libraries build successfully: - ✅ js-api - ✅ extensions - ✅ core - ✅ content-services - ✅ process-services - ✅ process-services-cloud - ✅ insights Dependencies were installed using npm install --legacy-peer-deps due to peer dependency conflicts with @mat-datetimepicker/core which requires Angular CDK ^19.0.0 but we are using 20.2.14. - ESLint warnings about @angular-eslint/prefer-inject are expected - this is a new recommendation in Angular 20 to use inject() function instead of constructor injection. These can be addressed in a follow-up PR. To fix these automatically, run: ng generate @angular/core:inject --path=lib fix: resolve peer dependency conflicts for CI/CD - Update @mat-datetimepicker/core from 15.0.2 to 16.0.1 (supports Angular 20) - Update webpack override to 5.104.1 for consistency - Add .npmrc with legacy-peer-deps=true for npm ci compatibility - Fixes npm ci failures in CI/CD pipeline fix: update webpack to 5.105.0 for Storybook compatibility - Align webpack version with @angular-devkit/build-angular bundled version - Fixes Storybook compilation error with webpack instance mismatch - Removes unnecessary webpack overrides chore: finalize Angular 20 migration and improve migration prompt - Marked all migration tasks as completed in the migration plan. - Added a comprehensive summary of the migration process, including phases, completed tasks, and known issues. - Introduced an improved migration prompt that addresses critical considerations and provides a detailed migration strategy for Angular 20 and related packages. fix: update migration prompt and tests for Angular 20 breaking changes - Enhanced migration prompt with specific instructions for handling Angular CDK Directionality API changes and removal of ng-reflect-* attributes. - Updated unit tests to replace deprecated ng-reflect-* attribute checks with appropriate Angular testing patterns. - Adjusted user preferences service to utilize the new directionality API method for setting text direction. fix: enhance ImgViewerComponent to handle cleanup and prevent errors after destruction - Added a `destroyed` flag to manage component lifecycle and prevent operations on a destroyed instance. - Implemented `afterEach` hooks in tests to ensure proper fixture cleanup. - Updated key event handlers and methods to check for the `destroyed` state before executing actions, improving stability and preventing errors. feat: update ESLint configuration to include @angular-eslint/prefer-inject rule - Added the @angular-eslint/prefer-inject rule to .eslintrc.json files in content-services, process-services, and process-services-cloud, promoting the use of the inject() function for dependency injection. - Made minor adjustments to comments in search-logical-filter.component.ts for clarity. chore: update ESLint configuration to include @angular-eslint/prefer-inject rule - Added the @angular-eslint/prefer-inject rule to .eslintrc.json files in extensions, insights, and js-api, promoting the use of the inject() function for dependency injection. - Removed unnecessary eslint-disable comments in process-list-cloud.component.ts and base-task-list-cloud.component.ts for cleaner code. remove unnecessary changes remove useless changes cleanup useless changes remove useless changes Update package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> chore: update version of @ngx-translate/core to 17.0.0 in package.json and package-lock.json Update package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update .npmrc Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> chore: upgrade apollo-angular and jest packages to support Angular 20 - Upgrade apollo-angular from 10.0.3 to 13.0.0 - Upgrade @apollo/client from 3.13.1 to ^4.0.1 - Upgrade jest packages to v30 (jest, jest-environment-jsdom) - Upgrade jest-preset-angular from 14.4.2 to 16.1.1 - Add overrides for Angular 20 peer dependency compatibility chore: downgrade @apollo/client and apollo-angular to compatible versions chore: downgrade @apollo/client and apollo-angular to compatible versions chore: remove unused configuration options from jest and tsconfig chore: refactor window.location mock in oauth2 tests for improved clarity and functionality chore: enhance oauth2Auth tests and improve hash handling logic chore: remove @typescript-eslint/brace-style rule from ESLint configuration chore: add prefer-optional-chain rule to ESLint configuration chore: update ESLint rules for optional chaining and refactor type definitions chore: refactor tests to use TestBed for dependency injection in FileViewer and ProcessFormRendering services chore: update AttachFileWidgetComponent to ensure early return after download chore: update AttachFileWidgetComponent to ensure early return after download chore: update unselectFacetBucket method to use optional chaining for safer property access * chore: clean up package-lock.json and update webpack version in package.json * [ACS-11306] Corrected main for eslint-angular * [ACS-11306] Reverted unwanted change * [ACS-11306] Fixed importing issue on ACA * [ACS-11306] Updated node-fetch * [ACS-11306] Reverted last commit * [ACS-11306] Fixed rendering issue with pdf viewer * [ACS-11306] Corrected storybook related versions * Updating dependencies and fixing conflict * [ACS-11306] Fixed cannot find name Buffer occurred in ACA * chore: Updating pnpm lock file * chore: Fixing ESLint issue * chore: Upgrading to version 20.3.24 to avoid security issue * chore: Fixing unit test * chore: Fixing type and exporting missing model * chore: Fixing type * Chore: Migrating to Angular 20.3.25 to mitigate security issues * Fix after rebase * Removing unused deps * Aligning deps * fix create dialog name field hint (#12007) --------- Co-authored-by: Aleksander Sklorz <Aleksander.Sklorz@hyland.com> Co-authored-by: Ehsan Rezaei <ehsan.rezaei@hyland.com> Co-authored-by: Grzegorz Jaśkowski <138671284+g-jaskowski@users.noreply.github.com>
638 lines
22 KiB
TypeScript
638 lines
22 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import assert from 'assert';
|
|
import { AlfrescoApi, ContentApi, Oauth2Auth } from '../src';
|
|
import { EcmAuthMock, OAuthMock } from './mockObjects';
|
|
import { jest } from '@jest/globals';
|
|
import * as browserUtils from '../src/utils/is-browser';
|
|
|
|
describe('Oauth2 test', () => {
|
|
let alfrescoJsApi: AlfrescoApi;
|
|
let oauth2Mock: OAuthMock;
|
|
let authResponseMock: EcmAuthMock;
|
|
|
|
beforeEach(() => {
|
|
const hostOauth2 = 'https://myOauthUrl:30081';
|
|
const mockStorage = {
|
|
getItem: () => {},
|
|
setItem: () => {},
|
|
removeItem: () => {}
|
|
};
|
|
|
|
oauth2Mock = new OAuthMock(hostOauth2);
|
|
authResponseMock = new EcmAuthMock(hostOauth2);
|
|
|
|
alfrescoJsApi = new AlfrescoApi({
|
|
hostEcm: 'myecm'
|
|
});
|
|
|
|
alfrescoJsApi.storage.setStorage(mockStorage);
|
|
delete (window as any).location;
|
|
(window as any).location = {
|
|
ancestorOrigins: null,
|
|
hash: null,
|
|
host: 'dummy.com',
|
|
port: '80',
|
|
protocol: 'http:',
|
|
hostname: 'dummy.com',
|
|
href: 'http://localhost/',
|
|
origin: 'dummy.com',
|
|
pathname: null,
|
|
search: null,
|
|
assign: jest.fn((url: string) => {
|
|
window.location.href = url;
|
|
}),
|
|
reload: jest.fn(),
|
|
replace: jest.fn()
|
|
};
|
|
});
|
|
|
|
afterEach(() => {
|
|
authResponseMock.cleanAll();
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
describe('Discovery urls', () => {
|
|
const authType = 'OAUTH';
|
|
const host = 'https://dummy/auth';
|
|
const clientId = 'dummy';
|
|
const scope = 'openid';
|
|
const redirectUri = '/';
|
|
|
|
it('should have default urls', async () => {
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host,
|
|
clientId,
|
|
scope,
|
|
redirectUri
|
|
},
|
|
authType
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
assert.equal(oauth2Auth.discovery.loginUrl, host + Oauth2Auth.DEFAULT_AUTHORIZATION_URL);
|
|
assert.equal(oauth2Auth.discovery.tokenEndpoint, host + Oauth2Auth.DEFAULT_TOKEN_URL);
|
|
assert.equal(oauth2Auth.discovery.logoutUrl, host + Oauth2Auth.DEFAULT_LOGOUT_URL);
|
|
});
|
|
|
|
it('should be possible to override the default urls', async () => {
|
|
const authorizationUrl = '/custom-login';
|
|
const logoutUrl = '/custom-logout';
|
|
const tokenUrl = '/custom-token';
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host,
|
|
authorizationUrl,
|
|
logoutUrl,
|
|
tokenUrl,
|
|
clientId,
|
|
scope,
|
|
redirectUri
|
|
},
|
|
authType
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
assert.equal(oauth2Auth.discovery.loginUrl, authorizationUrl);
|
|
assert.equal(oauth2Auth.discovery.tokenEndpoint, tokenUrl);
|
|
assert.equal(oauth2Auth.discovery.logoutUrl, logoutUrl);
|
|
});
|
|
});
|
|
|
|
describe('With Authentication', () => {
|
|
it('should be possible have different user login in different instance of the oauth2Auth class', async () => {
|
|
const oauth2AuthInstanceOne = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
const oauth2AuthInstanceTwo = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
const mock = new OAuthMock('https://myOauthUrl:30081');
|
|
mock.get200Response('superman-token');
|
|
const loginInstanceOne = await oauth2AuthInstanceOne.login('superman', 'crypto');
|
|
|
|
mock.get200Response('barman-token');
|
|
const loginInstanceTwo = await oauth2AuthInstanceTwo.login('barman', 'IamBarman');
|
|
|
|
assert.equal(loginInstanceOne.access_token, 'superman-token');
|
|
assert.equal(loginInstanceTwo.access_token, 'barman-token');
|
|
|
|
oauth2AuthInstanceOne.logOut();
|
|
oauth2AuthInstanceTwo.logOut();
|
|
});
|
|
|
|
it('login should return the Token if is ok', (done) => {
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.login('admin', 'admin').then((data) => {
|
|
assert.equal(data.access_token, 'test-token');
|
|
oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should refresh token when the login not use the implicitFlow ', (done) => {
|
|
jest.spyOn(browserUtils, 'isBrowser').mockReturnValue(false);
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout',
|
|
implicitFlow: false,
|
|
refreshTokenTimeout: 100
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
jest.spyOn(oauth2Auth as any, 'silentRefresh').mockImplementation(function (this: any) {
|
|
this.pollingRefreshToken();
|
|
});
|
|
|
|
let calls = 0;
|
|
oauth2Auth.refreshToken = () => {
|
|
calls++;
|
|
return Promise.resolve();
|
|
};
|
|
|
|
setTimeout(() => {
|
|
assert.equal(calls > 2, true);
|
|
oauth2Auth.logOut();
|
|
done();
|
|
}, 600);
|
|
|
|
oauth2Auth.login('admin', 'admin');
|
|
});
|
|
|
|
it('should not hang the app also if the logout is missing', (done) => {
|
|
jest.spyOn(browserUtils, 'isBrowser').mockReturnValue(false);
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
secret: '',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout',
|
|
implicitFlow: false,
|
|
refreshTokenTimeout: 100
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
jest.spyOn(oauth2Auth as any, 'silentRefresh').mockImplementation(function (this: any) {
|
|
this.pollingRefreshToken();
|
|
});
|
|
|
|
let calls = 0;
|
|
oauth2Auth.refreshToken = () => {
|
|
calls++;
|
|
return Promise.resolve();
|
|
};
|
|
|
|
setTimeout(() => {
|
|
assert.equal(calls > 2, true);
|
|
done();
|
|
}, 600);
|
|
|
|
oauth2Auth.login('admin', 'admin');
|
|
});
|
|
|
|
it('should emit a token_issued event if login is ok ', (done) => {
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.once('token_issued', () => {
|
|
oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
|
|
oauth2Auth.login('admin', 'admin');
|
|
});
|
|
|
|
it('should not emit a token_issued event if setToken is null ', (done) => {
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
let counterCallEvent = 0;
|
|
oauth2Auth.once('token_issued', () => {
|
|
counterCallEvent++;
|
|
});
|
|
|
|
oauth2Auth.setToken(null, null);
|
|
oauth2Auth.setToken('200', null);
|
|
oauth2Auth.setToken(null, null);
|
|
|
|
assert.equal(counterCallEvent, 1);
|
|
|
|
done();
|
|
});
|
|
|
|
it('should emit a token_issued if provider is ECM', (done) => {
|
|
oauth2Mock.get200Response();
|
|
authResponseMock.get200ValidTicket();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
provider: 'ECM',
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.once('token_issued', () => {
|
|
oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
|
|
oauth2Auth.login('admin', 'admin');
|
|
});
|
|
|
|
it('should emit a token_issued if provider is ALL', (done) => {
|
|
oauth2Mock.get200Response();
|
|
authResponseMock.get200ValidTicket();
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
provider: 'ALL',
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.once('token_issued', () => {
|
|
oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
|
|
oauth2Auth.login('admin', 'admin');
|
|
});
|
|
|
|
it('should after token_issued event exchange the access_token for the alf_ticket', (done) => {
|
|
oauth2Mock.get200Response();
|
|
authResponseMock.get200ValidTicket();
|
|
|
|
const alfrescoApi = new AlfrescoApi({
|
|
hostEcm: 'https://myOauthUrl:30081',
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
});
|
|
|
|
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
|
|
assert.equal(alfrescoApi.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
|
assert.equal(alfrescoApi.contentClient.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
|
|
|
const content = new ContentApi(alfrescoApi);
|
|
const URL = content.getContentUrl('FAKE-NODE-ID');
|
|
assert.equal(
|
|
URL,
|
|
'https://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
|
);
|
|
|
|
alfrescoApi.oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
|
|
alfrescoApi.login('admin', 'admin');
|
|
});
|
|
|
|
it('should after token_issued event exchange the access_token for the alf_ticket with the compatibility layer', (done) => {
|
|
oauth2Mock.get200Response();
|
|
authResponseMock.get200ValidTicket();
|
|
|
|
const alfrescoApi = new AlfrescoApi({
|
|
hostEcm: 'https://myOauthUrl:30081',
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
});
|
|
|
|
const contentApi = new ContentApi(alfrescoApi);
|
|
|
|
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
|
|
assert.equal(alfrescoApi.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
|
assert.equal(alfrescoApi.contentClient.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
|
|
|
const URL = contentApi.getContentUrl('FAKE-NODE-ID');
|
|
assert.equal(
|
|
URL,
|
|
'https://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
|
);
|
|
alfrescoApi.oauth2Auth.logOut();
|
|
|
|
done();
|
|
});
|
|
|
|
alfrescoApi.login('admin', 'admin');
|
|
});
|
|
|
|
// TODO: very flaky test, fails on different machines if running slow, might relate to `this.timeout`
|
|
// eslint-disable-next-line ban/ban
|
|
xit('should extend content session after oauth token refresh', function (done) {
|
|
jest.setTimeout(3000);
|
|
|
|
oauth2Mock.get200Response();
|
|
authResponseMock.get200ValidTicket();
|
|
|
|
const alfrescoApi = new AlfrescoApi({
|
|
hostEcm: 'https://myOauthUrl:30081',
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
});
|
|
|
|
let counterCallEvent = 0;
|
|
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
|
|
assert.equal(alfrescoApi.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
|
assert.equal(alfrescoApi.contentClient.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
|
|
|
const content = new ContentApi(alfrescoApi);
|
|
const URL = content.getContentUrl('FAKE-NODE-ID');
|
|
assert.equal(
|
|
URL,
|
|
'https://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
|
);
|
|
|
|
counterCallEvent++;
|
|
|
|
if (counterCallEvent === 2) {
|
|
done();
|
|
}
|
|
});
|
|
|
|
alfrescoApi.login('admin', 'admin');
|
|
jest.setTimeout(3000);
|
|
alfrescoApi.refreshToken();
|
|
});
|
|
|
|
it('isLoggedIn should return true if the api is logged in', (done) => {
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.login('admin', 'admin').then(() => {
|
|
assert.equal(oauth2Auth.isLoggedIn(), true);
|
|
oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('login password should be removed after login', (done) => {
|
|
oauth2Mock.get200Response();
|
|
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.login('admin', 'admin').then(() => {
|
|
assert.notEqual(oauth2Auth.authentications.basicAuth.password, 'admin');
|
|
oauth2Auth.logOut();
|
|
done();
|
|
});
|
|
});
|
|
|
|
describe('With mocked DOM', () => {
|
|
it('a failed hash check calls the logout', (done) => {
|
|
const oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
|
|
oauth2Auth.createIframe();
|
|
|
|
const iframe = <HTMLIFrameElement>document.getElementById('silent_refresh_token_iframe');
|
|
iframe.contentWindow.location.hash = 'invalid';
|
|
|
|
let logoutCalled = false;
|
|
oauth2Auth.logOut = () => {
|
|
logoutCalled = true;
|
|
return Promise.resolve();
|
|
};
|
|
|
|
// invalid hash location leads to a reject which leads to a logout
|
|
oauth2Auth.iFrameHashListener();
|
|
assert.equal(logoutCalled, true);
|
|
done();
|
|
});
|
|
});
|
|
|
|
describe('public urls', () => {
|
|
let oauth2Auth: Oauth2Auth;
|
|
|
|
beforeEach(() => {
|
|
oauth2Auth = new Oauth2Auth(
|
|
{
|
|
oauth2: {
|
|
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
|
clientId: 'activiti',
|
|
scope: 'openid',
|
|
redirectUri: '/',
|
|
redirectUriLogout: '/logout'
|
|
},
|
|
authType: 'OAUTH'
|
|
},
|
|
alfrescoJsApi
|
|
);
|
|
window.location.assign('public-url');
|
|
});
|
|
|
|
it('should return true if PathMatcher.match returns true for matching url', () => {
|
|
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
|
|
oauth2Auth.pathMatcher = {
|
|
match: () => true
|
|
};
|
|
|
|
assert.equal(oauth2Auth.isPublicUrl(), true);
|
|
});
|
|
|
|
it('should return false if PathMatcher.match returns false for matching url', () => {
|
|
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
|
|
oauth2Auth.pathMatcher = {
|
|
match: () => false
|
|
};
|
|
|
|
assert.equal(oauth2Auth.isPublicUrl(), false);
|
|
});
|
|
|
|
it('should return false if publicUrls property is not defined', () => {
|
|
assert.equal(oauth2Auth.isPublicUrl(), false);
|
|
});
|
|
|
|
it('should return false if public urls is not set as an array list', () => {
|
|
oauth2Auth.config.oauth2.publicUrls = null;
|
|
assert.equal(oauth2Auth.isPublicUrl(), false);
|
|
});
|
|
|
|
it('should not call `implicitLogin`', async () => {
|
|
oauth2Auth.config.oauth2.silentLogin = true;
|
|
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
|
|
|
|
oauth2Auth.pathMatcher = {
|
|
match: () => true
|
|
};
|
|
|
|
let implicitLoginCalled = false;
|
|
oauth2Auth.implicitLogin = () => {
|
|
implicitLoginCalled = true;
|
|
};
|
|
|
|
await oauth2Auth.checkFragment();
|
|
assert.equal(implicitLoginCalled, false);
|
|
});
|
|
});
|
|
});
|
|
});
|