Skip to content

Commit

Permalink
setup testing for proxy itself
Browse files Browse the repository at this point in the history
  • Loading branch information
toddself committed Jun 13, 2019
1 parent 90aeff3 commit db7a87b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 4 deletions.
77 changes: 77 additions & 0 deletions x-pack/plugins/proxy/server/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Observable, BehaviorSubject } from 'rxjs';
import { noop } from 'lodash';

import {
Config,
ConfigService,
Env,
ObjectToConfigAdapter,
} from '../../../../src/core/server/config';
import { mockHttpServer } from '../../../../src/core/server/http/http_service.test.mocks';
import { loggingServiceMock } from '../../../../src/core/server/logging/logging_service.mock';
import { getEnvOptions } from '../../../../src/core/server/config/__mocks__/env';
import { ProxyConfig, ProxyPluginType } from './proxy';

const logger = loggingServiceMock.create();
const env = Env.createDefault(getEnvOptions());

const createConfigService = (value: Partial<ProxyPluginType> = {}) => {
const conf = Object.assign(
{
updateInterval: 0,
timeoutThreshold: 0,
port: 0,
maxRetry: 0,
requestBackoff: 0,
cert: '',
key: '',
ca: '',
},
value
);
const cs = new ConfigService(
new BehaviorSubject<Config>(
new ObjectToConfigAdapter({
xpack: {
proxy: conf,
},
})
),
env,
logger
);
cs.setSchema('xpack.proxy', ProxyConfig.schema);
return cs;
};

function configService(value: Partial<ProxyPluginType>) {
return {
create: <ProxyPluginType>() =>
createConfigService(value).atPath('xpack.proxy') as Observable<ProxyPluginType>,
createIfExists: <ProxyPluginType>() =>
createConfigService(value).atPath('xpack.proxy') as Observable<ProxyPluginType>,
};
}

beforeEach(() => {
jest.useFakeTimers();
});

afterEach(() => {
jest.clearAllMocks();
});

test('creates and sets up proxy server', async () => {
const httpServer = {
isListening: () => false,
setup: jest.fn(),
start: jest.fn(),
stop: noop,
};
mockHttpServer.mockImplementation(() => httpServer);
});
18 changes: 14 additions & 4 deletions x-pack/plugins/proxy/server/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export interface ProxyServiceSetup {
type ProxyRequest = (req: KibanaRequest) => Promise<any>;

export interface ProxyServiceStart {
assignResource: (resource: string, data: RoutingNode) => Promise<void>;
assignResource: (
resource: string,
type: string,
state: RouteState,
node?: string
) => Promise<void>;
unassignResource: (resource: string) => Promise<void>;
proxyResource: (resource: string) => ProxyRequest;
proxyRequest: ProxyRequest;
Expand Down Expand Up @@ -144,7 +149,7 @@ export class ProxyService implements Plugin<ProxyServiceSetup, ProxyServiceStart
cipherSuites: config.cipherSuites,
keyPassphrase: undefined,
supportedProtocols: config.supportedProtocols,
requireCert: true,
requestCert: true,
});
return ssl;
}
Expand Down Expand Up @@ -177,8 +182,13 @@ export class ProxyService implements Plugin<ProxyServiceSetup, ProxyServiceStart
this.configSubscription = undefined;
}

public async assignResource(resource: string, data: RoutingNode): Promise<void> {
await this.clusterDocClient.assignResource(resource, data);
public async assignResource(
resource: string,
type: string,
state: RouteState,
node?: string
): Promise<void> {
await this.clusterDocClient.assignResource(resource, type, state, node);
}

public async unassignResource(resource: string) {
Expand Down

0 comments on commit db7a87b

Please sign in to comment.