Skip to content

Commit

Permalink
Merge branch 'main' into ftr/fix-login-on-MKI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko authored Sep 27, 2023
2 parents 1cf92ce + 7013a9b commit ba20b20
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { loggingSystemMock } from '@kbn/core/server/mocks';
import { createBenchmarkScoreIndex } from './create_indices';
import {
BENCHMARK_SCORE_INDEX_DEFAULT_NS,
BENCHMARK_SCORE_INDEX_PATTERN,
BENCHMARK_SCORE_INDEX_TEMPLATE_NAME,
CSP_INGEST_TIMESTAMP_PIPELINE,
} from '../../common/constants';
import { IndicesGetIndexTemplateIndexTemplateItem } from '@elastic/elasticsearch/lib/api/types';

const mockEsClient = elasticsearchClientMock.createClusterClient().asScoped().asInternalUser;

describe('createBenchmarkScoreIndex', () => {
let logger: ReturnType<typeof loggingSystemMock.createLogger>;

beforeEach(() => {
logger = loggingSystemMock.createLogger();
jest.resetAllMocks();
});

it('should delete old index template from prev verions first', async () => {
mockEsClient.indices.getIndexTemplate.mockResolvedValueOnce({
index_templates: [{ name: 'foo' } as IndicesGetIndexTemplateIndexTemplateItem],
});
// @ts-ignore
await createBenchmarkScoreIndex(mockEsClient, { serverless: { enabled: false } }, logger);
expect(mockEsClient.indices.deleteIndexTemplate).toHaveBeenCalledTimes(1);
expect(mockEsClient.indices.deleteIndexTemplate).toHaveBeenCalledWith({
name: 'cloud_security_posture.scores',
});
});

it('should create index template with the correct index pattern, index name and default ingest pipeline', async () => {
// @ts-ignore
await createBenchmarkScoreIndex(mockEsClient, { serverless: { enabled: false } }, logger);
expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1);
expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledWith(
expect.objectContaining({
name: BENCHMARK_SCORE_INDEX_TEMPLATE_NAME,
index_patterns: BENCHMARK_SCORE_INDEX_PATTERN,
template: expect.objectContaining({
settings: {
index: {
default_pipeline: CSP_INGEST_TIMESTAMP_PIPELINE,
},
lifecycle: {
name: '',
},
},
}),
})
);
});

it('should create index template the correct index patter, index name and default ingest pipeline but without lifecycle in serverless', async () => {
await createBenchmarkScoreIndex(
mockEsClient,
{ serverless: { enabled: true }, enabled: true },
logger
);
expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1);
expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledWith(
expect.objectContaining({
name: BENCHMARK_SCORE_INDEX_TEMPLATE_NAME,
index_patterns: BENCHMARK_SCORE_INDEX_PATTERN,
template: expect.objectContaining({
settings: expect.not.objectContaining({
lifecycle: {
name: '',
},
}),
}),
})
);
});

it('should create index if does not exist', async () => {
mockEsClient.indices.exists.mockResolvedValueOnce(false);

await createBenchmarkScoreIndex(
mockEsClient,
{ serverless: { enabled: true }, enabled: true },
logger
);
expect(mockEsClient.indices.create).toHaveBeenCalledTimes(1);
expect(mockEsClient.indices.create).toHaveBeenCalledWith({
index: BENCHMARK_SCORE_INDEX_DEFAULT_NS,
});
expect(mockEsClient.indices.putMapping).toHaveBeenCalledTimes(0);
});

