Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Apr 24, 2020
1 parent f562a32 commit 521a46c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 deletions.
4 changes: 0 additions & 4 deletions x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
SavedObjectsServiceStart,
ElasticsearchServiceStart,
IClusterClient,
ClusterClient,
} from '../../../../src/core/server';

import {
Expand Down Expand Up @@ -300,9 +299,6 @@ export class ActionsPlugin implements Plugin<Promise<PluginSetupContract>, Plugi
callCluster: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
savedObjectsClient: savedObjects.getScopedClient(request),
getScopedCallCluster(clusterClient: IClusterClient) {
if (!(clusterClient instanceof ClusterClient)) {
throw new Error('given clusterClient is not an instance of ClusterClient');
}
return clusterClient.asScoped(request).callAsCurrentUser;
},
});
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/alerting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
SharedGlobalConfig,
ElasticsearchServiceStart,
IClusterClient,
ClusterClient,
} from '../../../../src/core/server';

import {
Expand Down Expand Up @@ -273,9 +272,6 @@ export class AlertingPlugin {
callCluster: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
savedObjectsClient: savedObjects.getScopedClient(request),
getScopedCallCluster(clusterClient: IClusterClient) {
if (!(clusterClient instanceof ClusterClient)) {
throw new Error('given clusterClient is not an instance of ClusterClient');
}
return clusterClient.asScoped(request).callAsCurrentUser;
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function(kibana: any) {
require: ['xpack_main', 'actions', 'alerting', 'elasticsearch'],
name: 'alerts',
init(server: any) {
const clusterClient = server.newPlatform.start.core.elasticsearch.legacy.client;
server.plugins.xpack_main.registerFeature({
id: 'alerting',
name: 'Alerting',
Expand Down Expand Up @@ -165,6 +166,22 @@ export default function(kibana: any) {
} catch (e) {
callClusterError = e;
}
// Call scoped cluster
const callScopedCluster = services.getScopedCallCluster(clusterClient);
let callScopedClusterSuccess = false;
let callScopedClusterError;
try {
await callScopedCluster('index', {
index: params.callClusterAuthorizationIndex,
refresh: 'wait_for',
body: {
param1: 'test',
},
});
callScopedClusterSuccess = true;
} catch (e) {
callScopedClusterError = e;
}
// Saved objects client
let savedObjectsClientSuccess = false;
let savedObjectsClientError;
Expand All @@ -185,6 +202,8 @@ export default function(kibana: any) {
state: {
callClusterSuccess,
callClusterError,
callScopedClusterSuccess,
callScopedClusterError,
savedObjectsClientSuccess,
savedObjectsClientError,
},
Expand Down Expand Up @@ -376,6 +395,22 @@ export default function(kibana: any) {
} catch (e) {
callClusterError = e;
}
// Call scoped cluster
const callScopedCluster = services.getScopedCallCluster(clusterClient);
let callScopedClusterSuccess = false;
let callScopedClusterError;
try {
await callScopedCluster('index', {
index: params.callClusterAuthorizationIndex,
refresh: 'wait_for',
body: {
param1: 'test',
},
});
callScopedClusterSuccess = true;
} catch (e) {
callScopedClusterError = e;
}
// Saved objects client
let savedObjectsClientSuccess = false;
let savedObjectsClientError;
Expand All @@ -396,6 +431,8 @@ export default function(kibana: any) {
state: {
callClusterSuccess,
callClusterError,
callScopedClusterSuccess,
callScopedClusterError,
savedObjectsClientSuccess,
savedObjectsClientError,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,16 @@ export default function({ getService }: FtrProviderContext) {
indexedRecord = searchResult.hits.hits[0];
expect(indexedRecord._source.state).to.eql({
callClusterSuccess: false,
callScopedClusterSuccess: false,
savedObjectsClientSuccess: false,
callClusterError: {
...indexedRecord._source.state.callClusterError,
statusCode: 403,
},
callScopedClusterError: {
...indexedRecord._source.state.callScopedClusterError,
statusCode: 403,
},
savedObjectsClientError: {
...indexedRecord._source.state.savedObjectsClientError,
output: {
Expand All @@ -457,6 +462,7 @@ export default function({ getService }: FtrProviderContext) {
indexedRecord = searchResult.hits.hits[0];
expect(indexedRecord._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...indexedRecord._source.state.savedObjectsClientError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,16 @@ instanceStateValue: true
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
callClusterSuccess: false,
callScopedClusterSuccess: false,
savedObjectsClientSuccess: false,
callClusterError: {
...searchResult.hits.hits[0]._source.state.callClusterError,
statusCode: 403,
},
callScopedClusterError: {
...searchResult.hits.hits[0]._source.state.callScopedClusterError,
statusCode: 403,
},
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
output: {
Expand All @@ -497,6 +502,7 @@ instanceStateValue: true
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
Expand Down Expand Up @@ -577,11 +583,16 @@ instanceStateValue: true
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
callClusterSuccess: false,
callScopedClusterSuccess: false,
savedObjectsClientSuccess: false,
callClusterError: {
...searchResult.hits.hits[0]._source.state.callClusterError,
statusCode: 403,
},
callScopedClusterError: {
...searchResult.hits.hits[0]._source.state.callScopedClusterError,
statusCode: 403,
},
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
output: {
Expand All @@ -605,6 +616,7 @@ instanceStateValue: true
expect(searchResult.hits.total.value).to.eql(1);
expect(searchResult.hits.hits[0]._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...searchResult.hits.hits[0]._source.state.savedObjectsClientError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default function({ getService }: FtrProviderContext) {
const indexedRecord = searchResult.hits.hits[0];
expect(indexedRecord._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...indexedRecord._source.state.savedObjectsClientError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ instanceStateValue: true
)[0];
expect(alertTestRecord._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...alertTestRecord._source.state.savedObjectsClientError,
Expand Down Expand Up @@ -332,6 +333,7 @@ instanceStateValue: true
)[0];
expect(actionTestRecord._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
savedObjectsClientSuccess: false,
savedObjectsClientError: {
...actionTestRecord._source.state.savedObjectsClientError,
Expand Down

0 comments on commit 521a46c

Please sign in to comment.