mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2795] SSO implicitflow (#3332)
* Enable OAUTH2 * Create SSO services * SSO improvements * Rollback sso login change * Add SSO configuration from Setting component * Refactoring * Remove login ECM/BPM toggle and move use the userpreference instead of store * fix host setting unit test * Fix unit test missing instance * use the Js api oauth * add logout component and clean sso not used class * fix dependencies cicle * add translation settings * fix style setting page * clean * JS APi should receive the oauth config from the userPreference and not from the config file * change login if SSO is present * missing spaces * add sso test in login component * add logout directive new properties test * Improve host setting and remove library reference * fix login test * Remove unused code * Fix authentication unit test * fix authguard unit test * fix csrf check login component * fix unit test core and demo shell * remove
This commit is contained in:
committed by
Eugenio Romano
parent
3a6c12e624
commit
f8e92b2fb0
@@ -19,11 +19,14 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { HostSettingsComponent } from './host-settings.component';
|
||||
import { setupTestBed } from '../testing/setupTestBed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { UserPreferencesService } from '../services/user-preferences.service';
|
||||
|
||||
describe('HostSettingsComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<HostSettingsComponent>;
|
||||
let component: HostSettingsComponent;
|
||||
let userPreferences: UserPreferencesService;
|
||||
let element: any;
|
||||
|
||||
setupTestBed({
|
||||
imports: [CoreTestingModule]
|
||||
@@ -32,96 +35,262 @@ describe('HostSettingsComponent', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(HostSettingsComponent);
|
||||
component = fixture.componentInstance;
|
||||
userPreferences = TestBed.get(UserPreferencesService);
|
||||
element = fixture.nativeElement;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should emit an error when the ECM url inserted is wrong', (done) => {
|
||||
fixture.detectChanges();
|
||||
describe('BPM ', () => {
|
||||
|
||||
component.error.subscribe((message: string) => {
|
||||
expect(message).toEqual('CORE.HOST_SETTING.CS_URL_ERROR');
|
||||
done();
|
||||
let ecmUrlInput;
|
||||
let bpmUrlInput;
|
||||
|
||||
beforeEach(() => {
|
||||
userPreferences.providers = 'BPM';
|
||||
fixture.detectChanges();
|
||||
bpmUrlInput = element.querySelector('#bpmHost');
|
||||
ecmUrlInput = element.querySelector('#ecmHost');
|
||||
});
|
||||
|
||||
const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost');
|
||||
ecmUrlInput.value = 'wrong_url';
|
||||
|
||||
const event: any = {};
|
||||
event.target = ecmUrlInput;
|
||||
component.onChangeECMHost(event);
|
||||
});
|
||||
|
||||
it('should emit ecmHostChange when the ECM url inserted is correct', (done) => {
|
||||
fixture.detectChanges();
|
||||
const url = 'http://localhost:9999/ecm';
|
||||
component.ecmHostChange.subscribe((message: string) => {
|
||||
expect(message).toEqual(url);
|
||||
done();
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost');
|
||||
ecmUrlInput.value = url;
|
||||
it('should have a valid form when the url inserted is correct', (done) => {
|
||||
const url = 'http://localhost:9999/bpm';
|
||||
|
||||
const event: any = {};
|
||||
event.target = ecmUrlInput;
|
||||
component.onChangeECMHost(event);
|
||||
});
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('VALID');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should emit an error when the BPM url inserted is wrong', (done) => {
|
||||
fixture.detectChanges();
|
||||
component.form.valueChanges.subscribe((values) => {
|
||||
expect(values.bpmHost).toEqual(url);
|
||||
});
|
||||
|
||||
component.error.subscribe((message: string) => {
|
||||
expect(message).toEqual('CORE.HOST_SETTING.PS_URL_ERROR');
|
||||
done();
|
||||
bpmUrlInput.value = url;
|
||||
bpmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
const bpmUrlInput: any = fixture.nativeElement.querySelector('#bpmHost');
|
||||
bpmUrlInput.value = 'wrong_url';
|
||||
it('should have an invalid form when the inserted is wrong', (done) => {
|
||||
const url = 'wrong';
|
||||
|
||||
const event: any = {};
|
||||
event.target = bpmUrlInput;
|
||||
component.onChangeBPMHost(event);
|
||||
});
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.bpmHost.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should emit bpmHostChange when the BPM url inserted is correct', (done) => {
|
||||
fixture.detectChanges();
|
||||
const url = 'http://localhost:9999/bpm';
|
||||
|
||||
component.ecmHostChange.subscribe((message: string) => {
|
||||
expect(message).toEqual(url);
|
||||
done();
|
||||
bpmUrlInput.value = url;
|
||||
bpmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
const ecmUrlInput = fixture.nativeElement.querySelector('#bpmHost');
|
||||
ecmUrlInput.value = url;
|
||||
it('should not render the ECM url config if setting provider is BPM', () => {
|
||||
expect(ecmUrlInput).toEqual(null);
|
||||
expect(bpmUrlInput).toBeDefined();
|
||||
});
|
||||
|
||||
const event: any = {};
|
||||
event.target = ecmUrlInput;
|
||||
component.onChangeECMHost(event);
|
||||
});
|
||||
|
||||
it('should not render the ECM url config if setting provider is BPM', () => {
|
||||
component.providers = 'BPM';
|
||||
describe('ECM ', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
let ecmUrlInput;
|
||||
let bpmUrlInput;
|
||||
|
||||
const bpmUrlInput = fixture.nativeElement.querySelector('#bpmHost');
|
||||
const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost');
|
||||
expect(ecmUrlInput).toEqual(null);
|
||||
expect(bpmUrlInput).toBeDefined();
|
||||
beforeEach(() => {
|
||||
userPreferences.providers = 'ECM';
|
||||
fixture.detectChanges();
|
||||
bpmUrlInput = element.querySelector('#bpmHost');
|
||||
ecmUrlInput = element.querySelector('#ecmHost');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should have a valid form when the url inserted is correct', (done) => {
|
||||
const url = 'http://localhost:9999/ecm';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('VALID');
|
||||
done();
|
||||
});
|
||||
|
||||
ecmUrlInput.value = url;
|
||||
ecmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have an invalid form when the url inserted is wrong', (done) => {
|
||||
const url = 'wrong';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.ecmHost.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
ecmUrlInput.value = url;
|
||||
ecmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should not render the BPM url config if setting provider is BPM', () => {
|
||||
expect(bpmUrlInput).toEqual(null);
|
||||
expect(ecmUrlInput).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should hide the BPM url config if setting provider is ECM', () => {
|
||||
component.providers = 'ECM';
|
||||
describe('ALL ', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
let ecmUrlInput;
|
||||
let bpmUrlInput;
|
||||
|
||||
beforeEach(() => {
|
||||
userPreferences.providers = 'ALL';
|
||||
fixture.detectChanges();
|
||||
bpmUrlInput = element.querySelector('#bpmHost');
|
||||
ecmUrlInput = element.querySelector('#ecmHost');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should have a valid form when the BPM and ECM url inserted are correct', (done) => {
|
||||
const urlEcm = 'http://localhost:9999/ecm';
|
||||
const urlBpm = 'http://localhost:9999/bpm';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('VALID');
|
||||
done();
|
||||
});
|
||||
|
||||
ecmUrlInput.value = urlEcm;
|
||||
bpmUrlInput.value = urlBpm;
|
||||
ecmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have an invalid form when one of the ECM url inserted is wrong', (done) => {
|
||||
const url = 'wrong';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.ecmHost.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
ecmUrlInput.value = url;
|
||||
ecmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have an invalid form when one of the BPM url inserted is wrong', (done) => {
|
||||
const url = 'wrong';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.bpmHost.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
bpmUrlInput.value = url;
|
||||
bpmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have an invalid form when both BPM and ECM url inserted are wrong', (done) => {
|
||||
const url = 'wrong';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.bpmHost.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
bpmUrlInput.value = url;
|
||||
ecmUrlInput.value = url;
|
||||
bpmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
const ecmUrlInput = fixture.nativeElement.querySelector('#ecmHost');
|
||||
const bpmUrlInput = fixture.nativeElement.querySelector('#bpmHost');
|
||||
expect(bpmUrlInput).toEqual(null);
|
||||
expect(ecmUrlInput).toBeDefined();
|
||||
});
|
||||
|
||||
describe('OAUTH ', () => {
|
||||
|
||||
let ecmUrlInput;
|
||||
let bpmUrlInput;
|
||||
let oauthHostUrlInput;
|
||||
let clientIdInput;
|
||||
|
||||
beforeEach(() => {
|
||||
userPreferences.providers = 'OAUTH';
|
||||
userPreferences.oauthConfig = {
|
||||
host: 'http://localhost:6543',
|
||||
redirectUri: '/',
|
||||
silentLogin: false,
|
||||
implicitFlow: true,
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: ''
|
||||
};
|
||||
fixture.detectChanges();
|
||||
bpmUrlInput = element.querySelector('#bpmHost');
|
||||
oauthHostUrlInput = element.querySelector('#oauthHost');
|
||||
clientIdInput = element.querySelector('#clientId');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should have a valid form when the BPM is correct', (done) => {
|
||||
const urlBpm = 'http://localhost:9999/bpm';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('VALID');
|
||||
done();
|
||||
});
|
||||
|
||||
bpmUrlInput.value = urlBpm;
|
||||
bpmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have an invalid form when the url inserted is wrong', (done) => {
|
||||
const url = 'wrong';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.bpmHost.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
bpmUrlInput.value = url;
|
||||
bpmUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have an invalid form when the host is wrong', (done) => {
|
||||
const hostUrl = 'wrong';
|
||||
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.host.hasError('pattern')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
oauthHostUrlInput.value = hostUrl;
|
||||
oauthHostUrlInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
it('should have a required clientId an invalid form when the clientId is missing', (done) => {
|
||||
component.form.statusChanges.subscribe((status: string) => {
|
||||
expect(status).toEqual('INVALID');
|
||||
expect(component.clientId.hasError('required')).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
clientIdInput.value = '';
|
||||
clientIdInput.dispatchEvent(new Event('input'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user