it('should updat index mapping if index exists', async () => {
mockEsClient.indices.exists.mockResolvedValueOnce(true);

await createBenchmarkScoreIndex(
mockEsClient,
{ serverless: { enabled: true }, enabled: true },
logger
);
expect(mockEsClient.indices.create).toHaveBeenCalledTimes(0);
expect(mockEsClient.indices.putMapping).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const initializeCspIndices = async (
}
};

const createBenchmarkScoreIndex = async (
export const createBenchmarkScoreIndex = async (
esClient: ElasticsearchClient,
cloudSecurityPostureConfig: CloudSecurityPostureConfig,
logger: Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { waitForFleetSetup } from './helpers';

const logFilePath = path.join(__dirname, 'logs.log');

describe('fleet usage telemetry', () => {
// Failing: See https://github.com/elastic/kibana/issues/156245
describe.skip('fleet usage telemetry', () => {
let core: any;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/osquery/cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"resolveJsonModule": true,
},
"kbn_references": [
{
"path": "../../../test_serverless/tsconfig.json"
},
"@kbn/cypress-config",
// cypress projects that are nested inside of other ts project use code
// from the parent ts project in ways that can't be automatically deteceted
Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,17 @@ ${JSON.stringify(cypressConfigFile, null, 2)}
Cypress FTR setup for file: ${filePath}:
----------------------------------------------
${JSON.stringify(config.getAll(), null, 2)}
${JSON.stringify(
config.getAll(),
(key, v) => {
if (Array.isArray(v) && v.length > 32) {
return v.slice(0, 32).concat('... trimmed after 32 items.');
} else {
return v;
}
},
2
)}
----------------------------------------------
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
import { useStorage } from '@kbn/ml-local-storage';
import { useUrlState } from '@kbn/ml-url-state';

import { useEnabledFeatures } from '../../../../serverless_context';
import { PivotAggDict } from '../../../../../../common/types/pivot_aggs';
import { PivotGroupByDict } from '../../../../../../common/types/pivot_group_by';
import { TRANSFORM_FUNCTION } from '../../../../../../common/constants';
Expand Down Expand Up @@ -113,7 +112,6 @@ export const StepDefineForm: FC<StepDefineFormProps> = React.memo((props) => {
);
const toastNotifications = useToastNotifications();
const stepDefineForm = useStepDefineForm(props);
const { showNodeInfo } = useEnabledFeatures();

const { advancedEditorConfig } = stepDefineForm.advancedPivotEditor.state;
const {
Expand Down Expand Up @@ -355,7 +353,6 @@ export const StepDefineForm: FC<StepDefineFormProps> = React.memo((props) => {
query={undefined}
disabled={false}
timefilter={timefilter}
hideFrozenDataTierChoice={!showNodeInfo}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default function ({ getPageObjects, getService }) {
const testSubjects = getService('testSubjects');
const security = getService('security');

describe('maps add-to-dashboard save flow', () => {
// Failing: See https://github.com/elastic/kibana/issues/167320
describe.skip('maps add-to-dashboard save flow', () => {
before(async () => {
await security.testUser.setRoles(
[
Expand Down
14 changes: 7 additions & 7 deletions x-pack/test_serverless/api_integration/services/svl_cases/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import { CasesFindResponse } from '@kbn/cases-plugin/common/types/api';
import { kbnTestConfig, kibanaTestSuperuserServerless } from '@kbn/test';
import { FtrProviderContext } from '../../ftr_provider_context';

export interface User {
username: string;
password: string;
description?: string;
roles: string[];
}

export function SvlCasesApiServiceProvider({ getService }: FtrProviderContext) {
const kbnServer = getService('kibanaServer');
const supertest = getService('supertest');

interface User {
username: string;
password: string;
description?: string;
roles: string[];
}

const superUser: User = {
username: 'superuser',
password: 'superuser',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { Case, Attachment } from '@kbn/cases-plugin/common/types/domain';
import { omit } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';

export function SvlCasesOmitServiceProvider({}: FtrProviderContext) {
interface CommonSavedObjectAttributes {
id?: string | null;
created_at?: string | null;
updated_at?: string | null;
version?: string | null;
[key: string]: unknown;
}
export interface CommonSavedObjectAttributes {
id?: string | null;
created_at?: string | null;
updated_at?: string | null;
version?: string | null;
[key: string]: unknown;
}

export function SvlCasesOmitServiceProvider({}: FtrProviderContext) {
const savedObjectCommonAttributes = ['created_at', 'updated_at', 'version', 'id'];

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Cypress.Commands.add('loginAsElasticUser', () => {
method: 'POST',
url: `${kibanaUrlWithoutAuth}/internal/security/login`,
body: {
providerType: basicProvider.type,
providerName: basicProvider.name,
providerType: basicProvider?.type,
providerName: basicProvider?.name,
currentURL: `${kibanaUrlWithoutAuth}/login`,
params: { username, password },
},
Expand Down

0 comments on commit ba20b20

Please sign in to comment.