|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +import { expect } from '@kbn/scout/api'; |
| 11 | +import { apiTest, tags } from '@kbn/scout'; |
| 12 | +import type { RoleApiCredentials } from '@kbn/scout'; |
| 13 | +import { COMMON_HEADERS } from '../fixtures'; |
| 14 | + |
| 15 | +const SERVERLESS_TAGS = [ |
| 16 | + ...tags.serverless.search, |
| 17 | + ...tags.serverless.observability.complete, |
| 18 | + ...tags.serverless.security.complete, |
| 19 | + ...tags.serverless.workplaceai, |
| 20 | +]; |
| 21 | + |
| 22 | +const BLOCKED_APIS: Array<{ path: string; method: 'get' | 'post' | 'put' | 'delete' }> = [ |
| 23 | + { path: '/api/saved_objects/_bulk_create', method: 'post' }, |
| 24 | + { path: '/api/saved_objects/_bulk_delete', method: 'post' }, |
| 25 | + { path: '/api/saved_objects/_bulk_get', method: 'post' }, |
| 26 | + { path: '/api/saved_objects/_bulk_resolve', method: 'post' }, |
| 27 | + { path: '/api/saved_objects/_bulk_update', method: 'post' }, |
| 28 | + { path: '/api/saved_objects/test/id', method: 'get' }, |
| 29 | + { path: '/api/saved_objects/test/id', method: 'post' }, |
| 30 | + { path: '/api/saved_objects/test/id', method: 'delete' }, |
| 31 | + { path: '/api/saved_objects/_find', method: 'get' }, |
| 32 | + { path: '/api/saved_objects/test/id', method: 'put' }, |
| 33 | +]; |
| 34 | + |
| 35 | +apiTest.describe('blocked internal saved objects API', { tag: SERVERLESS_TAGS }, () => { |
| 36 | + let credentials: RoleApiCredentials; |
| 37 | + |
| 38 | + apiTest.beforeAll(async ({ requestAuth }) => { |
| 39 | + credentials = await requestAuth.getApiKey('viewer'); |
| 40 | + }); |
| 41 | + |
| 42 | + for (const { path, method } of BLOCKED_APIS) { |
| 43 | + apiTest(`${method} ${path} returns 400`, async ({ apiClient }) => { |
| 44 | + const response = await apiClient[method](path, { |
| 45 | + headers: { |
| 46 | + ...COMMON_HEADERS, |
| 47 | + ...credentials.apiKeyHeader, |
| 48 | + }, |
| 49 | + }); |
| 50 | + |
| 51 | + expect(response).toHaveStatusCode(400); |
| 52 | + expect(response.body).toStrictEqual({ |
| 53 | + statusCode: 400, |
| 54 | + error: 'Bad Request', |
| 55 | + message: `uri [${path}] with method [${method}] exists but is not available with the current configuration`, |
| 56 | + }); |
| 57 | + }); |
| 58 | + } |
| 59 | +}); |
0 commit comments