Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FTR](combined) update common serverless api tests to use api keys #181741

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
c682091
[FTR] update common serverless api tests to use api keys
wayneseymour Apr 25, 2024
d83c102
data_view_fied_editor folder
wayneseymour Apr 26, 2024
72feb2b
grok_debugger folder
wayneseymour Apr 26, 2024
af3a6c3
kql_telemetry folder
wayneseymour Apr 26, 2024
22dde6d
lower privs.
wayneseymour May 6, 2024
e44e56d
soooo, using viewer works,
wayneseymour May 6, 2024
ecdbf00
put this back
wayneseymour May 6, 2024
424004d
use viewer
wayneseymour May 6, 2024
6d28f9d
viewer works here too
wayneseymour May 6, 2024
aacc98b
viewer
wayneseymour May 6, 2024
3b23cbf
viewer
wayneseymour May 6, 2024
8976d72
add method to create api key for default role, and add debug logging
wayneseymour May 7, 2024
6d703c6
use new method
wayneseymour May 7, 2024
ceeea95
try this
wayneseymour May 7, 2024
826f441
drop unused.
wayneseymour May 7, 2024
6c39a83
use default
wayneseymour May 7, 2024
b8ae089
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 7, 2024
9747838
use admin
wayneseymour May 7, 2024
427ac53
use default for es_api home
wayneseymour May 7, 2024
e9c7f16
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 8, 2024
23dc327
Looks like using the default role for oblt didnt pass in ci
wayneseymour May 8, 2024
845cefc
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 8, 2024
e5859f0
use default role and and some debug
wayneseymour May 8, 2024
a4e2d39
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 9, 2024
f5bb385
default role works on local,
wayneseymour May 9, 2024
f3b04a9
this is the only way it's working on mki
wayneseymour May 9, 2024
2bedbb5
Let's see if this passes on ci.
wayneseymour May 9, 2024
cbf0d4d
drop log
wayneseymour May 9, 2024
29b11db
only works with admin
wayneseymour May 9, 2024
245f255
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 9, 2024
ca44c2f
had to use admin
wayneseymour May 9, 2024
f907c17
default role not working either
wayneseymour May 9, 2024
ad8d2e2
use admin
wayneseymour May 10, 2024
1efe7f3
gotta use admin
wayneseymour May 10, 2024
1ea7ca4
only admin is working
wayneseymour May 10, 2024
ba0b8fe
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 10, 2024
f394171
developer works on my local, against docker
wayneseymour May 10, 2024
11e3386
use admin
wayneseymour May 10, 2024
ba04a46
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 10, 2024
e5d32de
Update per Yulia
wayneseymour May 10, 2024
cfdfd7a
use type
wayneseymour May 10, 2024
aeacb23
use type
wayneseymour May 10, 2024
4a376b0
Merge branch 'main' into update-common-svrless-api-tests/combined
kibanamachine May 11, 2024
32a357b
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 13, 2024
33b57ad
only works with admin now
wayneseymour May 13, 2024
7469b4d
Merge branch 'update-common-svrless-api-tests/combined' of github.com…
wayneseymour May 13, 2024
088e9fb
Gotta use admin for /api/console/autocomplete_entities now
wayneseymour May 13, 2024
b048a54
only admin works now, for GET /api/console/es_config
wayneseymour May 13, 2024
35b098b
only admin now
wayneseymour May 14, 2024
91b7042
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 14, 2024
ac13a09
add in changes from combined 2 branch
wayneseymour May 14, 2024
eecde2e
reverting alerting, to be in another pr
wayneseymour May 14, 2024
db88350
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 14, 2024
170b5fa
delete pr review comment: https://github.com/elastic/kibana/pull/1817…
wayneseymour May 14, 2024
a3c7b06
reverting translations, to be in another pr
wayneseymour May 14, 2024
f67e959
whoops, this also will be in the alerting branch.
wayneseymour May 14, 2024
bf8af15
now editor works, and not viewer
wayneseymour May 14, 2024
76b4038
use admin
wayneseymour May 14, 2024
4c1fee3
Merge branch 'main' of github.com:elastic/kibana into update-common-s…
wayneseymour May 15, 2024
56efd6f
drop comment
wayneseymour May 15, 2024
b8c0592
add before / after per cr
wayneseymour May 15, 2024
575f85d
revert
wayneseymour May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default ({ getService }: FtrProviderContext) => {
const svlCommonApi = getService('svlCommonApi');
const consoleService = getService('console');
const supertest = getService('supertest');
const sendRequest = (query: object) =>
supertest

const svlUserManager = getService('svlUserManager');
const supertestWithoutAuth = getService('supertestWithoutAuth');
let internalRequestHeader: Record<string, string>;
let roleAuthc: RoleCredentials;
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved

const sendRequest = async (query: object) => {
return await supertestWithoutAuth
.get('/api/console/autocomplete_entities')
.set(svlCommonApi.getInternalRequestHeader())
.set(internalRequestHeader)
.set(roleAuthc.apiKeyHeader)
.query(query);
};

describe('/api/console/autocomplete_entities', function () {
let createIndex: typeof consoleService['helpers']['createIndex'];
Expand All @@ -37,6 +45,8 @@ export default ({ getService }: FtrProviderContext) => {
const dataStreamName = 'test-data-stream-1';

before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('viewer');
internalRequestHeader = svlCommonApi.getInternalRequestHeader();
({
helpers: {
createIndex,
Expand Down Expand Up @@ -67,6 +77,8 @@ export default ({ getService }: FtrProviderContext) => {
await deleteDataStream(dataStreamName);
await deleteIndexTemplate(indexTemplateName);
await deleteComponentTemplate(componentTemplateName);

await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});

it('should not succeed if no settings are provided in query params', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');

const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');

describe('GET /api/console/es_config', () => {
it('returns es host', async () => {
const { body } = await supertest
const roleAuthc: RoleCredentials = await svlUserManager.createApiKeyForRole('viewer');
const { body } = await supertestWithoutAuth
.get('/api/console/es_config')
.set('kbn-xsrf', 'true')
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.expect(200);
expect(body.host).to.be.ok();
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion : using before / after hooks to generate/invalidate API key; This way we will invalidate key even if it fails

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertest = getService('supertest');
let roleAuthc: RoleCredentials;

describe('POST /api/console/proxy', () => {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('viewer');
});
after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
describe('system indices behavior', () => {
it('returns warning header when making requests to .kibana index', async () => {
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
return await supertest
.post('/api/console/proxy?method=GET&path=/.kibana/_settings')
.set('kbn-xsrf', 'true')
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.then((response) => {
expect(response.header).to.have.property('warning');
const { warning } = response.header as { warning: string };
Expand All @@ -34,6 +44,7 @@ export default function ({ getService }: FtrProviderContext) {
.set('kbn-xsrf', 'true')
.set(svlCommonApi.getInternalRequestHeader())
.set('x-elastic-product-origin', 'kibana')
.set(roleAuthc.apiKeyHeader)
.then((response) => {
expect(response.header).to.have.property('warning');
const { warning } = response.header as { warning: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlUserManager = getService('svlUserManager');
let roleAuthc: RoleCredentials;
const svlCommonApi = getService('svlCommonApi');

describe('GET /api/console/api_server', () => {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('viewer');
});
after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
it('returns autocomplete definitions', async () => {
const { body } = await supertest
.get('/api/console/api_server')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
let roleAuthc: RoleCredentials;
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('/api/core/capabilities', () => {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('viewer');
});
after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
it(`returns a 400 when an invalid app id is provided`, async () => {
const { body } = await supertest
const { body } = await supertestWithoutAuth
.post('/api/core/capabilities')
.set(svlCommonApi.getInternalRequestHeader())
.send({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,46 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
let roleAuthc: RoleCredentials;
const supertestWithoutAuth = getService('supertestWithoutAuth');

const compressionSuite = (url: string) => {
it(`uses compression when there isn't a referer`, async () => {
await supertest
await supertestWithoutAuth
.get(url)
.set('accept-encoding', 'gzip')
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.then((response) => {
expect(response.header).to.have.property('content-encoding', 'gzip');
});
});

it(`uses compression when there is a whitelisted referer`, async () => {
await supertest
await supertestWithoutAuth
.get(url)
.set('accept-encoding', 'gzip')
.set(svlCommonApi.getInternalRequestHeader())
.set('referer', 'https://some-host.com')
.set(roleAuthc.apiKeyHeader)
.then((response) => {
expect(response.header).to.have.property('content-encoding', 'gzip');
});
});
};

describe('compression', () => {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('viewer');
});
after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
describe('against an application page', () => {
compressionSuite('/app/kibana');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,72 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
let roleAuthc: RoleCredentials;
const supertestWithoutAuth = getService('supertestWithoutAuth');

describe('translations', () => {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('viewer');
});
after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});
it(`returns the translations with the correct headers`, async () => {
await supertest.get('/translations/en.json').then((response) => {
expect(response.body.locale).to.eql('en');
await supertestWithoutAuth
.get('/translations/en.json')
.set(svlCommonApi.getInternalRequestHeader())
wayneseymour marked this conversation as resolved.
Show resolved Hide resolved
.set(roleAuthc.apiKeyHeader)
.then((response) => {
expect(response.body.locale).to.eql('en');

expect(response.header).to.have.property('content-type', 'application/json; charset=utf-8');
expect(response.header).to.have.property(
'cache-control',
'public, max-age=31536000, immutable'
);
expect(response.header).not.to.have.property('etag');
});
expect(response.header).to.have.property(
'content-type',
'application/json; charset=utf-8'
);
// console.dir(response.header);
/**
* `response.header` Looks like:
* {
* 'content-type': 'application/json; charset=utf-8',
* 'cache-control': 'must-revalidate',
* etag: '"18cda523c38f"',
* 'strict-transport-security': 'max-age=31536000; includeSubDomains',
* 'x-content-type-options': 'nosniff',
* 'referrer-policy': 'strict-origin-when-cross-origin',
* 'permissions-policy': 'camera=(), display-capture=(), fullscreen=(self), geolocation=(), microphone=(), web-share=()',
* 'cross-origin-opener-policy': 'same-origin',
* 'x-frame-options': 'SAMEORIGIN',
* 'content-security-policy': "script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'; frame-ancestors 'self'",
* 'content-security-policy-report-only': "form-action 'report-sample' 'self'",
* 'kbn-name': 'Waynes-MacBook-Pro.local',
* 'kbn-license-sig': '427a6af7553264697c4ddd1715e5758da34809ba708665a0bcc7c0d550c850ae',
* 'content-length': '29',
* 'accept-ranges': 'bytes',
* date: 'Mon, 06 May 2024 14:43:15 GMT',
* connection: 'close'
* }
*/
// expect(response.header).to.have.property(
wayneseymour marked this conversation as resolved.
Show resolved Hide resolved
// 'cache-control',
// 'public, max-age=31536000, immutable'
// );
// expect(response.header).not.to.have.property('etag');
});
});

it(`returns a 404 when not using the correct locale`, async () => {
await supertest.get('/translations/foo.json').then((response) => {
expect(response.status).to.eql(404);
});
await supertestWithoutAuth
.get('/translations/foo.json')
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.then((response) => {
expect(response.status).to.eql(404);
});
});
});
}
Loading