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

[Serverless][Security Solution][Endpoint] Remove use of hooks to check access to.lists-* for endpoint exceptions access #171412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -5,19 +5,10 @@
* 2.0.
*/

import { useMemo } from 'react';
import { useListsConfig } from '../../../detections/containers/detection_engine/lists/use_lists_config';
import { useHasSecurityCapability } from '../../../helper_hooks';

export const useEndpointExceptionsCapability = (
capability: 'showEndpointExceptions' | 'crudEndpointExceptions'
) => {
const { loading: listsConfigLoading, needsConfiguration: needsListsConfiguration } =
useListsConfig();
const hasEndpointExceptionCapability = useHasSecurityCapability(capability);

return useMemo(
() => !listsConfigLoading && !needsListsConfiguration && hasEndpointExceptionCapability,
[hasEndpointExceptionCapability, listsConfigLoading, needsListsConfiguration]
);
): boolean => {
return useHasSecurityCapability(capability);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 { getNewRule } from '../../../objects/rule';
import { createRule } from '../../../tasks/api_calls/rules';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { login } from '../../../tasks/login';
import { visit } from '../../../tasks/navigation';
import { ALERTS_URL } from '../../../urls/navigation';

/*
*
* Alert table is third party component which cannot be easily tested by jest.
* This test main checks if Alert Table does not call api/lists/index more than once.
*
* */

describe('Alert Table API calls', { tags: ['@ess', '@serverless'] }, () => {
let callCount: number = 0;

beforeEach(() => {
callCount = 0;
login();
createRule(getNewRule());
// intercept all calls to `api/lists/index`
// and count how many times it was called
cy.intercept('GET', '/api/lists/index', (req) => {
req.on('response', (res) => {
if (res.statusCode === 200) {
callCount += 1;
}
});
});

visit(ALERTS_URL);
waitForAlertsToPopulate();
});

it('should call `api/lists/index` only once', () => {
cy.get('[data-test-subj="alertsTable"]').then(() => {
expect(callCount, 'number of times lists index api is called').to.equal(1);
});
});
});
Loading