Commit d601573f authored by Alexander Turinske's avatar Alexander Turinske Committed by Natalia Tepluhina

Update vulnerabilities query to be agent-specific

- add clusterAgentID field
- update tests
parent 18305dff
...@@ -122,7 +122,7 @@ export default { ...@@ -122,7 +122,7 @@ export default {
</p> </p>
<gl-tabs sync-active-tab-with-query-params lazy> <gl-tabs sync-active-tab-with-query-params lazy>
<slot name="ee-security-tab"></slot> <slot name="ee-security-tab" :cluster-agent-id="clusterAgent.id"></slot>
<gl-tab :title="$options.i18n.activity" query-param-value="activity"> <gl-tab :title="$options.i18n.activity" query-param-value="activity">
<activity-events :agent-name="agentName" :project-path="projectPath" /> <activity-events :agent-name="agentName" :project-path="projectPath" />
......
...@@ -27,9 +27,9 @@ export default { ...@@ -27,9 +27,9 @@ export default {
<template> <template>
<agent-show-page> <agent-show-page>
<template v-if="showSecurityTab" #ee-security-tab> <template v-if="showSecurityTab" #ee-security-tab="{ clusterAgentId }">
<gl-tab :title="$options.i18n.securityTabTitle"> <gl-tab :title="$options.i18n.securityTabTitle">
<agent-vulnerability-report /> <agent-vulnerability-report :cluster-agent-id="clusterAgentId" />
</gl-tab> </gl-tab>
</template> </template>
</agent-show-page> </agent-show-page>
......
...@@ -34,23 +34,26 @@ export default { ...@@ -34,23 +34,26 @@ export default {
}; };
}, },
inject: ['projectPath'], inject: ['projectPath'],
props: {
clusterAgentId: {
type: String,
required: true,
},
},
data() { data() {
return { return {
graphqlFilters: undefined, graphqlFilters: { clusterAgentId: [this.clusterAgentId] },
}; };
}, },
computed: {
filtersToShow() {
return FILTER_PRESETS[REPORT_TAB.OPERATIONAL];
},
},
methods: { methods: {
updateGraphqlFilters(graphqlFilters) { updateGraphqlFilters(graphqlFilters) {
this.graphqlFilters = graphqlFilters; this.graphqlFilters = graphqlFilters;
this.graphqlFilters.reportType = REPORT_TYPE_PRESETS.OPERATIONAL; this.graphqlFilters.reportType = REPORT_TYPE_PRESETS.OPERATIONAL;
this.graphqlFilters.clusterAgentId = [this.clusterAgentId];
}, },
}, },
fieldsToShow: FIELD_PRESETS[REPORT_TAB.OPERATIONAL], fieldsToShow: FIELD_PRESETS[REPORT_TAB.OPERATIONAL],
filtersToShow: FILTER_PRESETS[REPORT_TAB.OPERATIONAL],
REPORT_TAB, REPORT_TAB,
projectVulnerabilitiesQuery, projectVulnerabilitiesQuery,
}; };
...@@ -59,7 +62,7 @@ export default { ...@@ -59,7 +62,7 @@ export default {
<template> <template>
<div> <div>
<vulnerability-filters <vulnerability-filters
:filters="filtersToShow" :filters="$options.filtersToShow"
class="security-dashboard-filters gl-mt-7" class="security-dashboard-filters gl-mt-7"
@filters-changed="updateGraphqlFilters" @filters-changed="updateGraphqlFilters"
/> />
......
...@@ -14,6 +14,7 @@ query projectVulnerabilities( ...@@ -14,6 +14,7 @@ query projectVulnerabilities(
$hasResolution: Boolean $hasResolution: Boolean
$includeExternalIssueLinks: Boolean = false $includeExternalIssueLinks: Boolean = false
$vetEnabled: Boolean = false $vetEnabled: Boolean = false
$clusterAgentId: [ClustersAgentID!]
) { ) {
project(fullPath: $fullPath) { project(fullPath: $fullPath) {
id id
...@@ -28,6 +29,7 @@ query projectVulnerabilities( ...@@ -28,6 +29,7 @@ query projectVulnerabilities(
sort: $sort sort: $sort
hasIssues: $hasIssues hasIssues: $hasIssues
hasResolution: $hasResolution hasResolution: $hasResolution
clusterAgentId: $clusterAgentId
) { ) {
nodes { nodes {
...VulnerabilityFragment ...VulnerabilityFragment
......
import { GlTab } from '@gitlab/ui'; import { GlTab } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import { stubComponent } from 'helpers/stub_component';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import ClusterAgentShow from 'ee/clusters/agents/components/show.vue'; import ClusterAgentShow from 'ee/clusters/agents/components/show.vue';
import AgentShowPage from '~/clusters/agents/components/show.vue';
import AgentVulnerabilityReport from 'ee/security_dashboard/components/agent/agent_vulnerability_report.vue';
describe('ClusterAgentShow', () => { describe('ClusterAgentShow', () => {
let wrapper; let wrapper;
const clusterAgentId = 'gid://gitlab/Clusters::Agent/1';
const AgentShowPageStub = stubComponent(AgentShowPage, {
provide: { agentName: 'test', projectPath: 'test' },
template: `<div><slot name="ee-security-tab" clusterAgentId="${clusterAgentId}"></slot></div>`,
});
const createWrapper = ({ glFeatures = {} } = {}) => { const createWrapper = ({ glFeatures = {} } = {}) => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
shallowMount(ClusterAgentShow, { shallowMount(ClusterAgentShow, {
provide: { glFeatures }, provide: { glFeatures },
stubs: {
AgentShowPage: AgentShowPageStub,
},
}), }),
); );
}; };
const findAgentVulnerabilityReport = () => wrapper.findComponent(AgentVulnerabilityReport);
const findTab = () => wrapper.findComponent(GlTab); const findTab = () => wrapper.findComponent(GlTab);
afterEach(() => { afterEach(() => {
...@@ -34,4 +47,14 @@ describe('ClusterAgentShow', () => { ...@@ -34,4 +47,14 @@ describe('ClusterAgentShow', () => {
expect(findTab().exists()).toBe(tabStatus); expect(findTab().exists()).toBe(tabStatus);
}); });
}); });
describe('vulnerability report', () => {
it('renders with cluster agent id', async () => {
createWrapper({
glFeatures: { clusterVulnerabilities: true, kubernetesClusterVulnerabilities: true },
});
await nextTick();
expect(findAgentVulnerabilityReport().props('clusterAgentId')).toBe(clusterAgentId);
});
});
}); });
...@@ -9,6 +9,7 @@ exports[`Agent vulnerability report component renders 1`] = ` ...@@ -9,6 +9,7 @@ exports[`Agent vulnerability report component renders 1`] = `
<vulnerability-list-graphql-stub <vulnerability-list-graphql-stub
fields="[object Object],[object Object],[object Object],[object Object],,[object Object]" fields="[object Object],[object Object],[object Object],[object Object],,[object Object]"
filters="[object Object]"
query="[object Object]" query="[object Object]"
/> />
</div> </div>
......
...@@ -4,10 +4,11 @@ import AgentVulnerabilityReport from 'ee/security_dashboard/components/agent/age ...@@ -4,10 +4,11 @@ import AgentVulnerabilityReport from 'ee/security_dashboard/components/agent/age
describe('Agent vulnerability report component', () => { describe('Agent vulnerability report component', () => {
let wrapper; let wrapper;
const propsData = { clusterAgentId: 'gid://gitlab/Clusters::Agent/1' };
const provide = { agentName: 'primary-agent', projectPath: '/path/to/project/' }; const provide = { agentName: 'primary-agent', projectPath: '/path/to/project/' };
const createWrapper = () => { const createWrapper = () => {
wrapper = shallowMount(AgentVulnerabilityReport, { provide }); wrapper = shallowMount(AgentVulnerabilityReport, { propsData, provide });
}; };
afterEach(() => { afterEach(() => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment