Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit dd6f15c

Browse files
committed
gh-455 Fix: Stream fails to deploy with security enabled
- Ensure that we send the respective default headers: * `Content-Type`: `application/json` * `Accept`: `application/json` - Fix tests
1 parent b261309 commit dd6f15c

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

ui/src/app/streams/streams.service.spec.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {StreamsService} from './streams.service';
33
import {Observable} from 'rxjs/Observable';
44
import {HttpUtils} from '../shared/support/http.utils';
55
import {StreamDefinition} from './model/stream-definition';
6-
import {Headers, RequestOptions} from '@angular/http';
6+
import {Headers, RequestOptions, URLSearchParams} from '@angular/http';
77
import {MockResponse} from '../tests/mocks/response';
88
import {STREAM_DEFINITIONS} from '../tests/mocks/mock-data';
99

@@ -28,56 +28,62 @@ describe('StreamsService', () => {
2828
expect(this.streamsService.streamDefinitions).toBeDefined();
2929

3030
const params: URLSearchParams = HttpUtils.getPaginationParams(0, 10);
31-
32-
this.streamsService.getDefinitions();
31+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
32+
requestOptionsArgs.search = params;
33+
this.streamsService.getDefinitions() ;
3334

3435
const defaultPageNumber: number = this.streamsService.streamDefinitions.pageNumber;
3536
const defaultPageSize: number = this.streamsService.streamDefinitions.pageSize;
3637

3738
expect(defaultPageNumber).toBe(0);
3839
expect(defaultPageSize).toBe(10);
39-
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', {search: params});
40+
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', requestOptionsArgs);
4041

4142
this.streamsService.streamDefinitions.filter = 'testFilter';
4243
this.streamsService.getDefinitions();
4344
expect(this.streamsService.streamDefinitions.filter).toBe('testFilter');
44-
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', {search: params});
45+
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', requestOptionsArgs);
4546
});
4647

4748
it('should call the definitions service with the right url [no sort params]', () => {
4849
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
4950

5051
const params: URLSearchParams = HttpUtils.getPaginationParams(0, 10);
51-
52+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
53+
requestOptionsArgs.search = params;
5254
this.streamsService.getDefinitions();
53-
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', { search: params });
55+
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', requestOptionsArgs);
5456
});
5557

5658
it('should call the definitions service with the right url [null sort params]', () => {
5759
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
5860
const params: URLSearchParams = HttpUtils.getPaginationParams(0, 10);
61+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
62+
requestOptionsArgs.search = params;
5963
this.streamsService.getDefinitions(undefined, undefined);
60-
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', { search: params });
64+
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', requestOptionsArgs);
6165
});
6266

6367
it('should call the definitions service with the right url [desc asc sort]', () => {
6468
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
6569
const params: URLSearchParams = HttpUtils.getPaginationParams(0, 10);
66-
const tocheck = params;
67-
tocheck.append('sort', 'DEFINITION,ASC');
68-
tocheck.append('sort', 'DEFINITION_NAME,DESC');
70+
params.append('sort', 'DEFINITION,ASC');
71+
params.append('sort', 'DEFINITION_NAME,DESC');
6972
this.streamsService.getDefinitions(true, false);
70-
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', { search: tocheck });
73+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
74+
requestOptionsArgs.search = params;
75+
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', requestOptionsArgs);
7176
});
7277

7378
it('should call the definitions service with the right url [asc desc sort]', () => {
7479
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
7580
const params: URLSearchParams = HttpUtils.getPaginationParams(0, 10);
76-
const tocheck = params;
77-
tocheck.append('sort', 'DEFINITION,DESC');
78-
tocheck.append('sort', 'DEFINITION_NAME,ASC');
81+
params.append('sort', 'DEFINITION,DESC');
82+
params.append('sort', 'DEFINITION_NAME,ASC');
7983
this.streamsService.getDefinitions(false, true);
80-
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', { search: tocheck });
84+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
85+
requestOptionsArgs.search = params;
86+
expect(this.mockHttp.get).toHaveBeenCalledWith('/streams/definitions', requestOptionsArgs);
8187
});
8288
});
8389

@@ -89,9 +95,8 @@ describe('StreamsService', () => {
8995

9096
const streamDefinition = new StreamDefinition('test', 'time|log', 'undeployed');
9197
this.streamsService.destroyDefinition(streamDefinition);
92-
const headers = new Headers({'Content-Type': 'application/json'});
93-
const options = new RequestOptions({headers: headers});
94-
expect(this.mockHttp.delete).toHaveBeenCalledWith('/streams/definitions/test', options);
98+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
99+
expect(this.mockHttp.delete).toHaveBeenCalledWith('/streams/definitions/test', requestOptionsArgs);
95100
});
96101

97102
describe('undeployDefinition', () => {
@@ -102,9 +107,8 @@ describe('StreamsService', () => {
102107

103108
const streamDefinition = new StreamDefinition('test', 'time|log', 'deployed');
104109
this.streamsService.undeployDefinition(streamDefinition);
105-
const headers = new Headers({'Content-Type': 'application/json'});
106-
const options = new RequestOptions({headers: headers});
107-
expect(this.mockHttp.delete).toHaveBeenCalledWith('/streams/deployments/test', options);
110+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
111+
expect(this.mockHttp.delete).toHaveBeenCalledWith('/streams/deployments/test', requestOptionsArgs);
108112
});
109113
});
110114

@@ -115,9 +119,8 @@ describe('StreamsService', () => {
115119
expect(this.streamsService.streamDefinitions).toBeDefined();
116120

117121
this.streamsService.deployDefinition('test', {});
118-
const headers = new Headers({'Content-Type': 'application/json'});
119-
const options = new RequestOptions({headers: headers});
120-
expect(this.mockHttp.post).toHaveBeenCalledWith('/streams/deployments/test', {}, options);
122+
const requestOptionsArgs = HttpUtils.getDefaultRequestOptions();
123+
expect(this.mockHttp.post).toHaveBeenCalledWith('/streams/deployments/test', {}, requestOptionsArgs);
121124
});
122125
});
123126

ui/src/app/streams/streams.service.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ export class StreamsService {
7070
if (this.streamDefinitions.filter && this.streamDefinitions.filter.length > 0) {
7171
params.append('search', this.streamDefinitions.filter);
7272
}
73-
return this.http.get(this.streamDefinitionsUrl, {search: params})
73+
74+
const options = HttpUtils.getDefaultRequestOptions();
75+
options.params = params;
76+
return this.http.get(this.streamDefinitionsUrl, options)
7477
.map(this.extractData.bind(this))
7578
.catch(this.errorHandler.handleError);
7679
}
7780

7881
getDefinition(name: string): Observable<StreamDefinition> {
79-
return this.http.get(`${this.streamDefinitionsUrl}/${name}`)
82+
const options = HttpUtils.getDefaultRequestOptions();
83+
return this.http.get(`${this.streamDefinitionsUrl}/${name}`, options)
8084
.map(res => {
8185
const json = res.json();
8286
return new StreamDefinition(json.name, json.dslText, json.status);
@@ -85,13 +89,15 @@ export class StreamsService {
8589
}
8690

8791
createDefinition(name: string, dsl: string, deploy?: boolean): Observable<Response> {
92+
const options = HttpUtils.getDefaultRequestOptions();
8893
const params = new URLSearchParams('', URL_QUERY_ENCODER);
8994
params.append('name', name);
9095
params.append('definition', dsl);
9196
if (deploy) {
9297
params.set('deploy', deploy.toString());
9398
}
94-
return this.http.post(this.streamDefinitionsUrl, null, {params: params});
99+
options.search = params;
100+
return this.http.post(this.streamDefinitionsUrl, null, options);
95101
}
96102

97103
/**
@@ -101,8 +107,7 @@ export class StreamsService {
101107
*/
102108
destroyDefinition(streamDefinition: StreamDefinition): Observable<Response> {
103109
console.log('Destroying...', streamDefinition);
104-
const headers = new Headers({'Content-Type': 'application/json'});
105-
const options = new RequestOptions({headers: headers});
110+
const options = HttpUtils.getDefaultRequestOptions();
106111
return this.http.delete('/streams/definitions/' + streamDefinition.name, options)
107112
.map(data => {
108113
this.streamDefinitions.items = this.streamDefinitions.items.filter(item => item.name !== streamDefinition.name);
@@ -117,8 +122,7 @@ export class StreamsService {
117122
*/
118123
undeployDefinition(streamDefinition: StreamDefinition): Observable<Response> {
119124
console.log('Undeploying...', streamDefinition);
120-
const headers = new Headers({'Content-Type': 'application/json'});
121-
const options = new RequestOptions({headers: headers});
125+
const options = HttpUtils.getDefaultRequestOptions();
122126
return this.http.delete('/streams/deployments/' + streamDefinition.name, options)
123127
.catch(this.errorHandler.handleError);
124128
}
@@ -131,8 +135,7 @@ export class StreamsService {
131135
*/
132136
deployDefinition(streamDefinitionName: String, propertiesAsMap: any): Observable<Response> {
133137
console.log('Deploying...', streamDefinitionName);
134-
const headers = new Headers({'Content-Type': 'application/json'});
135-
const options = new RequestOptions({headers: headers});
138+
const options = HttpUtils.getDefaultRequestOptions();
136139
return this.http.post('/streams/deployments/' + streamDefinitionName, propertiesAsMap, options)
137140
.catch(this.errorHandler.handleError);
138141
}

0 commit comments

Comments
 (0)