Run serverless jest integration with security enabled (#190414)

This commit is contained in:
Jean-Louis Leysens 2024-08-14 16:50:30 +02:00 committed by GitHub
parent 5ce361170c
commit 211170c3f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 4 deletions

View file

@ -14,6 +14,8 @@ import { REPO_ROOT } from '@kbn/repo-info';
import { ToolingLog } from '@kbn/tooling-log';
import { esTestConfig } from '@kbn/test';
import { CliArgs } from '@kbn/config';
import { kibanaDevServiceAccount } from '@kbn/dev-utils';
import { systemIndicesSuperuser } from '@kbn/test';
import { createRoot, type TestElasticsearchUtils, type TestKibanaUtils } from './create_root';
export type TestServerlessESUtils = Pick<TestElasticsearchUtils, 'stop' | 'es'> & {
@ -27,7 +29,6 @@ export interface TestServerlessUtils {
}
const ES_BASE_PATH_DIR = Path.join(REPO_ROOT, '.es/es_test_serverless');
const projectType: ServerlessProjectType = 'es';
/**
@ -97,8 +98,6 @@ function createServerlessES() {
kill: true,
waitForReady: true,
...esServerlessImageParams,
// security is enabled by default, if needed kibana requires serviceAccountToken
esArgs: ['xpack.security.enabled=false'],
});
const client = getServerlessESClient({ port: esPort });
@ -116,6 +115,7 @@ const getServerlessESClient = ({ port }: { port: number }) => {
return new Client({
node: `http://localhost:${port}`,
Connection: HttpConnection,
auth: { ...systemIndicesSuperuser },
});
};
@ -130,6 +130,7 @@ const getServerlessDefault = () => {
},
elasticsearch: {
hosts: [`http://localhost:${esTestConfig.getPort()}`],
serviceAccountToken: kibanaDevServiceAccount.token,
},
migrations: {
algorithm: 'zdt',

View file

@ -19,6 +19,7 @@
"@kbn/repo-info",
"@kbn/repo-packages",
"@kbn/es",
"@kbn/dev-utils",
],
"exclude": [
"target/**/*",

View file

@ -31,7 +31,15 @@ describe('ES capabilities for serverless ES', () => {
});
it('returns the correct capabilities', async () => {
const capabilities = await getCapabilitiesFromClient(client);
const capabilities = await Promise.race([
getCapabilitiesFromClient(client),
new Promise((_, reject) =>
setTimeout(
() => reject('Waited 10+ seconds to get capabilities from ES, timed out...'),
10_000
)
),
]);
expect(capabilities).toEqual({
serverless: true,
});