mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Fix lint and test issues
This commit is contained in:
@@ -11,6 +11,7 @@ import { HttpOptions } from '../dspace-rest/dspace-rest.service';
|
|||||||
import objectContaining = jasmine.objectContaining;
|
import objectContaining = jasmine.objectContaining;
|
||||||
import { AuthStatus } from './models/auth-status.model';
|
import { AuthStatus } from './models/auth-status.model';
|
||||||
import { RestRequestMethod } from '../data/rest-request-method';
|
import { RestRequestMethod } from '../data/rest-request-method';
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
|
||||||
describe(`AuthRequestService`, () => {
|
describe(`AuthRequestService`, () => {
|
||||||
let halService: HALEndpointService;
|
let halService: HALEndpointService;
|
||||||
@@ -34,8 +35,8 @@ describe(`AuthRequestService`, () => {
|
|||||||
super(hes, rs, rdbs);
|
super(hes, rs, rdbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected createShortLivedTokenRequest(href: string): PostRequest {
|
protected createShortLivedTokenRequest(href: string): Observable<PostRequest> {
|
||||||
return new PostRequest(this.requestService.generateRequestId(), href);
|
return observableOf(new PostRequest(this.requestService.generateRequestId(), href));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import { AuthRequestService } from './auth-request.service';
|
import { AuthRequestService } from './auth-request.service';
|
||||||
import { RequestService } from '../data/request.service';
|
import { RequestService } from '../data/request.service';
|
||||||
import { BrowserAuthRequestService } from './browser-auth-request.service';
|
import { BrowserAuthRequestService } from './browser-auth-request.service';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { PostRequest } from '../data/request.models';
|
||||||
|
|
||||||
describe(`BrowserAuthRequestService`, () => {
|
describe(`BrowserAuthRequestService`, () => {
|
||||||
let href: string;
|
let href: string;
|
||||||
@@ -17,13 +19,17 @@ describe(`BrowserAuthRequestService`, () => {
|
|||||||
|
|
||||||
describe(`createShortLivedTokenRequest`, () => {
|
describe(`createShortLivedTokenRequest`, () => {
|
||||||
it(`should return a PostRequest`, () => {
|
it(`should return a PostRequest`, () => {
|
||||||
const result = (service as any).createShortLivedTokenRequest(href);
|
const obs = (service as any).createShortLivedTokenRequest(href) as Observable<PostRequest>;
|
||||||
expect(result.constructor.name).toBe('PostRequest');
|
obs.subscribe((result: PostRequest) => {
|
||||||
|
expect(result.constructor.name).toBe('PostRequest');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a request with the given href`, () => {
|
it(`should return a request with the given href`, () => {
|
||||||
const result = (service as any).createShortLivedTokenRequest(href);
|
const obs = (service as any).createShortLivedTokenRequest(href) as Observable<PostRequest>;
|
||||||
expect(result.href).toBe(href) ;
|
obs.subscribe((result: PostRequest) => {
|
||||||
|
expect(result.href).toBe(href);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,44 +1,60 @@
|
|||||||
import { AuthRequestService } from './auth-request.service';
|
import { AuthRequestService } from './auth-request.service';
|
||||||
import { RequestService } from '../data/request.service';
|
import { RequestService } from '../data/request.service';
|
||||||
import { ServerAuthRequestService } from './server-auth-request.service';
|
import { ServerAuthRequestService } from './server-auth-request.service';
|
||||||
import { HttpXsrfTokenExtractorMock } from '../../shared/mocks/http-xsrf-token-extractor.mock';
|
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
import { XSRF_RESPONSE_HEADER } from '../xsrf/xsrf.interceptor';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { PostRequest } from '../data/request.models';
|
||||||
|
|
||||||
describe(`ServerAuthRequestService`, () => {
|
describe(`ServerAuthRequestService`, () => {
|
||||||
let href: string;
|
let href: string;
|
||||||
let requestService: RequestService;
|
let requestService: RequestService;
|
||||||
let service: AuthRequestService;
|
let service: AuthRequestService;
|
||||||
let xsrfExtractor: HttpXsrfTokenExtractorMock;
|
let httpClient: HttpClient;
|
||||||
|
let httpResponse: HttpResponse<any>;
|
||||||
const mockToken = 'mockToken';
|
let halService: HALEndpointService;
|
||||||
|
const mockToken = 'mock-token';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
href = 'https://rest.api/auth/shortlivedtokens';
|
href = 'https://rest.api/auth/shortlivedtokens';
|
||||||
requestService = jasmine.createSpyObj('requestService', {
|
requestService = jasmine.createSpyObj('requestService', {
|
||||||
'generateRequestId': '8bb0582d-5013-4337-af9c-763beb25aae2'
|
'generateRequestId': '8bb0582d-5013-4337-af9c-763beb25aae2'
|
||||||
});
|
});
|
||||||
xsrfExtractor = new HttpXsrfTokenExtractorMock(mockToken);
|
httpResponse = {
|
||||||
service = new ServerAuthRequestService(null, requestService, null, xsrfExtractor);
|
body: { bar: false },
|
||||||
|
headers: new HttpHeaders({ XSRF_RESPONSE_HEADER: mockToken }),
|
||||||
|
statusText: '200'
|
||||||
|
} as HttpResponse<any>;
|
||||||
|
httpClient = jasmine.createSpyObj('httpClient', {
|
||||||
|
get: observableOf(httpResponse),
|
||||||
|
});
|
||||||
|
halService = jasmine.createSpyObj('halService', {
|
||||||
|
'getRootHref': '/api'
|
||||||
|
});
|
||||||
|
service = new ServerAuthRequestService(halService, requestService, null, httpClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(`createShortLivedTokenRequest`, () => {
|
describe(`createShortLivedTokenRequest`, () => {
|
||||||
it(`should return a PostRequest`, () => {
|
it(`should return a PostRequest`, () => {
|
||||||
const result = (service as any).createShortLivedTokenRequest(href);
|
const obs = (service as any).createShortLivedTokenRequest(href) as Observable<PostRequest>;
|
||||||
expect(result.constructor.name).toBe('PostRequest');
|
obs.subscribe((result: PostRequest) => {
|
||||||
|
expect(result.constructor.name).toBe('PostRequest');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a request with the given href`, () => {
|
it(`should return a request with the given href`, () => {
|
||||||
const result = (service as any).createShortLivedTokenRequest(href);
|
const obs = (service as any).createShortLivedTokenRequest(href) as Observable<PostRequest>;
|
||||||
expect(result.href).toBe(href) ;
|
obs.subscribe((result: PostRequest) => {
|
||||||
|
expect(result.href).toBe(href) ;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return a request with a xsrf header`, () => {
|
it(`should return a request with a xsrf header`, () => {
|
||||||
const result = (service as any).createShortLivedTokenRequest(href);
|
const obs = (service as any).createShortLivedTokenRequest(href) as Observable<PostRequest>;
|
||||||
expect(result.options.headers.get('X-XSRF-TOKEN')).toBe(mockToken);
|
obs.subscribe((result: PostRequest) => {
|
||||||
});
|
expect(result.options.headers.get(XSRF_RESPONSE_HEADER)).toBe(mockToken);
|
||||||
|
});
|
||||||
it(`should have a responseMsToLive of 2 seconds`, () => {
|
|
||||||
const result = (service as any).createShortLivedTokenRequest(href);
|
|
||||||
expect(result.responseMsToLive).toBe(2 * 1000) ;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -6,7 +6,6 @@ import { RequestService } from '../data/request.service';
|
|||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
import {
|
import {
|
||||||
HttpHeaders,
|
HttpHeaders,
|
||||||
HttpXsrfTokenExtractor,
|
|
||||||
HttpClient,
|
HttpClient,
|
||||||
HttpResponse
|
HttpResponse
|
||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
@@ -53,15 +52,16 @@ export class ServerAuthRequestService extends AuthRequestService {
|
|||||||
.set('Cookie', `${DSPACE_XSRF_COOKIE}=${xsrfToken}`)),
|
.set('Cookie', `${DSPACE_XSRF_COOKIE}=${xsrfToken}`)),
|
||||||
map((headers: HttpHeaders) =>
|
map((headers: HttpHeaders) =>
|
||||||
// Create a new PostRequest using those headers and the given href
|
// Create a new PostRequest using those headers and the given href
|
||||||
new PostRequest(
|
Object.assign(new PostRequest(
|
||||||
this.requestService.generateRequestId(),
|
this.requestService.generateRequestId(),
|
||||||
href,
|
href,
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
headers: headers,
|
headers: headers,
|
||||||
}
|
},
|
||||||
))
|
),{})
|
||||||
)
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
import { XhrFactory } from '@angular/common';
|
import { XhrFactory } from '@angular/common';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import * as xhr2 from 'xhr2';
|
import { prototype, XMLHttpRequest } from 'xhr2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides the default XhrFactoru server side, to allow us to set cookies in requests to the
|
* Overrides the default XhrFactory server side, to allow us to set cookies in requests to the
|
||||||
* backend. This was added to be able to perform a working XSRF request from the node server, as it
|
* backend. This was added to be able to perform a working XSRF request from the node server, as it
|
||||||
* needs to set a cookie for the XSRF token
|
* needs to set a cookie for the XSRF token
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServerXhrService implements XhrFactory {
|
export class ServerXhrService implements XhrFactory {
|
||||||
build(): XMLHttpRequest {
|
build(): XMLHttpRequest {
|
||||||
xhr2.prototype._restrictedHeaders.cookie = false;
|
prototype._restrictedHeaders.cookie = false;
|
||||||
return new xhr2.XMLHttpRequest();
|
return new XMLHttpRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user