Skip to content

Commit 1bd3385

Browse files
authored
[ES 9.0] Remove body workaround (@elastic/kibana-security) (#217222)
## Summary Follow up to #213375: The latest version of the ES client fixed the issue elastic/elasticsearch-js#2584. We should be able to remove all usages of `// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584`. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 0d84936 commit 1bd3385

File tree

4 files changed

+45
-55
lines changed

4 files changed

+45
-55
lines changed

x-pack/platform/plugins/shared/security/server/authentication/api_keys/api_keys.test.ts

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,14 @@ describe('API Keys', () => {
483483
});
484484
expect(mockValidateKibanaPrivileges).not.toHaveBeenCalled(); // this is only called if kibana_role_descriptors is defined
485485
expect(mockClusterClient.asInternalUser.security.grantApiKey).toHaveBeenCalledWith({
486-
body: {
487-
api_key: {
488-
name: 'test_api_key',
489-
role_descriptors: { foo: true },
490-
expiration: '1d',
491-
},
492-
grant_type: 'password',
493-
username: 'foo',
494-
password: 'bar',
486+
api_key: {
487+
name: 'test_api_key',
488+
role_descriptors: { foo: true },
489+
expiration: '1d',
495490
},
491+
grant_type: 'password',
492+
username: 'foo',
493+
password: 'bar',
496494
});
497495
});
498496

@@ -522,15 +520,13 @@ describe('API Keys', () => {
522520
});
523521
expect(mockValidateKibanaPrivileges).not.toHaveBeenCalled(); // this is only called if kibana_role_descriptors is defined
524522
expect(mockClusterClient.asInternalUser.security.grantApiKey).toHaveBeenCalledWith({
525-
body: {
526-
api_key: {
527-
name: 'test_api_key',
528-
role_descriptors: roleDescriptors,
529-
expiration: '1d',
530-
},
531-
grant_type: 'access_token',
532-
access_token: 'foo-access-token',
523+
api_key: {
524+
name: 'test_api_key',
525+
role_descriptors: roleDescriptors,
526+
expiration: '1d',
533527
},
528+
grant_type: 'access_token',
529+
access_token: 'foo-access-token',
534530
});
535531
});
536532

@@ -563,18 +559,16 @@ describe('API Keys', () => {
563559
});
564560
expect(mockValidateKibanaPrivileges).not.toHaveBeenCalled(); // this is only called if kibana_role_descriptors is defined
565561
expect(mockClusterClient.asInternalUser.security.grantApiKey).toHaveBeenCalledWith({
566-
body: {
567-
api_key: {
568-
name: 'test_api_key',
569-
role_descriptors: { foo: true },
570-
expiration: '1d',
571-
},
572-
grant_type: 'access_token',
573-
access_token: 'foo-access-token',
574-
client_authentication: {
575-
scheme: 'SharedSecret',
576-
value: 'secret',
577-
},
562+
api_key: {
563+
name: 'test_api_key',
564+
role_descriptors: { foo: true },
565+
expiration: '1d',
566+
},
567+
grant_type: 'access_token',
568+
access_token: 'foo-access-token',
569+
client_authentication: {
570+
scheme: 'SharedSecret',
571+
value: 'secret',
578572
},
579573
});
580574
});
@@ -857,29 +851,27 @@ describe('API Keys', () => {
857851
name: 'key-name',
858852
});
859853
expect(mockClusterClient.asInternalUser.security.grantApiKey).toHaveBeenCalledWith({
860-
body: {
861-
api_key: {
862-
name: 'key-name',
863-
role_descriptors: {
864-
synthetics_writer: {
865-
applications: [
866-
{
867-
application: 'kibana-.kibana',
868-
privileges: ['feature_uptime.all'],
869-
resources: ['*'],
870-
},
871-
],
872-
cluster: ['manage'],
873-
indices: [],
874-
run_as: [],
875-
},
854+
api_key: {
855+
name: 'key-name',
856+
role_descriptors: {
857+
synthetics_writer: {
858+
applications: [
859+
{
860+
application: 'kibana-.kibana',
861+
privileges: ['feature_uptime.all'],
862+
resources: ['*'],
863+
},
864+
],
865+
cluster: ['manage'],
866+
indices: [],
867+
run_as: [],
876868
},
877-
expiration: '1d',
878869
},
879-
grant_type: 'password',
880-
password: 'bar',
881-
username: 'foo',
870+
expiration: '1d',
882871
},
872+
grant_type: 'password',
873+
password: 'bar',
874+
username: 'foo',
883875
});
884876
});
885877

x-pack/platform/plugins/shared/security/server/authentication/api_keys/api_keys.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ export class APIKeys implements APIKeysType {
290290
// User needs `manage_api_key` or `grant_api_key` privilege to use this API
291291
let result: GrantAPIKeyResult;
292292
try {
293-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584 (client_authentication)
294-
result = await this.clusterClient.asInternalUser.security.grantApiKey({ body: params });
293+
result = await this.clusterClient.asInternalUser.security.grantApiKey(params);
295294
this.logger.debug('API key was granted successfully');
296295
} catch (e) {
297296
this.logger.error(`Failed to grant API key: ${e.message}`);

x-pack/platform/plugins/shared/security/server/session_management/session_index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe('Session index', () => {
340340
expect(mockElasticsearchClient.indices.putMapping).toHaveBeenCalledTimes(1);
341341
expect(mockElasticsearchClient.indices.putMapping).toHaveBeenCalledWith({
342342
index: aliasName,
343-
body: getSessionIndexSettings({ indexName, aliasName }).mappings,
343+
...getSessionIndexSettings({ indexName, aliasName }).mappings,
344344
});
345345
});
346346

@@ -367,7 +367,7 @@ describe('Session index', () => {
367367
expect(mockElasticsearchClient.indices.putMapping).toHaveBeenCalledTimes(1);
368368
expect(mockElasticsearchClient.indices.putMapping).toHaveBeenCalledWith({
369369
index: aliasName,
370-
body: getSessionIndexSettings({ indexName, aliasName }).mappings,
370+
...getSessionIndexSettings({ indexName, aliasName }).mappings,
371371
});
372372
});
373373

x-pack/platform/plugins/shared/security/server/session_management/session_index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,7 @@ export class SessionIndex {
761761
try {
762762
await this.options.elasticsearchClient.indices.putMapping({
763763
index: this.aliasName,
764-
// @ts-expect-error [email protected] https://github.com/elastic/elasticsearch-js/issues/2584
765-
body: sessionIndexSettings.mappings,
764+
...sessionIndexSettings.mappings,
766765
});
767766
this.options.logger.debug('Successfully updated session index mappings.');
768767
} catch (err) {

0 commit comments

Comments
 (0)