mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2200] fixed problem with redirection url (#2877)
* [ADF-2200] fixed wrong handling of redirectUrl * [ADF-2200] fixed problem with redirection url * [ADF-2200] fixed redirection config path * [ADF-2200] fixed wrong fdescribe test * [ADF-2200] removed authserviceMock and fixed some tests
This commit is contained in:
@@ -26,8 +26,8 @@ import { AuthenticationService } from '../../services/authentication.service';
|
||||
import { MaterialModule } from '../../material.module';
|
||||
import { LoginErrorEvent } from '../models/login-error.event';
|
||||
import { LoginSuccessEvent } from '../models/login-success.event';
|
||||
import { AuthenticationMock } from './../../mock/authentication.service.mock';
|
||||
import { LoginComponent } from './login.component';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
describe('LoginComponent', () => {
|
||||
let component: LoginComponent;
|
||||
@@ -64,7 +64,7 @@ describe('LoginComponent', () => {
|
||||
LoginComponent
|
||||
],
|
||||
providers: [
|
||||
{provide: AuthenticationService, useClass: AuthenticationMock}
|
||||
AuthenticationService
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
@@ -101,6 +101,7 @@ describe('LoginComponent', () => {
|
||||
}
|
||||
|
||||
it('should redirect to route on successful login', () => {
|
||||
spyOn(authService, 'login').and.returnValue(Observable.of({ type: 'type', ticket: 'ticket'}));
|
||||
const redirect = '/home';
|
||||
component.successRoute = redirect;
|
||||
spyOn(router, 'navigate');
|
||||
@@ -109,9 +110,10 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
it('should redirect to previous route state on successful login', () => {
|
||||
spyOn(authService, 'login').and.returnValue(Observable.of({ type: 'type', ticket: 'ticket'}));
|
||||
const redirect = '/home';
|
||||
component.successRoute = redirect;
|
||||
authService.setRedirectUrl('redirect-url');
|
||||
authService.setRedirectUrl({ provider: 'ECM', url: 'redirect-url' } );
|
||||
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
@@ -152,12 +154,14 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
it('should be changed back to the default after a failed login attempt', () => {
|
||||
spyOn(authService, 'login').and.returnValue(Observable.throw('Fake server error'));
|
||||
loginWithCredentials('fake-wrong-username', 'fake-wrong-password');
|
||||
|
||||
expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.LOGIN');
|
||||
});
|
||||
|
||||
it('should be changed to the "welcome key" after a successful login attempt', () => {
|
||||
spyOn(authService, 'login').and.returnValue(Observable.of({ type: 'type', ticket: 'ticket'}));
|
||||
loginWithCredentials('fake-username', 'fake-password');
|
||||
|
||||
expect(getLoginButtonText()).toEqual('LOGIN.BUTTON.WELCOME');
|
||||
@@ -436,6 +440,12 @@ describe('LoginComponent', () => {
|
||||
}));
|
||||
|
||||
it('should return CORS error when server CORS error occurs', async(() => {
|
||||
spyOn(authService, 'login').and.returnValue(Observable.throw({
|
||||
error: {
|
||||
crossDomain: true,
|
||||
message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin'
|
||||
}
|
||||
}));
|
||||
component.providers = 'ECM';
|
||||
|
||||
component.error.subscribe(() => {
|
||||
@@ -450,6 +460,8 @@ describe('LoginComponent', () => {
|
||||
}));
|
||||
|
||||
it('should return CSRF error when server CSRF error occurs', async(() => {
|
||||
spyOn(authService, 'login')
|
||||
.and.returnValue(Observable.throw({ message: 'ERROR: Invalid CSRF-token', status: 403 }));
|
||||
component.providers = 'ECM';
|
||||
|
||||
component.error.subscribe(() => {
|
||||
@@ -464,6 +476,14 @@ describe('LoginComponent', () => {
|
||||
}));
|
||||
|
||||
it('should return ECOM read-oly error when error occurs', async(() => {
|
||||
spyOn(authService, 'login')
|
||||
.and.returnValue(
|
||||
Observable.throw(
|
||||
{
|
||||
message: 'ERROR: 00170728 Access Denied. The system is currently in read-only mode',
|
||||
status: 403
|
||||
}
|
||||
));
|
||||
component.providers = 'ECM';
|
||||
|
||||
component.error.subscribe(() => {
|
||||
@@ -493,6 +513,7 @@ describe('LoginComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit error event after the login has failed', async(() => {
|
||||
spyOn(authService, 'login').and.returnValue(Observable.throw('Fake server error'));
|
||||
component.providers = 'ECM';
|
||||
|
||||
component.error.subscribe((error) => {
|
||||
|
@@ -213,7 +213,7 @@ export class LoginComponent implements OnInit {
|
||||
this.authService.login(values.username, values.password, this.rememberMe)
|
||||
.subscribe(
|
||||
(token: any) => {
|
||||
const redirectUrl = this.authService.getRedirectUrl();
|
||||
const redirectUrl = this.authService.getRedirectUrl(this.providers);
|
||||
|
||||
this.actualLoginStep = LoginSteps.Welcome;
|
||||
this.userPreferences.setStoragePrefix(values.username);
|
||||
|
Reference in New Issue
Block a user