mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5332] Login basic auth - Ability to override the successRoute from app.config.json (#6651)
* ability to override successRoute from app.config * Add basic doc * Reset the appconfig * Rebase and handle login errors * Remove the default route / * remove space
This commit is contained in:
@@ -124,7 +124,44 @@ describe('LoginComponent', () => {
|
||||
expect(router.navigate).toHaveBeenCalledWith([redirect]);
|
||||
});
|
||||
|
||||
it('should use the input successRoute as redirect if defined', () => {
|
||||
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
component.successRoute = 'input-route';
|
||||
appConfigService.config = {};
|
||||
|
||||
component.ngOnInit();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['input-route']);
|
||||
});
|
||||
|
||||
it('should use the successRoute route from app.config if the input successRoute is NOT defined', () => {
|
||||
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
component.successRoute = undefined;
|
||||
appConfigService.config.successRoute = 'route-app-config';
|
||||
|
||||
component.ngOnInit();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['route-app-config']);
|
||||
});
|
||||
|
||||
it('should use the successRoute route from app.config if both successRoute are defined', () => {
|
||||
spyOn(authService, 'isLoggedIn').and.returnValue(true);
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
component.successRoute = 'input-route';
|
||||
appConfigService.config.successRoute = 'route-app-config';
|
||||
|
||||
component.ngOnInit();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['route-app-config']);
|
||||
});
|
||||
|
||||
it('should redirect to previous route state on successful login', () => {
|
||||
appConfigService.config = {};
|
||||
appConfigService.config.providers = 'ECM';
|
||||
|
||||
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||
|
@@ -150,6 +150,8 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
this.initFormFieldsDefault();
|
||||
this.initFormFieldsMessages();
|
||||
|
||||
this.successRoute = this.appConfig.get<string>('successRoute', this.successRoute);
|
||||
|
||||
if (this.authService.isLoggedIn()) {
|
||||
this.router.navigate([this.successRoute]);
|
||||
} else {
|
||||
|
@@ -93,7 +93,13 @@ export class ApiService {
|
||||
async loginWithProfile(profileName: string): Promise<void> {
|
||||
const profile = browser.params.testConfig.users[profileName];
|
||||
if (profile) {
|
||||
await this.apiService.login(profile.username, profile.password);
|
||||
Logger.log(`try to login with ${profile.username} on HOST: ${this.apiService.config.hostEcm} AUTHTYPE: ${this.apiService.config.authType} PROVIDER: ${this.apiService.config.provider}`);
|
||||
try {
|
||||
await this.apiService.login(profile.username, profile.password);
|
||||
} catch (error) {
|
||||
Logger.error(`Failed to login with ${profile.username}`, error.message);
|
||||
throw new Error(`Login failed with ${profile.username}`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Login profile "${profileName}" not found on "browser.params.testConfig".`);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import { BrowserActions } from '../../core/utils/browser-actions';
|
||||
import { BrowserVisibility } from '../../core/utils/browser-visibility';
|
||||
import { ContentNodeSelectorDialogPage } from '../../content-services/dialog/content-node-selector-dialog.page';
|
||||
import { DocumentListPage } from '../../content-services/pages/document-list.page';
|
||||
|
||||
import { Logger } from '../../core/utils/logger';
|
||||
export class ExternalNodeSelectorDialogPage extends ContentNodeSelectorDialogPage {
|
||||
txtUsername = element(by.css('input[id="username"]'));
|
||||
txtPassword = element(by.css('input[id="password"]'));
|
||||
@@ -63,6 +63,7 @@ export class ExternalNodeSelectorDialogPage extends ContentNodeSelectorDialogPag
|
||||
}
|
||||
|
||||
async login(username, password): Promise<void> {
|
||||
Logger.log('Login external With ' + username);
|
||||
await this.waitForLogInDialog();
|
||||
await this.enterUsername(username);
|
||||
await this.enterPassword(password);
|
||||
|
Reference in New Issue
Block a user