Skip to content

Conversation

@rylnd
Copy link
Contributor

@rylnd rylnd commented Nov 14, 2025

Backport

This will backport the following commits from main to 9.2:

Questions ?

Please refer to the Backport tool documentation

…ther users (elastic#241909)

## Summary

We provide FTR services for our APIs, generated from our OpenAPI
schemae. However, the existing services are hardcoded to the default
`supertest` instance returned by `getService('supertest')`, which means
we cannot change the authentication of those APIs with what is currently
exposed.

This PR modifies the template defining those services slightly, to both
a) preserve existing APIs, and b) add a new method that will return
another instance of the API methods, allowing the following:

```ts
const detectionsApi = getService('detectionsApi');

const restrictedUser = { username: 'username', password: 'restricted' };
const restrictedApis = detectionsApi.withUser(restrictedUser);

// ...

// in test for standard user:
const apiResponse = detectionsApi.performRulesBulkAction(...);

// in test for restricted user:
const apiResponse = restrictedApis.performRulesBulkAction(...);

// or, if you want to chain it:
const apiResponse = detectionsApi.withUser(restrictedUser).performRulesBulkAction(...);
```

## How to Review
Since this is an extension of existing test tooling, the fact of this PR
being green on CI is validation that we're not breaking these tools with
this PR. Evidence of the new functionality can be seen [on this
branch](https://github.com/rylnd/kibana/pull/11/files#diff-8a7e0219eb7a142d9c996a45d4d062d8e7d5054f7037a99b0974a79e9698d474R57-R58),
where we are rescoping the API clients to act as one of two different
users.

The changes themselves (to
`src/platform/packages/shared/kbn-openapi-generator/src/template_service/templates/api_client_supertest.handlebars`;
the rest of the changes are downstream codegen change) are relatively
straightforward, just a few lines of code.

### TODO
- [ ] update all relevant generated code (I've only run `yarn
openapi:generate` within `security_solution`)
- [x] better interface: allow passing of a `User` instead of a supertest
instance

### Checklist

Check the PR satisfies following conditions.

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [ ] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit a713526)

# Conflicts:
#	x-pack/solutions/security/packages/test-api-clients/supertest/endpoint_management.gen.ts
#	x-pack/solutions/security/packages/test-api-clients/supertest/entity_analytics.gen.ts
@rylnd rylnd requested a review from kibanamachine as a code owner November 14, 2025 22:53
@rylnd rylnd added the backport This PR is a backport of another PR label Nov 14, 2025
@rylnd rylnd enabled auto-merge (squash) November 14, 2025 22:54
@rylnd rylnd merged commit d8ebb4b into elastic:9.2 Nov 16, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants