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

[Security Solution][Endpoint] Refactor Cypress login task and ensure consistent use of users across ESS and Serverless tests #166958

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
326206b
added `RoleAndUserLoader` to scripts `common`
paul-tavares Sep 20, 2023
f321d31
better logging of errors in roleUserLoader
paul-tavares Sep 20, 2023
b006af6
refactor `ServerlessUser`
paul-tavares Sep 20, 2023
41a0f15
added `role_users/` index file + `getAllRoles()`
paul-tavares Sep 20, 2023
9d3d5d9
Added rule_author and t3_analyst
paul-tavares Sep 20, 2023
5249001
updates to the const's that keep list of roles names
paul-tavares Sep 21, 2023
6d61f53
new `EndpointSecurityTestRolesLoader` subclass
paul-tavares Sep 21, 2023
d54784b
Added `loadUserAndRole` cy.task
paul-tavares Sep 21, 2023
55324ef
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 21, 2023
104fe22
Moved type to `types.ts`
paul-tavares Sep 21, 2023
b3778fd
new common/constants
paul-tavares Sep 21, 2023
b800df4
Initial version of refactored `login()` task
paul-tavares Sep 21, 2023
e65eb46
Updated test files to replace `loginWithRole()` with `login()`
paul-tavares Sep 21, 2023
74030ae
introduce `login.withCustomRole()` and refactor prior approaches to t…
paul-tavares Sep 21, 2023
e86d1cb
Merge remote-tracking branch 'origin/task/olm-7690-cypress-login-task…
paul-tavares Sep 21, 2023
03e4537
refactored `resolver_generator_script` to use new roles loader
paul-tavares Sep 21, 2023
7f4e9e7
Fix cy test missing import
paul-tavares Sep 21, 2023
36f1736
Merge branch 'main' into task/olm-7690-cypress-login-task
paul-tavares Sep 22, 2023
1e4fe25
Deleted `loing_serverles` task. replaced usages with `login()`
paul-tavares Sep 25, 2023
fa698da
convert `KIBANA_KNOWN_DEFAULT_ACCOUNTS` to object
paul-tavares Sep 25, 2023
fff9bf9
Merge remote-tracking branch 'origin/task/olm-7690-cypress-login-task…
paul-tavares Sep 25, 2023
e1cf3ee
Merge remote-tracking branch 'upstream/main' into task/olm-7690-cypre…
paul-tavares Sep 25, 2023
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
@@ -0,0 +1,21 @@
/*
* 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 type { EndpointSecurityRoleNames } from '../../../../scripts/endpoint/common/roles_users';

export type KibanaKnownUserAccounts = keyof typeof KIBANA_KNOWN_DEFAULT_ACCOUNTS;

export type SecurityTestUser = EndpointSecurityRoleNames | KibanaKnownUserAccounts;

/**
* List of kibana system accounts
*/
export const KIBANA_KNOWN_DEFAULT_ACCOUNTS = {
elastic: 'elastic',
elastic_serverless: 'elastic_serverless',
system_indices_superuser: 'system_indices_superuser',
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import type {
HostPolicyResponse,
LogsEndpointActionResponse,
} from '../../../common/endpoint/types';
import type { IndexEndpointHostsCyTaskOptions, HostActionResponse } from './types';
import type {
HostActionResponse,
IndexEndpointHostsCyTaskOptions,
LoadUserAndRoleCyTaskOptions,
CreateUserAndRoleCyTaskOptions,
} from './types';
import type {
DeleteIndexedFleetEndpointPoliciesResponse,
IndexedFleetEndpointPolicyResponse,
Expand All @@ -32,6 +37,7 @@ import type {
DeletedIndexedEndpointRuleAlerts,
IndexedEndpointRuleAlerts,
} from '../../../common/endpoint/data_loaders/index_endpoint_rule_alerts';
import type { LoadedRoleAndUser } from '../../../scripts/endpoint/common/role_and_user_loader';

declare global {
namespace Cypress {
Expand Down Expand Up @@ -185,6 +191,18 @@ declare global {
arg: { hostname: string; path: string; password?: string },
options?: Partial<Loggable & Timeoutable>
): Chainable<string>;

task(
name: 'loadUserAndRole',
arg: LoadUserAndRoleCyTaskOptions,
options?: Partial<Loggable & Timeoutable>
): Chainable<LoadedRoleAndUser>;

task(
name: 'createUserAndRole',
arg: CreateUserAndRoleCyTaskOptions,
options?: Partial<Loggable & Timeoutable>
): Chainable<LoadedRoleAndUser>;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { getRoleWithArtifactReadPrivilege } from '../../fixtures/role_with_artifact_read_privilege';
import { getEndpointSecurityPolicyManager } from '../../../../../scripts/endpoint/common/roles_users/endpoint_security_policy_manager';
import { getArtifactsListTestsData } from '../../fixtures/artifacts_page';
import { visitPolicyDetailsPage } from '../../screens/policy_details';
Expand All @@ -16,27 +17,21 @@ import {
yieldFirstPolicyID,
} from '../../tasks/artifacts';
import { loadEndpointDataForEventFiltersIfNeeded } from '../../tasks/load_endpoint_data';
import {
getRoleWithArtifactReadPrivilege,
login,
loginWithCustomRole,
loginWithRole,
ROLE,
} from '../../tasks/login';
import { login, ROLE } from '../../tasks/login';
import { performUserActions } from '../../tasks/perform_user_actions';

const loginWithPrivilegeAll = () => {
loginWithRole(ROLE.endpoint_security_policy_manager);
login(ROLE.endpoint_policy_manager);
};

const loginWithPrivilegeRead = (privilegePrefix: string) => {
const roleWithArtifactReadPrivilege = getRoleWithArtifactReadPrivilege(privilegePrefix);
loginWithCustomRole('roleWithArtifactReadPrivilege', roleWithArtifactReadPrivilege);
login.withCustomRole({ name: 'roleWithArtifactReadPrivilege', ...roleWithArtifactReadPrivilege });
};

const loginWithPrivilegeNone = (privilegePrefix: string) => {
const roleWithoutArtifactPrivilege = getRoleWithoutArtifactPrivilege(privilegePrefix);
loginWithCustomRole('roleWithoutArtifactPrivilege', roleWithoutArtifactPrivilege);
login.withCustomRole({ name: 'roleWithoutArtifactPrivilege', ...roleWithoutArtifactPrivilege });
};

const getRoleWithoutArtifactPrivilege = (privilegePrefix: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
* 2.0.
*/

import {
getRoleWithArtifactReadPrivilege,
login,
loginWithCustomRole,
loginWithRole,
ROLE,
} from '../../tasks/login';
import { getRoleWithArtifactReadPrivilege } from '../../fixtures/role_with_artifact_read_privilege';
import { login, ROLE } from '../../tasks/login';
import { loadPage } from '../../tasks/common';

import { getArtifactsListTestsData } from '../../fixtures/artifacts_page';
Expand All @@ -20,18 +15,18 @@ import { performUserActions } from '../../tasks/perform_user_actions';
import { loadEndpointDataForEventFiltersIfNeeded } from '../../tasks/load_endpoint_data';

const loginWithWriteAccess = (url: string) => {
loginWithRole(ROLE.endpoint_security_policy_manager);
login(ROLE.endpoint_policy_manager);
loadPage(url);
};

const loginWithReadAccess = (privilegePrefix: string, url: string) => {
const roleWithArtifactReadPrivilege = getRoleWithArtifactReadPrivilege(privilegePrefix);
loginWithCustomRole('roleWithArtifactReadPrivilege', roleWithArtifactReadPrivilege);
login.withCustomRole({ name: 'roleWithArtifactReadPrivilege', ...roleWithArtifactReadPrivilege });
loadPage(url);
};

const loginWithoutAccess = (url: string) => {
loginWithRole(ROLE.t1_analyst);
login(ROLE.t1_analyst);
loadPage(url);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
} from '../../tasks/response_actions';
import { cleanupRule, generateRandomStringName, loadRule } from '../../tasks/api_fixtures';
import { RESPONSE_ACTION_TYPES } from '../../../../../common/api/detection_engine';
import { loginWithRole, ROLE } from '../../tasks/login';
import { login, ROLE } from '../../tasks/login';

describe('Form', { tags: '@ess' }, () => {
describe('User with no access can not create an endpoint response action', () => {
before(() => {
loginWithRole(ROLE.endpoint_response_actions_no_access);
login(ROLE.endpoint_response_actions_no_access);
});

it('no endpoint response action option during rule creation', () => {
Expand All @@ -36,7 +36,7 @@ describe('Form', { tags: '@ess' }, () => {
const [ruleName, ruleDescription] = generateRandomStringName(2);

before(() => {
loginWithRole(ROLE.endpoint_response_actions_access);
login(ROLE.endpoint_response_actions_access);
});
after(() => {
cleanupRule(ruleId);
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Form', { tags: '@ess' }, () => {
});
});
beforeEach(() => {
loginWithRole(ROLE.endpoint_response_actions_access);
login(ROLE.endpoint_response_actions_access);
});
after(() => {
cleanupRule(ruleId);
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('Form', { tags: '@ess' }, () => {
const [ruleName, ruleDescription] = generateRandomStringName(2);

before(() => {
loginWithRole(ROLE.endpoint_response_actions_no_access);
login(ROLE.endpoint_response_actions_no_access);
});

it('response actions are disabled', () => {
Expand All @@ -166,7 +166,7 @@ describe('Form', { tags: '@ess' }, () => {
loadRule().then((res) => {
ruleId = res.id;
});
loginWithRole(ROLE.endpoint_response_actions_no_access);
login(ROLE.endpoint_response_actions_no_access);
});
after(() => {
cleanupRule(ruleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { disableExpandableFlyoutAdvancedSettings } from '../../tasks/common';
import { APP_ALERTS_PATH } from '../../../../../common/constants';
import { closeAllToasts } from '../../tasks/toasts';
import { fillUpNewRule } from '../../tasks/response_actions';
import { login, loginWithRole, ROLE } from '../../tasks/login';
import { login, ROLE } from '../../tasks/login';
import { generateRandomStringName } from '../../tasks/utils';
import type { ReturnTypeFromChainable } from '../../types';
import { indexEndpointHosts } from '../../tasks/index_endpoint_hosts';
Expand All @@ -20,7 +20,7 @@ describe('No License', { tags: '@ess', env: { ftrConfig: { license: 'basic' } }
const [ruleName, ruleDescription] = generateRandomStringName(2);

before(() => {
loginWithRole(ROLE.endpoint_response_actions_access);
login(ROLE.endpoint_response_actions_access);
});

it('response actions are disabled', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { CyIndexEndpointHosts } from '../../tasks/index_endpoint_hosts';
import { indexEndpointHosts } from '../../tasks/index_endpoint_hosts';
import { loginServerless } from '../../tasks/login_serverless';
import { login } from '../../tasks/login';
import {
getConsoleActionMenuItem,
getUnIsolateActionMenuItem,
Expand Down Expand Up @@ -42,7 +42,7 @@ describe(
});

beforeEach(() => {
loginServerless();
login();
visitEndpointList();
openRowActionMenu();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ensureResponseActionAuthzAccess } from '../../../tasks/response_actions';
import { loginServerless, ServerlessUser } from '../../../tasks/login_serverless';
import { login, ROLE } from '../../../tasks/login';
import { RESPONSE_ACTION_API_COMMANDS_NAMES } from '../../../../../../common/endpoint/service/response_actions/constants';
import { getNoPrivilegesPage } from '../../../screens/common';
import { getEndpointManagementPageList } from '../../../screens';
Expand All @@ -31,7 +31,7 @@ describe(
let password: string;

beforeEach(() => {
loginServerless(ServerlessUser.ENDPOINT_OPERATIONS_ANALYST).then((response) => {
login(ROLE.endpoint_operations_analyst).then((response) => {
username = response.username;
password = response.password;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ensureResponseActionAuthzAccess } from '../../../tasks/response_actions';
import { loginServerless, ServerlessUser } from '../../../tasks/login_serverless';
import { login, ROLE } from '../../../tasks/login';
import { RESPONSE_ACTION_API_COMMANDS_NAMES } from '../../../../../../common/endpoint/service/response_actions/constants';
import {
getEndpointManagementPageList,
Expand All @@ -33,7 +33,7 @@ describe(
let password: string;

beforeEach(() => {
loginServerless(ServerlessUser.ENDPOINT_OPERATIONS_ANALYST).then((response) => {
login(ROLE.endpoint_operations_analyst).then((response) => {
username = response.username;
password = response.password;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ensureResponseActionAuthzAccess } from '../../../tasks/response_actions';
import { loginServerless, ServerlessUser } from '../../../tasks/login_serverless';
import { login, ROLE } from '../../../tasks/login';
import { RESPONSE_ACTION_API_COMMANDS_NAMES } from '../../../../../../common/endpoint/service/response_actions/constants';
import { getNoPrivilegesPage } from '../../../screens/common';
import { getEndpointManagementPageList } from '../../../screens';
Expand All @@ -33,7 +33,7 @@ describe(
let password: string;

beforeEach(() => {
loginServerless(ServerlessUser.ENDPOINT_OPERATIONS_ANALYST).then((response) => {
login(ROLE.endpoint_operations_analyst).then((response) => {
username = response.username;
password = response.password;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ensureResponseActionAuthzAccess } from '../../../tasks/response_actions';
import { loginServerless, ServerlessUser } from '../../../tasks/login_serverless';
import { login, ROLE } from '../../../tasks/login';
import { RESPONSE_ACTION_API_COMMANDS_NAMES } from '../../../../../../common/endpoint/service/response_actions/constants';
import {
getEndpointManagementPageMap,
Expand Down Expand Up @@ -41,7 +41,7 @@ describe(
let password: string;

beforeEach(() => {
loginServerless(ServerlessUser.ENDPOINT_OPERATIONS_ANALYST).then((response) => {
login(ROLE.endpoint_operations_analyst).then((response) => {
username = response.username;
password = response.password;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { loginServerless } from '../../tasks/login_serverless';
import { login } from '../../tasks/login';
import { visitPolicyDetailsPage } from '../../screens/policy_details';
import type { IndexedFleetEndpointPolicyResponse } from '../../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy';

Expand Down Expand Up @@ -35,7 +35,7 @@ describe(
});

beforeEach(() => {
loginServerless();
login();
visitPolicyDetailsPage(loadedPolicyData.integrationPolicies[0].id);
});

Expand Down
Loading
Loading