Merge remote-tracking branch 'remotes/origin/master' into shibboleth

# Conflicts:
#	src/app/core/auth/auth.actions.ts
#	src/app/core/auth/auth.effects.spec.ts
#	src/app/core/auth/auth.effects.ts
#	src/app/core/auth/auth.reducer.spec.ts
#	src/app/core/auth/auth.reducer.ts
#	src/app/core/auth/auth.service.spec.ts
#	src/app/core/auth/auth.service.ts
#	src/app/core/auth/server-auth.service.ts
#	src/app/shared/testing/auth-request-service-stub.ts
This commit is contained in:
Giuseppe Digilio
2020-03-03 20:04:02 +01:00
113 changed files with 3503 additions and 2724 deletions

View File

@@ -19,6 +19,9 @@ import {
LogOutSuccessAction,
RefreshTokenErrorAction,
RefreshTokenSuccessAction,
RetrieveAuthenticatedEpersonAction,
RetrieveAuthenticatedEpersonErrorAction,
RetrieveAuthenticatedEpersonSuccessAction,
RetrieveAuthMethodsAction,
RetrieveAuthMethodsErrorAction,
RetrieveAuthMethodsSuccessAction,
@@ -27,7 +30,6 @@ import {
import { authMethodsMock, AuthServiceStub } from '../../shared/testing/auth-service-stub';
import { AuthService } from './auth.service';
import { AuthState } from './auth.reducer';
import { EPersonMock } from '../../shared/testing/eperson-mock';
import { AuthStatus } from './models/auth-status.model';
@@ -47,13 +49,14 @@ describe('AuthEffects', () => {
authServiceStub = new AuthServiceStub();
token = authServiceStub.getToken();
}
beforeEach(() => {
init();
TestBed.configureTestingModule({
providers: [
AuthEffects,
{provide: AuthService, useValue: authServiceStub},
{provide: Store, useValue: store},
{ provide: AuthService, useValue: authServiceStub },
{ provide: Store, useValue: store },
provideMockActions(() => actions),
// other providers
],
@@ -68,11 +71,11 @@ describe('AuthEffects', () => {
actions = hot('--a-', {
a: {
type: AuthActionTypes.AUTHENTICATE,
payload: {email: 'user', password: 'password'}
payload: { email: 'user', password: 'password' }
}
});
const expected = cold('--b-', {b: new AuthenticationSuccessAction(token)});
const expected = cold('--b-', { b: new AuthenticationSuccessAction(token) });
expect(authEffects.authenticate$).toBeObservable(expected);
});
@@ -85,11 +88,11 @@ describe('AuthEffects', () => {
actions = hot('--a-', {
a: {
type: AuthActionTypes.AUTHENTICATE,
payload: {email: 'user', password: 'wrongpassword'}
payload: { email: 'user', password: 'wrongpassword' }
}
});
const expected = cold('--b-', {b: new AuthenticationErrorAction(new Error('Message Error test'))});
const expected = cold('--b-', { b: new AuthenticationErrorAction(new Error('Message Error test')) });
expect(authEffects.authenticate$).toBeObservable(expected);
});
@@ -99,9 +102,9 @@ describe('AuthEffects', () => {
describe('authenticateSuccess$', () => {
it('should return a AUTHENTICATED action in response to a AUTHENTICATE_SUCCESS action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.AUTHENTICATE_SUCCESS, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.AUTHENTICATE_SUCCESS, payload: token } });
const expected = cold('--b-', {b: new AuthenticatedAction(token)});
const expected = cold('--b-', { b: new AuthenticatedAction(token) });
expect(authEffects.authenticateSuccess$).toBeObservable(expected);
});
@@ -111,9 +114,9 @@ describe('AuthEffects', () => {
describe('when token is valid', () => {
it('should return a AUTHENTICATED_SUCCESS action in response to a AUTHENTICATED action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.AUTHENTICATED, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.AUTHENTICATED, payload: token } });
const expected = cold('--b-', {b: new AuthenticatedSuccessAction(true, token, EPersonMock)});
const expected = cold('--b-', { b: new AuthenticatedSuccessAction(true, token, EPersonMock._links.self.href) });
expect(authEffects.authenticated$).toBeObservable(expected);
});
@@ -123,23 +126,42 @@ describe('AuthEffects', () => {
it('should return a AUTHENTICATED_ERROR action in response to a AUTHENTICATED action', () => {
spyOn((authEffects as any).authService, 'authenticatedUser').and.returnValue(observableThrow(new Error('Message Error test')));
actions = hot('--a-', {a: {type: AuthActionTypes.AUTHENTICATED, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.AUTHENTICATED, payload: token } });
const expected = cold('--b-', {b: new AuthenticatedErrorAction(new Error('Message Error test'))});
const expected = cold('--b-', { b: new AuthenticatedErrorAction(new Error('Message Error test')) });
expect(authEffects.authenticated$).toBeObservable(expected);
});
});
});
describe('authenticatedSuccess$', () => {
it('should return a RETRIEVE_AUTHENTICATED_EPERSON action in response to a AUTHENTICATED_SUCCESS action', () => {
actions = hot('--a-', {
a: {
type: AuthActionTypes.AUTHENTICATED_SUCCESS, payload: {
authenticated: true,
authToken: token,
userHref: EPersonMock._links.self.href
}
}
});
const expected = cold('--b-', { b: new RetrieveAuthenticatedEpersonAction(EPersonMock._links.self.href) });
expect(authEffects.authenticatedSuccess$).toBeObservable(expected);
});
});
describe('checkToken$', () => {
describe('when check token succeeded', () => {
it('should return a AUTHENTICATED action in response to a CHECK_AUTHENTICATION_TOKEN action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN}});
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN } });
const expected = cold('--b-', {b: new AuthenticatedAction(token)});
const expected = cold('--b-', { b: new AuthenticatedAction(token) });
expect(authEffects.checkToken$).toBeObservable(expected);
});
@@ -149,9 +171,9 @@ describe('AuthEffects', () => {
it('should return a CHECK_AUTHENTICATION_TOKEN_ERROR action in response to a CHECK_AUTHENTICATION_TOKEN action', () => {
spyOn((authEffects as any).authService, 'hasValidAuthenticationToken').and.returnValue(observableThrow(''));
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN, payload: token } });
const expected = cold('--b-', {b: new CheckAuthenticationTokenCookieAction()});
const expected = cold('--b-', { b: new CheckAuthenticationTokenCookieAction() });
expect(authEffects.checkToken$).toBeObservable(expected);
});
@@ -164,12 +186,13 @@ describe('AuthEffects', () => {
it('should return a RETRIEVE_TOKEN action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action when authenticated is true', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(
observableOf(
{ authenticated: true
{
authenticated: true
})
);
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE}});
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE } });
const expected = cold('--b-', {b: new RetrieveTokenAction()});
const expected = cold('--b-', { b: new RetrieveTokenAction() });
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
@@ -179,9 +202,9 @@ describe('AuthEffects', () => {
observableOf(
{ authenticated: false })
);
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE}});
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE } });
const expected = cold('--b-', {b: new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus)});
const expected = cold('--b-', { b: new RetrieveAuthMethodsAction({ authenticated: false } as AuthStatus) });
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
@@ -191,23 +214,53 @@ describe('AuthEffects', () => {
it('should return a AUTHENTICATED_ERROR action in response to a CHECK_AUTHENTICATION_TOKEN_COOKIE action', () => {
spyOn((authEffects as any).authService, 'checkAuthenticationCookie').and.returnValue(observableThrow(new Error('Message Error test')));
actions = hot('--a-', {a: {type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.CHECK_AUTHENTICATION_TOKEN_COOKIE, payload: token } });
const expected = cold('--b-', {b: new AuthenticatedErrorAction(new Error('Message Error test'))});
const expected = cold('--b-', { b: new AuthenticatedErrorAction(new Error('Message Error test')) });
expect(authEffects.checkTokenCookie$).toBeObservable(expected);
});
})
});
describe('retrieveAuthenticatedEperson$', () => {
describe('when request is successful', () => {
it('should return a RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS action in response to a RETRIEVE_AUTHENTICATED_EPERSON action', () => {
actions = hot('--a-', {
a: {
type: AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON,
payload: EPersonMock._links.self.href
}
});
const expected = cold('--b-', { b: new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock) });
expect(authEffects.retrieveAuthenticatedEperson$).toBeObservable(expected);
});
});
describe('when request is not successful', () => {
it('should return a RETRIEVE_AUTHENTICATED_EPERSON_ERROR action in response to a RETRIEVE_AUTHENTICATED_EPERSON action', () => {
spyOn((authEffects as any).authService, 'retrieveAuthenticatedUserByHref').and.returnValue(observableThrow(new Error('Message Error test')));
actions = hot('--a-', { a: { type: AuthActionTypes.RETRIEVE_AUTHENTICATED_EPERSON, payload: token } });
const expected = cold('--b-', { b: new RetrieveAuthenticatedEpersonErrorAction(new Error('Message Error test')) });
expect(authEffects.retrieveAuthenticatedEperson$).toBeObservable(expected);
});
});
});
describe('refreshToken$', () => {
describe('when refresh token succeeded', () => {
it('should return a REFRESH_TOKEN_SUCCESS action in response to a REFRESH_TOKEN action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.REFRESH_TOKEN}});
actions = hot('--a-', { a: { type: AuthActionTypes.REFRESH_TOKEN } });
const expected = cold('--b-', {b: new RefreshTokenSuccessAction(token)});
const expected = cold('--b-', { b: new RefreshTokenSuccessAction(token) });
expect(authEffects.refreshToken$).toBeObservable(expected);
});
@@ -217,9 +270,9 @@ describe('AuthEffects', () => {
it('should return a REFRESH_TOKEN_ERROR action in response to a REFRESH_TOKEN action', () => {
spyOn((authEffects as any).authService, 'refreshAuthenticationToken').and.returnValue(observableThrow(''));
actions = hot('--a-', {a: {type: AuthActionTypes.REFRESH_TOKEN, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.REFRESH_TOKEN, payload: token } });
const expected = cold('--b-', {b: new RefreshTokenErrorAction()});
const expected = cold('--b-', { b: new RefreshTokenErrorAction() });
expect(authEffects.refreshToken$).toBeObservable(expected);
});
@@ -235,7 +288,7 @@ describe('AuthEffects', () => {
}
});
const expected = cold('--b-', {b: new AuthenticationSuccessAction(token)});
const expected = cold('--b-', { b: new AuthenticationSuccessAction(token) });
expect(authEffects.retrieveToken$).toBeObservable(expected);
});
@@ -251,7 +304,7 @@ describe('AuthEffects', () => {
}
});
const expected = cold('--b-', {b: new AuthenticationErrorAction(new Error('Message Error test'))});
const expected = cold('--b-', { b: new AuthenticationErrorAction(new Error('Message Error test')) });
expect(authEffects.retrieveToken$).toBeObservable(expected);
});
@@ -263,9 +316,9 @@ describe('AuthEffects', () => {
describe('when refresh token succeeded', () => {
it('should return a LOG_OUT_SUCCESS action in response to a LOG_OUT action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.LOG_OUT}});
actions = hot('--a-', { a: { type: AuthActionTypes.LOG_OUT } });
const expected = cold('--b-', {b: new LogOutSuccessAction()});
const expected = cold('--b-', { b: new LogOutSuccessAction() });
expect(authEffects.logOut$).toBeObservable(expected);
});
@@ -275,9 +328,9 @@ describe('AuthEffects', () => {
it('should return a REFRESH_TOKEN_ERROR action in response to a LOG_OUT action', () => {
spyOn((authEffects as any).authService, 'logout').and.returnValue(observableThrow(new Error('Message Error test')));
actions = hot('--a-', {a: {type: AuthActionTypes.LOG_OUT, payload: token}});
actions = hot('--a-', { a: { type: AuthActionTypes.LOG_OUT, payload: token } });
const expected = cold('--b-', {b: new LogOutErrorAction(new Error('Message Error test'))});
const expected = cold('--b-', { b: new LogOutErrorAction(new Error('Message Error test')) });
expect(authEffects.logOut$).toBeObservable(expected);
});
@@ -288,9 +341,9 @@ describe('AuthEffects', () => {
describe('when retrieve authentication methods succeeded', () => {
it('should return a RETRIEVE_AUTH_METHODS_SUCCESS action in response to a RETRIEVE_AUTH_METHODS action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.RETRIEVE_AUTH_METHODS}});
actions = hot('--a-', { a: { type: AuthActionTypes.RETRIEVE_AUTH_METHODS } });
const expected = cold('--b-', {b: new RetrieveAuthMethodsSuccessAction(authMethodsMock)});
const expected = cold('--b-', { b: new RetrieveAuthMethodsSuccessAction(authMethodsMock) });
expect(authEffects.retrieveMethods$).toBeObservable(expected);
});
@@ -300,9 +353,9 @@ describe('AuthEffects', () => {
it('should return a RETRIEVE_AUTH_METHODS_ERROR action in response to a RETRIEVE_AUTH_METHODS action', () => {
spyOn((authEffects as any).authService, 'retrieveAuthMethodsFromAuthStatus').and.returnValue(observableThrow(''));
actions = hot('--a-', {a: {type: AuthActionTypes.RETRIEVE_AUTH_METHODS}});
actions = hot('--a-', { a: { type: AuthActionTypes.RETRIEVE_AUTH_METHODS } });
const expected = cold('--b-', {b: new RetrieveAuthMethodsErrorAction()});
const expected = cold('--b-', { b: new RetrieveAuthMethodsErrorAction() });
expect(authEffects.retrieveMethods$).toBeObservable(expected);
});