Fixes for authentication (awaiting fixes in EPerson REST endpoint)

This commit is contained in:
lotte
2018-09-12 11:38:08 +02:00
parent 0455a16d03
commit caf9194f36
17 changed files with 96 additions and 50 deletions

View File

@@ -1,14 +1,14 @@
import { AuthType } from './auth-type'; import { AuthType } from './auth-type';
import { GenericConstructor } from '../shared/generic-constructor'; import { GenericConstructor } from '../shared/generic-constructor';
import { NormalizedAuthStatus } from './models/normalized-auth-status.model'; import { NormalizedAuthStatus } from './models/normalized-auth-status.model';
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model'; import { NormalizedEperson } from '../eperson/models/NormalizedEperson.model';
import { NormalizedEpersonModel } from '../eperson/models/NormalizedEperson.model'; import { NormalizedObject } from '../cache/models/normalized-object.model';
export class AuthObjectFactory { export class AuthObjectFactory {
public static getConstructor(type): GenericConstructor<NormalizedDSpaceObject> { public static getConstructor(type): GenericConstructor<NormalizedObject> {
switch (type) { switch (type) {
case AuthType.Eperson: { case AuthType.Eperson: {
return NormalizedEpersonModel return NormalizedEperson
} }
case AuthType.Status: { case AuthType.Status: {

View File

@@ -8,12 +8,13 @@ import { CoreState } from '../core.reducers';
import { AuthStatus } from './models/auth-status.model'; import { AuthStatus } from './models/auth-status.model';
import { AuthResponseParsingService } from './auth-response-parsing.service'; import { AuthResponseParsingService } from './auth-response-parsing.service';
import { AuthGetRequest, AuthPostRequest } from '../data/request.models'; import { AuthGetRequest, AuthPostRequest } from '../data/request.models';
import { getMockStore } from '../../shared/mocks/mock-store';
describe('ConfigResponseParsingService', () => { describe('AuthResponseParsingService', () => {
let service: AuthResponseParsingService; let service: AuthResponseParsingService;
const EnvConfig = {} as GlobalConfig; const EnvConfig = {cache: {msToLive: 1000}} as GlobalConfig;
const store = {} as Store<CoreState>; const store = getMockStore() as Store<CoreState>;
const objectCacheService = new ObjectCacheService(store); const objectCacheService = new ObjectCacheService(store);
beforeEach(() => { beforeEach(() => {
@@ -86,13 +87,19 @@ describe('ConfigResponseParsingService', () => {
type: 'eperson', type: 'eperson',
uuid: '4dc70ab5-cd73-492f-b007-3179d2d9296b', uuid: '4dc70ab5-cd73-492f-b007-3179d2d9296b',
_links: { _links: {
self: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/eperson/epersons/4dc70ab5-cd73-492f-b007-3179d2d9296b' self: {
href: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/eperson/epersons/4dc70ab5-cd73-492f-b007-3179d2d9296b'
}
} }
} }
}, },
_links: { _links: {
eperson: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/eperson/epersons/4dc70ab5-cd73-492f-b007-3179d2d9296b', eperson: {
self: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/authn/status' href: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/eperson/epersons/4dc70ab5-cd73-492f-b007-3179d2d9296b'
},
self: {
href: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/authn/status'
}
} }
}, },
statusCode: '200' statusCode: '200'

View File

@@ -12,22 +12,23 @@ import { ResponseParsingService } from '../data/parsing.service';
import { RestRequest } from '../data/request.models'; import { RestRequest } from '../data/request.models';
import { AuthType } from './auth-type'; import { AuthType } from './auth-type';
import { AuthStatus } from './models/auth-status.model'; import { AuthStatus } from './models/auth-status.model';
import { NormalizedAuthStatus } from './models/normalized-auth-status.model';
@Injectable() @Injectable()
export class AuthResponseParsingService extends BaseResponseParsingService implements ResponseParsingService { export class AuthResponseParsingService extends BaseResponseParsingService implements ResponseParsingService {
protected objectFactory = AuthObjectFactory; protected objectFactory = AuthObjectFactory;
protected toCache = false; protected toCache = true;
constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, constructor(@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
protected objectCache: ObjectCacheService,) { protected objectCache: ObjectCacheService) {
super(); super();
} }
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === '200' || data.statusCode === 'OK')) { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === '200' || data.statusCode === 'OK')) {
const response = this.process<AuthStatus, AuthType>(data.payload, request.href); const response = this.process<NormalizedAuthStatus, AuthType>(data.payload, request.href);
return new AuthStatusResponse(response[Object.keys(response)[0]][0], data.statusCode); return new AuthStatusResponse(response, data.statusCode);
} else { } else {
return new AuthStatusResponse(data.payload as AuthStatus, data.statusCode); return new AuthStatusResponse(data.payload as AuthStatus, data.statusCode);
} }

View File

@@ -30,7 +30,6 @@ import { EpersonMock } from '../../shared/testing/eperson-mock';
describe('AuthEffects', () => { describe('AuthEffects', () => {
let authEffects: AuthEffects; let authEffects: AuthEffects;
let actions: Observable<any>; let actions: Observable<any>;
const authServiceStub = new AuthServiceStub(); const authServiceStub = new AuthServiceStub();
const store: Store<TruncatablesState> = jasmine.createSpyObj('store', { const store: Store<TruncatablesState> = jasmine.createSpyObj('store', {
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */

View File

@@ -22,6 +22,8 @@ import { Eperson } from '../eperson/models/eperson.model';
import { EpersonMock } from '../../shared/testing/eperson-mock'; import { EpersonMock } from '../../shared/testing/eperson-mock';
import { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
import { ClientCookieService } from '../../shared/services/client-cookie.service'; import { ClientCookieService } from '../../shared/services/client-cookie.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-data-build.service';
describe('AuthService test', () => { describe('AuthService test', () => {
@@ -44,7 +46,7 @@ describe('AuthService test', () => {
authToken: token, authToken: token,
user: EpersonMock user: EpersonMock
}; };
const rdbService = getMockRemoteDataBuildService();
describe('', () => { describe('', () => {
beforeEach(() => { beforeEach(() => {
@@ -61,6 +63,7 @@ describe('AuthService test', () => {
{provide: Router, useValue: routerStub}, {provide: Router, useValue: routerStub},
{provide: ActivatedRoute, useValue: routeStub}, {provide: ActivatedRoute, useValue: routeStub},
{provide: Store, useValue: mockStore}, {provide: Store, useValue: mockStore},
{provide: RemoteDataBuildService, useValue: rdbService},
CookieService, CookieService,
AuthService AuthService
], ],
@@ -121,6 +124,7 @@ describe('AuthService test', () => {
{provide: AuthRequestService, useValue: authRequest}, {provide: AuthRequestService, useValue: authRequest},
{provide: REQUEST, useValue: {}}, {provide: REQUEST, useValue: {}},
{provide: Router, useValue: routerStub}, {provide: Router, useValue: routerStub},
{provide: RemoteDataBuildService, useValue: rdbService},
CookieService CookieService
] ]
}).compileComponents(); }).compileComponents();
@@ -132,7 +136,7 @@ describe('AuthService test', () => {
(state as any).core = Object.create({}); (state as any).core = Object.create({});
(state as any).core.auth = authenticatedState; (state as any).core.auth = authenticatedState;
}); });
authService = new AuthService({}, window, authReqService, router, cookieService, store); authService = new AuthService({}, window, authReqService, router, cookieService, store, rdbService);
})); }));
it('should return true when user is logged in', () => { it('should return true when user is logged in', () => {
@@ -191,7 +195,7 @@ describe('AuthService test', () => {
(state as any).core = Object.create({}); (state as any).core = Object.create({});
(state as any).core.auth = authenticatedState; (state as any).core.auth = authenticatedState;
}); });
authService = new AuthService({}, window, authReqService, router, cookieService, store); authService = new AuthService({}, window, authReqService, router, cookieService, store, rdbService);
storage = (authService as any).storage; storage = (authService as any).storage;
spyOn(storage, 'get'); spyOn(storage, 'get');
spyOn(storage, 'remove'); spyOn(storage, 'remove');

View File

@@ -7,7 +7,7 @@ import { RouterReducerState } from '@ngrx/router-store';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { CookieAttributes } from 'js-cookie'; import { CookieAttributes } from 'js-cookie';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { map, withLatestFrom } from 'rxjs/operators'; import { map, switchMap, withLatestFrom } from 'rxjs/operators';
import { Eperson } from '../eperson/models/eperson.model'; import { Eperson } from '../eperson/models/eperson.model';
import { AuthRequestService } from './auth-request.service'; import { AuthRequestService } from './auth-request.service';
@@ -17,11 +17,18 @@ import { AuthStatus } from './models/auth-status.model';
import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model'; import { AuthTokenInfo, TOKENITEM } from './models/auth-token-info.model';
import { isEmpty, isNotEmpty, isNotNull, isNotUndefined } from '../../shared/empty.util'; import { isEmpty, isNotEmpty, isNotNull, isNotUndefined } from '../../shared/empty.util';
import { CookieService } from '../../shared/services/cookie.service'; import { CookieService } from '../../shared/services/cookie.service';
import { getAuthenticationToken, getRedirectUrl, isAuthenticated, isTokenRefreshing } from './selectors'; import {
getAuthenticationToken,
getRedirectUrl,
isAuthenticated,
isTokenRefreshing
} from './selectors';
import { AppState, routerStateSelector } from '../../app.reducer'; import { AppState, routerStateSelector } from '../../app.reducer';
import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.actions'; import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.actions';
import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service'; import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service';
import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util'; import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedEperson } from '../eperson/models/NormalizedEperson.model';
export const LOGIN_ROUTE = '/login'; export const LOGIN_ROUTE = '/login';
export const LOGOUT_ROUTE = '/logout'; export const LOGOUT_ROUTE = '/logout';
@@ -45,7 +52,9 @@ export class AuthService {
protected authRequestService: AuthRequestService, protected authRequestService: AuthRequestService,
protected router: Router, protected router: Router,
protected storage: CookieService, protected storage: CookieService,
protected store: Store<AppState>) { protected store: Store<AppState>,
protected rdbService: RemoteDataBuildService
) {
this.store.select(isAuthenticated) this.store.select(isAuthenticated)
.startWith(false) .startWith(false)
.subscribe((authenticated: boolean) => this._authenticated = authenticated); .subscribe((authenticated: boolean) => this._authenticated = authenticated);
@@ -123,14 +132,19 @@ export class AuthService {
headers = headers.append('Accept', 'application/json'); headers = headers.append('Accept', 'application/json');
headers = headers.append('Authorization', `Bearer ${token.accessToken}`); headers = headers.append('Authorization', `Bearer ${token.accessToken}`);
options.headers = headers; options.headers = headers;
return this.authRequestService.getRequest('status', options) return this.authRequestService.getRequest('status', options).pipe(
.map((status: AuthStatus) => { switchMap((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
return status.eperson[0];
// TODO this should be cleaned up, AuthStatus could be parsed by the RemoteDataService as a whole...
const person$ = this.rdbService.buildSingle<NormalizedEperson, Eperson>(status.eperson.toString());
// person$.subscribe(() => console.log('test'));
return person$.pipe(map((eperson) => eperson.payload));
} else { } else {
throw(new Error('Not authenticated')); throw(new Error('Not authenticated'));
} }
}); }))
} }
/** /**

View File

@@ -1,7 +1,8 @@
import { AuthError } from './auth-error.model'; import { AuthError } from './auth-error.model';
import { AuthTokenInfo } from './auth-token-info.model'; import { AuthTokenInfo } from './auth-token-info.model';
import { DSpaceObject } from '../../shared/dspace-object.model';
import { Eperson } from '../../eperson/models/eperson.model'; import { Eperson } from '../../eperson/models/eperson.model';
import { RemoteData } from '../../data/remote-data';
import { Observable } from 'rxjs/Observable';
export class AuthStatus { export class AuthStatus {
@@ -13,7 +14,7 @@ export class AuthStatus {
error?: AuthError; error?: AuthError;
eperson: Eperson[]; eperson: Observable<RemoteData<Eperson>>;
token?: AuthTokenInfo; token?: AuthTokenInfo;

View File

@@ -1,12 +1,18 @@
import { AuthStatus } from './auth-status.model'; import { AuthStatus } from './auth-status.model';
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize'; import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
import { mapsTo } from '../../cache/builders/build-decorators'; import { mapsTo, relationship } from '../../cache/builders/build-decorators';
import { NormalizedDSpaceObject } from '../../cache/models/normalized-dspace-object.model'; import { ResourceType } from '../../shared/resource-type';
import { Eperson } from '../../eperson/models/eperson.model'; import { NormalizedObject } from '../../cache/models/normalized-object.model';
import { IDToUUIDSerializer } from '../../cache/id-to-uuid-serializer';
@mapsTo(AuthStatus) @mapsTo(AuthStatus)
@inheritSerialization(NormalizedDSpaceObject) @inheritSerialization(NormalizedObject)
export class NormalizedAuthStatus extends NormalizedDSpaceObject { export class NormalizedAuthStatus extends NormalizedObject {
@autoserialize
id: string;
@autoserializeAs(new IDToUUIDSerializer('auth-status'), 'id')
uuid: string;
/** /**
* True if REST API is up and running, should never return false * True if REST API is up and running, should never return false
@@ -20,7 +26,7 @@ export class NormalizedAuthStatus extends NormalizedDSpaceObject {
@autoserialize @autoserialize
authenticated: boolean; authenticated: boolean;
@autoserializeAs(Eperson) @relationship(ResourceType.Eperson, false)
eperson: Eperson[]; @autoserialize
eperson: string;
} }

View File

@@ -1,3 +1,4 @@
import {first, map} from 'rxjs/operators';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
@@ -32,14 +33,14 @@ export class ServerAuthService extends AuthService {
headers = headers.append('X-Forwarded-For', clientIp); headers = headers.append('X-Forwarded-For', clientIp);
options.headers = headers; options.headers = headers;
return this.authRequestService.getRequest('status', options) return this.authRequestService.getRequest('status', options).pipe(
.map((status: AuthStatus) => { map((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
return status.eperson[0]; return status.eperson[0];
} else { } else {
throw(new Error('Not authenticated')); throw(new Error('Not authenticated'));
} }
}); }));
} }
/** /**
@@ -53,8 +54,8 @@ export class ServerAuthService extends AuthService {
* Redirect to the route navigated before the login * Redirect to the route navigated before the login
*/ */
public redirectToPreviousUrl() { public redirectToPreviousUrl() {
this.getRedirectUrl() this.getRedirectUrl().pipe(
.first() first())
.subscribe((redirectUrl) => { .subscribe((redirectUrl) => {
if (isNotEmpty(redirectUrl)) { if (isNotEmpty(redirectUrl)) {
// override the route reuse strategy // override the route reuse strategy

View File

@@ -8,6 +8,8 @@ import { ResourceType } from '../../shared/resource-type';
import { NormalizedObject } from './normalized-object.model'; import { NormalizedObject } from './normalized-object.model';
import { NormalizedBitstreamFormat } from './normalized-bitstream-format.model'; import { NormalizedBitstreamFormat } from './normalized-bitstream-format.model';
import { NormalizedResourcePolicy } from './normalized-resource-policy.model'; import { NormalizedResourcePolicy } from './normalized-resource-policy.model';
import { NormalizedEperson } from '../../eperson/models/NormalizedEperson.model';
import { NormalizedGroup } from '../../eperson/models/NormalizedGroup.model';
export class NormalizedObjectFactory { export class NormalizedObjectFactory {
public static getConstructor(type: ResourceType): GenericConstructor<NormalizedObject> { public static getConstructor(type: ResourceType): GenericConstructor<NormalizedObject> {
@@ -33,6 +35,12 @@ export class NormalizedObjectFactory {
case ResourceType.ResourcePolicy: { case ResourceType.ResourcePolicy: {
return NormalizedResourcePolicy return NormalizedResourcePolicy
} }
case ResourceType.Eperson: {
return NormalizedEperson
}
case ResourceType.Group: {
return NormalizedGroup
}
default: { default: {
return undefined; return undefined;
} }

View File

@@ -1,3 +1,4 @@
import { filter, take } from 'rxjs/operators';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { hasValue, isNotEmpty } from '../../shared/empty.util';
@@ -60,9 +61,9 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
const hrefObs = this.halService.getEndpoint(this.linkPath).filter((href: string) => isNotEmpty(href)) const hrefObs = this.halService.getEndpoint(this.linkPath).filter((href: string) => isNotEmpty(href))
.flatMap((endpoint: string) => this.getFindAllHref(endpoint, options)); .flatMap((endpoint: string) => this.getFindAllHref(endpoint, options));
hrefObs hrefObs.pipe(
.filter((href: string) => hasValue(href)) filter((href: string) => hasValue(href)),
.take(1) take(1))
.subscribe((href: string) => { .subscribe((href: string) => {
const request = new FindAllRequest(this.requestService.generateRequestId(), href, options); const request = new FindAllRequest(this.requestService.generateRequestId(), href, options);
this.requestService.configure(request); this.requestService.configure(request);

View File

@@ -8,7 +8,7 @@ import { ResourceType } from '../../shared/resource-type';
@mapsTo(Eperson) @mapsTo(Eperson)
@inheritSerialization(NormalizedDSpaceObject) @inheritSerialization(NormalizedDSpaceObject)
export class NormalizedEpersonModel extends NormalizedDSpaceObject implements CacheableObject, ListableObject { export class NormalizedEperson extends NormalizedDSpaceObject implements CacheableObject, ListableObject {
@autoserialize @autoserialize
public handle: string; public handle: string;

View File

@@ -2,13 +2,12 @@ import { autoserialize, inheritSerialization } from 'cerialize';
import { CacheableObject } from '../../cache/object-cache.reducer'; import { CacheableObject } from '../../cache/object-cache.reducer';
import { ListableObject } from '../../../shared/object-collection/shared/listable-object.model'; import { ListableObject } from '../../../shared/object-collection/shared/listable-object.model';
import { NormalizedDSpaceObject } from '../../cache/models/normalized-dspace-object.model'; import { NormalizedDSpaceObject } from '../../cache/models/normalized-dspace-object.model';
import { Eperson } from './eperson.model';
import { mapsTo } from '../../cache/builders/build-decorators'; import { mapsTo } from '../../cache/builders/build-decorators';
import { Group } from './group.model'; import { Group } from './group.model';
@mapsTo(Group) @mapsTo(Group)
@inheritSerialization(NormalizedDSpaceObject) @inheritSerialization(NormalizedDSpaceObject)
export class NormalizedGroupModel extends NormalizedDSpaceObject implements CacheableObject, ListableObject { export class NormalizedGroup extends NormalizedDSpaceObject implements CacheableObject, ListableObject {
@autoserialize @autoserialize
public handle: string; public handle: string;

View File

@@ -10,6 +10,7 @@ import { isNotUndefined } from '../empty.util';
import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors'; import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { Eperson } from '../../core/eperson/models/eperson.model';
import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service'; import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
import { RemoteData } from '../../core/data/remote-data';
@Component({ @Component({
selector: 'ds-auth-nav-menu', selector: 'ds-auth-nav-menu',

View File

@@ -5,6 +5,7 @@ import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { RequestEntry } from '../../core/data/request.reducer'; import { RequestEntry } from '../../core/data/request.reducer';
import { hasValue } from '../empty.util'; import { hasValue } from '../empty.util';
import { NormalizedObject } from '../../core/cache/models/normalized-object.model';
export function getMockRemoteDataBuildService(toRemoteDataObservable$?: Observable<RemoteData<any>>): RemoteDataBuildService { export function getMockRemoteDataBuildService(toRemoteDataObservable$?: Observable<RemoteData<any>>): RemoteDataBuildService {
return { return {
@@ -17,7 +18,8 @@ export function getMockRemoteDataBuildService(toRemoteDataObservable$?: Observab
payload payload
} as RemoteData<any>))) } as RemoteData<any>)))
} }
} },
buildSingle: (href$: string | Observable<string>) => Observable.of(new RemoteData(false, false, true, undefined, {}))
} as RemoteDataBuildService; } as RemoteDataBuildService;
} }

View File

@@ -5,6 +5,7 @@ import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { Eperson } from '../../core/eperson/models/eperson.model';
import { isNotEmpty } from '../empty.util'; import { isNotEmpty } from '../empty.util';
import { EpersonMock } from './eperson-mock'; import { EpersonMock } from './eperson-mock';
import { RemoteData } from '../../core/data/remote-data';
export class AuthRequestServiceStub { export class AuthRequestServiceStub {
protected mockUser: Eperson = EpersonMock; protected mockUser: Eperson = EpersonMock;
@@ -26,7 +27,7 @@ export class AuthRequestServiceStub {
if (this.validateToken(token)) { if (this.validateToken(token)) {
authStatusStub.authenticated = true; authStatusStub.authenticated = true;
authStatusStub.token = this.mockTokenInfo; authStatusStub.token = this.mockTokenInfo;
authStatusStub.eperson = [this.mockUser]; authStatusStub.eperson = Observable.of(new RemoteData<Eperson>(false, false, true, undefined, this.mockUser));
} else { } else {
authStatusStub.authenticated = false; authStatusStub.authenticated = false;
} }
@@ -45,7 +46,7 @@ export class AuthRequestServiceStub {
if (this.validateToken(token)) { if (this.validateToken(token)) {
authStatusStub.authenticated = true; authStatusStub.authenticated = true;
authStatusStub.token = this.mockTokenInfo; authStatusStub.token = this.mockTokenInfo;
authStatusStub.eperson = [this.mockUser]; authStatusStub.eperson = Observable.of(new RemoteData<Eperson>(false, false, true, undefined, this.mockUser));
} else { } else {
authStatusStub.authenticated = false; authStatusStub.authenticated = false;
} }

View File

@@ -3,6 +3,7 @@ import { Observable } from 'rxjs/Observable';
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model'; import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { EpersonMock } from './eperson-mock'; import { EpersonMock } from './eperson-mock';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { Eperson } from '../../core/eperson/models/eperson.model';
import { RemoteData } from '../../core/data/remote-data';
export class AuthServiceStub { export class AuthServiceStub {
@@ -19,7 +20,7 @@ export class AuthServiceStub {
authStatus.okay = true; authStatus.okay = true;
authStatus.authenticated = true; authStatus.authenticated = true;
authStatus.token = this.token; authStatus.token = this.token;
authStatus.eperson = [EpersonMock]; authStatus.eperson = Observable.of(new RemoteData<Eperson>(false, false, true, undefined, EpersonMock));
return Observable.of(authStatus); return Observable.of(authStatus);
} else { } else {
console.log('error'); console.log('error');