-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set sourceFiles to empty array on workflowVersions endpoint (#780)
* Set sourceFiles to empty array on workflowVersions endpoint dockstore/dockstore#2833 dockstore/dockstore#2836
- Loading branch information
Showing
3 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/app/interceptors/workflow-versions.interceptor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { WorkflowVersionsInterceptor } from './workflow-versions.interceptor'; | ||
import { inject, TestBed } from '@angular/core/testing'; | ||
import { HttpEvent, HttpHandler, HttpRequest } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
|
||
class SourcefilesEmptyChecker extends HttpHandler { | ||
handle(req: HttpRequest<any>): Observable<HttpEvent<any>> { | ||
expect(req.body[0].sourceFiles).toEqual([]); | ||
return undefined; | ||
} | ||
} | ||
|
||
class RequestUnchangedChecker extends HttpHandler { | ||
constructor(private origRequest: HttpRequest<any>) { | ||
super(); | ||
} | ||
|
||
handle(req: HttpRequest<any>): Observable<HttpEvent<any>> { | ||
expect(req).toBe(this.origRequest); | ||
return undefined; | ||
} | ||
} | ||
|
||
describe('WorkflowVersionsInterceptor', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [WorkflowVersionsInterceptor] | ||
}); | ||
}); | ||
|
||
it('Should tranform put', inject([WorkflowVersionsInterceptor], (interceptor: WorkflowVersionsInterceptor) => { | ||
const httpRequest = new HttpRequest('PUT', 'https://dockstore.org/api/workflows/1234/workflowVersions', [ | ||
{ sourceFiles: [{ one: 'something' }] } | ||
]); | ||
const httpHandler = new SourcefilesEmptyChecker(); | ||
interceptor.intercept(httpRequest, httpHandler); | ||
})); | ||
|
||
it('Should leave other stuff alone', inject([WorkflowVersionsInterceptor], (interceptor: WorkflowVersionsInterceptor) => { | ||
const body = [{ sourceFiles: [{ one: 'something' }] }]; | ||
const httpRequest1 = new HttpRequest('GET', 'https://dockstore.org/api/workflows/1234/workflowVersions', body); | ||
const httpHandler = new RequestUnchangedChecker(httpRequest1); | ||
interceptor.intercept(httpRequest1, httpHandler); | ||
|
||
const httpRequest2 = new HttpRequest('PUT', 'https://dockstore.org/api/tools/1234/workflowVersions', body); | ||
const httpHandler2 = new RequestUnchangedChecker(httpRequest2); | ||
interceptor.intercept(httpRequest2, httpHandler2); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2019 OICR | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
|
||
const workflowVersionsEndpoint = /workflows\/\d+\/workflowVersions$/; | ||
|
||
/** | ||
* An interceptor that ensures that PUT requests on the workflowVersions | ||
* endpoint have the sourceFiles property set to an empty array. | ||
* | ||
* The sourceFiles property is ignored by the web service endpoint, but can be | ||
* sizeable. This affects performance and more importantly, can run into a max | ||
* request limit size that we have on our nginx server. | ||
* | ||
* See https://github.com/dockstore/dockstore/issues/2833 | ||
*/ | ||
@Injectable() | ||
export class WorkflowVersionsInterceptor implements HttpInterceptor { | ||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | ||
// In my tests, the body was an array of length 1. I assume it is an array to handle | ||
// multipart form requests. To be safe, just handling arrays of size 1. | ||
if (req.method === 'PUT' && workflowVersionsEndpoint.test(req.url) && req.body && req.body.length === 1) { | ||
const emptySourceFiles = { sourceFiles: [] }; | ||
const newBody = [{ ...req.body[0], ...emptySourceFiles }]; | ||
return next.handle(req.clone({ body: newBody })); | ||
} | ||
return next.handle(req); | ||
} | ||
} |