CN-1063 fix: 单元测试--实体详情流量折线图和底下3个tab
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<!--初步方案:error提示替换table。后续若改为table内error提示,记得在此修改-->
|
<!--初步方案:error提示替换table。后续若改为table内error提示,记得在此修改-->
|
||||||
<chart-error v-if="showError" :content="errorMsg" class="entity-detail-event-error"></chart-error>
|
<chart-error v-if="showError" :content="errorMsg" class="entity-detail-event-error"></chart-error>
|
||||||
<chart-no-data v-if="isNoData && !showError"></chart-no-data>
|
<chart-no-data v-if="isNoData && !showError" test-id="no-data"></chart-no-data>
|
||||||
|
|
||||||
<div v-if="!isNoData && !showError" class="information-aggregation__table">
|
<div v-if="!isNoData && !showError" class="information-aggregation__table">
|
||||||
<el-table
|
<el-table
|
||||||
@@ -44,13 +44,13 @@
|
|||||||
<!-- <div class="information-aggregation-tags">
|
<!-- <div class="information-aggregation-tags">
|
||||||
<template v-for="ic in scope.row.intelligenceContent" >
|
<template v-for="ic in scope.row.intelligenceContent" >
|
||||||
<template v-if="ic.type === 0" >
|
<template v-if="ic.type === 0" >
|
||||||
<div v-if="ic.threatLevel === -1" class="entity-tag entity-tag--small entity-tag--level-one-negative margin-r-6">
|
<div v-if="ic.threatLevel === -1" class="entity-tag entity-tag--small entity-tag--level-one-negative margin-r-6">
|
||||||
{{ic.value}}
|
{{ic.value}}
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="ic.threatLevel === 0" class="entity-tag entity-tag--small entity-tag--level-one-normal margin-r-6">
|
<div v-else-if="ic.threatLevel === 0" class="entity-tag entity-tag--small entity-tag--level-one-normal margin-r-6">
|
||||||
{{ic.value}}
|
{{ic.value}}
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="ic.threatLevel === 1" class="entity-tag entity-tag--small entity-tag--level-one-positive margin-r-6">
|
<div v-else-if="ic.threatLevel === 1" class="entity-tag entity-tag--small entity-tag--level-one-positive margin-r-6">
|
||||||
{{ic.value}}
|
{{ic.value}}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<div class="information-aggregation-tags">
|
<div class="information-aggregation-tags">
|
||||||
<div v-for="ic in scope.row.intelligenceContent" :key="ic.key">
|
<div v-for="ic in scope.row.intelligenceContent" :key="ic.key">
|
||||||
<div>
|
<div>
|
||||||
<div class="entity-tag entity-tag--small margin-r-6" :class="`entity-tag--level-two-${ic.type}`">
|
<div class="entity-tag entity-tag--small margin-r-6" :test-id="`entity-tag${scope.$index}`" :class="`entity-tag--level-two-${ic.type}`">
|
||||||
{{ic.value}}
|
{{ic.value}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -75,10 +75,10 @@
|
|||||||
prop="status"
|
prop="status"
|
||||||
>
|
>
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<div v-if="scope.row.status === 1" class="information-aggregation__valid">
|
<div v-if="scope.row.status === 1" :test-id="`entity-status${scope.$index}`" class="information-aggregation__valid">
|
||||||
{{ $t("entity.detail.valid") }}
|
{{ $t("entity.detail.valid") }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="scope.row.status === 0" class="information-aggregation__invalid">
|
<div v-else-if="scope.row.status === 0" :test-id="`entity-status${scope.$index}`" class="information-aggregation__invalid">
|
||||||
{{ $t("entity.detail.invalid") }}
|
{{ $t("entity.detail.invalid") }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -107,7 +107,7 @@ export default {
|
|||||||
components: { chartNoData },
|
components: { chartNoData },
|
||||||
methods: {
|
methods: {
|
||||||
dateFormatByAppearance,
|
dateFormatByAppearance,
|
||||||
intelligenceContentClass ({ row, column, rowIndex, columnIndex }) {
|
intelligenceContentClass ({ columnIndex }) {
|
||||||
if (columnIndex === 2) {
|
if (columnIndex === 2) {
|
||||||
return 'padding-0'
|
return 'padding-0'
|
||||||
}
|
}
|
||||||
@@ -120,29 +120,31 @@ export default {
|
|||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
this.isNoData = res.data.result.length === 0
|
this.isNoData = res.data.result.length === 0
|
||||||
this.showError = false
|
this.showError = false
|
||||||
res.data.result.forEach(r => {
|
if (!this.isNoData) {
|
||||||
Object.keys(r).forEach(k => {
|
res.data.result.forEach(r => {
|
||||||
const aggregation = {
|
Object.keys(r).forEach(k => {
|
||||||
createTime: r[k].createTime,
|
const aggregation = {
|
||||||
updateTime: r[k].updateTime,
|
createTime: r[k].createTime,
|
||||||
status: r[k].isValid,
|
updateTime: r[k].updateTime,
|
||||||
intelligenceContent: []
|
status: r[k].isValid,
|
||||||
}
|
intelligenceContent: []
|
||||||
if (k === 'userDefinedTag') {
|
}
|
||||||
aggregation.intelligenceContent.push({ key: k, value: r[k].tagValue, type: 'normal' })
|
if (k === 'userDefinedTag') {
|
||||||
} else {
|
aggregation.intelligenceContent.push({ key: k, value: r[k].tagValue, type: 'normal' })
|
||||||
Object.keys(r[k]).forEach(k2 => {
|
} else {
|
||||||
const find = entityDetailTags[this.entity.entityType].find(t => t.name === k2)
|
Object.keys(r[k]).forEach(k2 => {
|
||||||
if (find) {
|
const find = entityDetailTags[this.entity.entityType].find(t => t.name === k2)
|
||||||
aggregation.intelligenceContent.push({ key: k2, value: r[k][k2], type: find.type })
|
if (find) {
|
||||||
}
|
aggregation.intelligenceContent.push({ key: k2, value: r[k][k2], type: find.type })
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
if (aggregation.intelligenceContent.length > 0) {
|
}
|
||||||
this.informationAggregationList.push(aggregation)
|
if (aggregation.intelligenceContent.length > 0) {
|
||||||
}
|
this.informationAggregationList.push(aggregation)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
} else {
|
} else {
|
||||||
this.showError = true
|
this.showError = true
|
||||||
this.isNoData = false
|
this.isNoData = false
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div v-if="!isNoData && !showError" class="entity-detail-event-block">
|
<div v-if="!isNoData && !showError" class="entity-detail-event-block">
|
||||||
<div
|
<div
|
||||||
class="entity-detail-event-border"
|
class="entity-detail-event-border"
|
||||||
v-for="item in eventList"
|
v-for="(item, index) in eventList"
|
||||||
:key="item.eventId">
|
:key="item.eventId">
|
||||||
<div class="cn-detection--list">
|
<div class="cn-detection--list">
|
||||||
<div class="cn-detection__case entity-detail-performance">
|
<div class="cn-detection__case entity-detail-performance">
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
<div class="cn-detection__row">
|
<div class="cn-detection__row">
|
||||||
<div class="cn-detection__header">
|
<div class="cn-detection__header">
|
||||||
<span
|
<span
|
||||||
|
:test-id="`severity-color-block${index}`"
|
||||||
class="detection-event-severity-color-block"
|
class="detection-event-severity-color-block"
|
||||||
:style="`background-color: ${eventSeverityColor[item.eventSeverity]}`">
|
:style="`background-color: ${eventSeverityColor[item.eventSeverity]}`">
|
||||||
</span>
|
</span>
|
||||||
@@ -25,17 +26,17 @@
|
|||||||
<div class="basic-info__item" v-if="item.eventSeverity">
|
<div class="basic-info__item" v-if="item.eventSeverity">
|
||||||
<i class="cn-icon cn-icon-severity-level"></i>
|
<i class="cn-icon cn-icon-severity-level"></i>
|
||||||
<span>{{ $t('network.severity') }} : </span>
|
<span>{{ $t('network.severity') }} : </span>
|
||||||
<span>{{ toUpperCaseByString(item.eventSeverity) || '-' }}</span>
|
<span :test-id="`severity${index}`">{{ toUpperCaseByString(item.eventSeverity) || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="basic-info__item">
|
<div class="basic-info__item">
|
||||||
<i class="cn-icon cn-icon-time2"></i>
|
<i class="cn-icon cn-icon-time2"></i>
|
||||||
<span>{{ $t('detection.list.startTime') }} : </span>
|
<span>{{ $t('detection.list.startTime') }} : </span>
|
||||||
<span>{{ dateFormatByAppearance(item.startTime) || '-' }}</span>
|
<span :test-id="`start-time${index}`">{{ dateFormatByAppearance(item.startTime) || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="basic-info__item">
|
<div class="basic-info__item">
|
||||||
<i class="cn-icon cn-icon-duration"></i>
|
<i class="cn-icon cn-icon-duration"></i>
|
||||||
<span>{{ $t('overall.duration') }} : </span>
|
<span>{{ $t('overall.duration') }} : </span>
|
||||||
<span>{{ unitConvert(item.durationMs, 'time', null, null, 0).join(' ') || '-' }}</span>
|
<span :test-id="`duration-time${index}`">{{ unitConvert(item.durationMs, 'time', null, null, 0).join(' ') || '-' }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
<template>
|
<template>
|
||||||
<chart-error v-if="showError" :content="errorMsg" class="entity-detail-event-error"></chart-error>
|
<chart-error v-if="showError" :content="errorMsg" class="entity-detail-event-error"></chart-error>
|
||||||
<chart-no-data v-if="isNoData && !showError"></chart-no-data>
|
<chart-no-data v-if="isNoData && !showError" test-id="no-data"></chart-no-data>
|
||||||
|
|
||||||
<div v-if="!isNoData && !showError" class="entity-detail-event-block">
|
<div v-if="!isNoData && !showError" class="entity-detail-event-block">
|
||||||
<div
|
<div
|
||||||
class="entity-detail-event-border"
|
class="entity-detail-event-border"
|
||||||
v-for="item in eventList"
|
v-for="(item, index) in eventList"
|
||||||
:key="item.eventId">
|
:key="item.eventId">
|
||||||
<div class="cn-detection--list">
|
<div class="cn-detection--list">
|
||||||
<div class="cn-detection__case entity-detail-security">
|
<div class="cn-detection__case entity-detail-security">
|
||||||
<div class="cn-detection__icon" :style="`background-color: ${eventSeverityColor[item.eventSecurity]}`"></div>
|
<div class="cn-detection__icon" :style="`background-color: ${eventSeverityColor[item.eventSecurity]}`"></div>
|
||||||
<div class="cn-detection__row">
|
<div class="cn-detection__row">
|
||||||
<div class="cn-detection__header">
|
<div class="cn-detection__header">
|
||||||
<span
|
<span
|
||||||
class="detection-event-severity-color-block"
|
:test-id="`severity-color-block${index}`"
|
||||||
:style="`background-color: ${eventSeverityColor[item.eventSeverity]}`">
|
class="detection-event-severity-color-block"
|
||||||
</span>
|
:style="`background-color: ${eventSeverityColor[item.eventSeverity]}`">
|
||||||
|
</span>
|
||||||
<span class="detection-event-severity-block">{{ toUpperCaseByString(item.securityType) || '-' }}</span>
|
<span class="detection-event-severity-block">{{ toUpperCaseByString(item.securityType) || '-' }}</span>
|
||||||
<i class="cn-icon cn-icon-attacker"></i>{{ item.offenderIp || '-' }}
|
<i class="cn-icon cn-icon-attacker"></i>
|
||||||
|
<span :test-id="`offender-ip${index}`">{{ item.offenderIp || '-' }}</span>
|
||||||
<div class="domain">{{ item.offenderDomain }}</div>
|
<div class="domain">{{ item.offenderDomain }}</div>
|
||||||
<span class="line">-------</span>
|
<span class="line">-------</span>
|
||||||
<span class="circle"></span>
|
<span class="circle"></span>
|
||||||
<i class="cn-icon cn-icon-attacked"></i>{{ item.victimIp || '-' }}
|
<i class="cn-icon cn-icon-attacked"></i>
|
||||||
|
<span :test-id="`victim-ip${index}`">{{ item.victimIp || '-' }}</span>
|
||||||
<div class="domain">{{ item.victimDomain }}</div>
|
<div class="domain">{{ item.victimDomain }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="cn-detection__body">
|
<div class="cn-detection__body">
|
||||||
@@ -73,7 +76,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getSecond } from '@/utils/date-util'
|
import { getSecond, dateFormatByAppearance } from '@/utils/date-util'
|
||||||
import { eventSeverityColor } from '@/utils/constants'
|
import { eventSeverityColor } from '@/utils/constants'
|
||||||
import unitConvert from '@/utils/unit-convert'
|
import unitConvert from '@/utils/unit-convert'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
@@ -111,6 +114,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
unitConvert,
|
unitConvert,
|
||||||
toUpperCaseByString,
|
toUpperCaseByString,
|
||||||
|
dateFormatByAppearance,
|
||||||
initData () {
|
initData () {
|
||||||
const params = {
|
const params = {
|
||||||
resource: this.entityName,
|
resource: this.entityName,
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import InformationAggregation from '@/views/charts2/charts/entityDetail/tabs/InformationAggregation'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import axios from 'axios'
|
||||||
|
import mockData from './mockData/InformationAggregation'
|
||||||
|
import ElementPlus from '_element-plus@1.0.2-beta.71@element-plus'
|
||||||
|
|
||||||
|
let wrapper = null
|
||||||
|
const mockGet = mockData.common
|
||||||
|
|
||||||
|
const timeFilter = {
|
||||||
|
dateRangeValue: -1,
|
||||||
|
startTime: 1673244000000,
|
||||||
|
endTime: 1673247600000
|
||||||
|
}
|
||||||
|
const entity = {
|
||||||
|
entityType: 'ip',
|
||||||
|
entityName: '153.99.250.123'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进行axios请求,并挂载vue实例
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
function axiosPostAndMounted (data) {
|
||||||
|
require('vue-router').useRoute.mockReturnValue({ query: {} })
|
||||||
|
const _data = data || mockGet
|
||||||
|
// 模拟 axios 数据
|
||||||
|
axios.get.mockResolvedValue(_data)
|
||||||
|
|
||||||
|
// 加载vue组件,获得实例
|
||||||
|
wrapper = mount(InformationAggregation, {
|
||||||
|
global: {
|
||||||
|
plugins: [ElementPlus]
|
||||||
|
},
|
||||||
|
propsData: {
|
||||||
|
entity,
|
||||||
|
timeFilter
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('views/charts2/charts/entityDetail/tabs/InformationAggregation.vue测试', () => {
|
||||||
|
test('实体详情tabs-情报聚合:表格信息验证(情报内容列)', async () => {
|
||||||
|
axiosPostAndMounted()
|
||||||
|
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const textNode0 = await wrapper.find('[test-id="entity-tag0"]')
|
||||||
|
const textNode1 = await wrapper.find('[test-id="entity-tag1"]')
|
||||||
|
const textNode2 = await wrapper.find('[test-id="entity-tag2"]')
|
||||||
|
const textNode3 = await wrapper.find('[test-id="entity-tag3"]')
|
||||||
|
const textNode4 = await wrapper.find('[test-id="entity-tag4"]')
|
||||||
|
|
||||||
|
expect(textNode0.classes()).toContain('entity-tag--level-two-normal')
|
||||||
|
expect(textNode1.classes()).toContain('entity-tag--level-two-negative')
|
||||||
|
expect(textNode2.classes()).toContain('entity-tag--level-two-negative')
|
||||||
|
expect(textNode3.classes()).toContain('entity-tag--level-two-normal')
|
||||||
|
expect(textNode4.classes()).toContain('entity-tag--level-two-normal')
|
||||||
|
|
||||||
|
expect(textNode0.text()).toEqual('dba Omsoft')
|
||||||
|
expect(textNode1.text()).toEqual('IcedID')
|
||||||
|
expect(textNode2.text()).toEqual('i2p')
|
||||||
|
expect(textNode3.text()).toEqual('门户网站')
|
||||||
|
expect(textNode4.text()).toEqual('用户tag')
|
||||||
|
resolve()
|
||||||
|
}, 400))
|
||||||
|
})
|
||||||
|
test('实体详情tabs-情报聚合:表格信息验证(状态列)', async () => {
|
||||||
|
axiosPostAndMounted()
|
||||||
|
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const textNode0 = await wrapper.get('[test-id="entity-status0"]')
|
||||||
|
const textNode1 = await wrapper.get('[test-id="entity-status1"]')
|
||||||
|
const textNode2 = await wrapper.get('[test-id="entity-status2"]')
|
||||||
|
const textNode3 = await wrapper.get('[test-id="entity-status3"]')
|
||||||
|
const textNode4 = await wrapper.get('[test-id="entity-status4"]')
|
||||||
|
|
||||||
|
expect(textNode0.text()).toEqual('entity.detail.valid')
|
||||||
|
expect(textNode1.text()).toEqual('entity.detail.valid')
|
||||||
|
expect(textNode2.text()).toEqual('entity.detail.valid')
|
||||||
|
expect(textNode3.text()).toEqual('entity.detail.valid')
|
||||||
|
expect(textNode4.text()).toEqual('entity.detail.valid')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
test('实体详情tabs-安全事件:请求无数据', async () => {
|
||||||
|
axiosPostAndMounted(mockData.empty)
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const noData = wrapper.get('[test-id="no-data"]')
|
||||||
|
expect(noData.text()).toBe('npm.noData')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
})
|
||||||
96
test/views/charts2/charts/entityDetail/PerformanceEvent.js
Normal file
96
test/views/charts2/charts/entityDetail/PerformanceEvent.js
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import PerformanceEvent from '@/views/charts2/charts/entityDetail/tabs/PerformanceEvent'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import axios from 'axios'
|
||||||
|
import mockData from './mockData/PerformanceEvent'
|
||||||
|
|
||||||
|
const timeFilter = {
|
||||||
|
dateRangeValue: -1,
|
||||||
|
startTime: 1673244000000,
|
||||||
|
endTime: 1673247600000
|
||||||
|
}
|
||||||
|
const entity = {
|
||||||
|
entityType: 'ip',
|
||||||
|
entityName: '153.99.250.123'
|
||||||
|
}
|
||||||
|
|
||||||
|
function init (query) {
|
||||||
|
require('vue-router').useRoute.mockReturnValue({ query: query || {} })
|
||||||
|
}
|
||||||
|
function getRgb (str) {
|
||||||
|
return str.substring(str.indexOf('rgb'), str.indexOf(';'))
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('views/charts2/charts/entityDetail/tabs/PerformanceEvent.vue测试', () => {
|
||||||
|
test('实体详情tabs-性能事件:信息展示', async () => {
|
||||||
|
init()
|
||||||
|
axios.get.mockResolvedValue(mockData.common)
|
||||||
|
const wrapper = mount(PerformanceEvent, {
|
||||||
|
propsData: {
|
||||||
|
entity,
|
||||||
|
timeFilter
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const textNode0 = await wrapper.get('[test-id="severity-color-block0"]')
|
||||||
|
const textNode1 = await wrapper.get('[test-id="severity-color-block1"]')
|
||||||
|
|
||||||
|
expect(getRgb(textNode0.html())).toEqual('rgb(216, 76, 76)')
|
||||||
|
expect(getRgb(textNode1.html())).toEqual('rgb(255, 216, 45)')
|
||||||
|
|
||||||
|
const severity0 = await wrapper.get('[test-id="severity0"]')
|
||||||
|
const severity1 = await wrapper.get('[test-id="severity1"]')
|
||||||
|
|
||||||
|
expect(severity0.text()).toEqual('critical')
|
||||||
|
expect(severity1.text()).toEqual('info')
|
||||||
|
|
||||||
|
const startTime0 = await wrapper.get('[test-id="start-time0"]')
|
||||||
|
const startTime1 = await wrapper.get('[test-id="start-time1"]')
|
||||||
|
|
||||||
|
expect(startTime0.text()).toEqual('2023-06-07 10:16:16')
|
||||||
|
expect(startTime1.text()).toEqual('2023-06-07 10:16:16')
|
||||||
|
|
||||||
|
const duration0 = await wrapper.get('[test-id="duration-time0"]')
|
||||||
|
const duration1 = await wrapper.get('[test-id="duration-time1"]')
|
||||||
|
|
||||||
|
expect(duration0.text()).toEqual('15 m')
|
||||||
|
expect(duration1.text()).toEqual('15 m')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
test('实体详情tabs-性能事件:持续时间过小或过大,单位转换', async () => {
|
||||||
|
init()
|
||||||
|
axios.get.mockResolvedValue(mockData.empty)
|
||||||
|
const wrapper = mount(PerformanceEvent, {
|
||||||
|
propsData: {
|
||||||
|
entity,
|
||||||
|
timeFilter
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const duration0 = await wrapper.get('[test-id="duration-time0"]')
|
||||||
|
const duration1 = await wrapper.get('[test-id="duration-time1"]')
|
||||||
|
|
||||||
|
expect(duration0.text()).toEqual('900 ms')
|
||||||
|
expect(duration1.text()).toEqual('104167 d')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
test('实体详情tabs-性能事件:请求无数据', async () => {
|
||||||
|
init()
|
||||||
|
axios.get.mockResolvedValue(mockData.empty)
|
||||||
|
const wrapper = mount(PerformanceEvent, {
|
||||||
|
propsData: {
|
||||||
|
entity,
|
||||||
|
timeFilter
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const noData = wrapper.get('[test-id="no-data"]')
|
||||||
|
expect(noData.text()).toBe('npm.noData')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
})
|
||||||
75
test/views/charts2/charts/entityDetail/SecurityEvent.test.js
Normal file
75
test/views/charts2/charts/entityDetail/SecurityEvent.test.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import SecurityEvent from '@/views/charts2/charts/entityDetail/tabs/SecurityEvent'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import axios from 'axios'
|
||||||
|
import mockData from './mockData/SecurityEvent'
|
||||||
|
|
||||||
|
const timeFilter = {
|
||||||
|
dateRangeValue: -1,
|
||||||
|
startTime: 1673244000000,
|
||||||
|
endTime: 1673247600000
|
||||||
|
}
|
||||||
|
const entity = {
|
||||||
|
entityType: 'ip',
|
||||||
|
entityName: '153.99.250.123'
|
||||||
|
}
|
||||||
|
|
||||||
|
function init (query) {
|
||||||
|
require('vue-router').useRoute.mockReturnValue({ query: query || {} })
|
||||||
|
}
|
||||||
|
function getRgb (str) {
|
||||||
|
return str.substring(str.indexOf('rgb'), str.indexOf(';'))
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('views/charts2/charts/entityDetail/tabs/SecurityEvent.vue测试', () => {
|
||||||
|
test('实体详情tabs-安全事件:信息展示,severity严重程度与色块验证', async () => {
|
||||||
|
init()
|
||||||
|
axios.get.mockResolvedValue(mockData.common)
|
||||||
|
const wrapper = mount(SecurityEvent, {
|
||||||
|
propsData: {
|
||||||
|
entity,
|
||||||
|
timeFilter
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const textNode0 = await wrapper.get('[test-id="severity-color-block0"]')
|
||||||
|
const textNode1 = await wrapper.get('[test-id="severity-color-block1"]')
|
||||||
|
const textNode2 = await wrapper.get('[test-id="severity-color-block2"]')
|
||||||
|
|
||||||
|
expect(getRgb(textNode0.html())).toEqual('rgb(216, 76, 76)')
|
||||||
|
expect(getRgb(textNode1.html())).toEqual('rgb(255, 216, 45)')
|
||||||
|
expect(getRgb(textNode2.html())).toEqual('rgb(255, 216, 45)')
|
||||||
|
|
||||||
|
const offenderIp1 = await wrapper.get('[test-id="offender-ip0"]')
|
||||||
|
const offenderIp2 = await wrapper.get('[test-id="offender-ip1"]')
|
||||||
|
const offenderIp3 = await wrapper.get('[test-id="offender-ip2"]')
|
||||||
|
const victimIp1 = await wrapper.get('[test-id="victim-ip0"]')
|
||||||
|
const victimIp2 = await wrapper.get('[test-id="victim-ip1"]')
|
||||||
|
const victimIp3 = await wrapper.get('[test-id="victim-ip2"]')
|
||||||
|
|
||||||
|
expect(offenderIp1.text()).toEqual('213.186.33.5')
|
||||||
|
expect(offenderIp2.text()).toEqual('213.186.33.5')
|
||||||
|
expect(offenderIp3.text()).toEqual('213.186.33.5')
|
||||||
|
expect(victimIp1.text()).toEqual('116.178.217.92')
|
||||||
|
expect(victimIp2.text()).toEqual('116.178.217.93')
|
||||||
|
expect(victimIp3.text()).toEqual('116.178.217.93')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
test('实体详情tabs-安全事件:请求无数据', async () => {
|
||||||
|
init()
|
||||||
|
axios.get.mockResolvedValue(mockData.empty)
|
||||||
|
const wrapper = mount(SecurityEvent, {
|
||||||
|
propsData: {
|
||||||
|
entity,
|
||||||
|
timeFilter
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 延迟等待渲染。使用wrapper.vm.$nextTick有时不管用(例如组件中使用了setTimeout的时候)
|
||||||
|
await new Promise(resolve => setTimeout(async () => {
|
||||||
|
const noData = wrapper.get('[test-id="no-data"]')
|
||||||
|
expect(noData.text()).toBe('npm.noData')
|
||||||
|
resolve()
|
||||||
|
}, 200))
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
const mockData = {
|
||||||
|
// 空
|
||||||
|
empty: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bytes: {
|
||||||
|
// 边界
|
||||||
|
boundary: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: []
|
||||||
|
},
|
||||||
|
msg: 'OK'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 正常数据
|
||||||
|
common: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
location: {
|
||||||
|
isp: 'dba Omsoft',
|
||||||
|
updateTime: 1685696510,
|
||||||
|
createTime: 1685696510,
|
||||||
|
isValid: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
malware: {
|
||||||
|
threatType: 'command and control',
|
||||||
|
malwareName: 'IcedID',
|
||||||
|
malwareAlias: 'BokBot,IceID',
|
||||||
|
updateTime: 1685696510,
|
||||||
|
createTime: 1685696510,
|
||||||
|
isValid: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
darkweb: {
|
||||||
|
nodeType: 'i2p',
|
||||||
|
updateTime: 1685696510,
|
||||||
|
createTime: 1685696510,
|
||||||
|
isValid: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userDefinedTag: {
|
||||||
|
id: 1,
|
||||||
|
tagValue: '门户网站',
|
||||||
|
updateTime: 1685696500,
|
||||||
|
createTime: 1685696500,
|
||||||
|
isValid: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userDefinedTag: {
|
||||||
|
id: 1,
|
||||||
|
tagValue: '用户tag',
|
||||||
|
updateTime: 1685696500,
|
||||||
|
createTime: 1685696500,
|
||||||
|
isValid: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
msg: 'OK'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mockData
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
const mockData = {
|
||||||
|
// 空
|
||||||
|
empty: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bytes: {
|
||||||
|
// 边界
|
||||||
|
boundary: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
eventId: '1308078720390412288',
|
||||||
|
entityType: 'ip',
|
||||||
|
serverIp: '116.178.78.180',
|
||||||
|
domain: null,
|
||||||
|
appName: null,
|
||||||
|
eventSeverity: 'critical',
|
||||||
|
eventType: 'Http error',
|
||||||
|
startTime: 1686100507,
|
||||||
|
durationMs: 900,
|
||||||
|
endTime: 1686104107
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eventId: '1308078720390412289',
|
||||||
|
entityType: 'ip',
|
||||||
|
serverIp: '116.178.78.180',
|
||||||
|
domain: null,
|
||||||
|
appName: null,
|
||||||
|
eventSeverity: 'info',
|
||||||
|
eventType: 'Http error',
|
||||||
|
startTime: 1686100507,
|
||||||
|
durationMs: 9000000000000,
|
||||||
|
endTime: 1686104107
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
msg: 'OK'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 正常数据
|
||||||
|
common: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
eventId: '1308078720390412288',
|
||||||
|
entityType: 'ip',
|
||||||
|
serverIp: '116.178.78.180',
|
||||||
|
domain: null,
|
||||||
|
appName: null,
|
||||||
|
eventSeverity: 'critical',
|
||||||
|
eventType: 'Http error',
|
||||||
|
startTime: 1686100507,
|
||||||
|
durationMs: 900000,
|
||||||
|
endTime: 1686104107
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eventId: '1308078720390412289',
|
||||||
|
entityType: 'ip',
|
||||||
|
serverIp: '116.178.78.180',
|
||||||
|
domain: null,
|
||||||
|
appName: null,
|
||||||
|
eventSeverity: 'info',
|
||||||
|
eventType: 'Http error',
|
||||||
|
startTime: 1686100507,
|
||||||
|
durationMs: 900000,
|
||||||
|
endTime: 1686104107
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
msg: 'OK'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mockData
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
const mockData = {
|
||||||
|
// 空
|
||||||
|
empty: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bytes: {
|
||||||
|
// 边界
|
||||||
|
boundary: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: []
|
||||||
|
},
|
||||||
|
msg: 'OK'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 正常数据
|
||||||
|
common: {
|
||||||
|
data: {
|
||||||
|
status: 200,
|
||||||
|
code: 200,
|
||||||
|
data: {
|
||||||
|
resultType: 'object',
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
eventId: '1298414830886991872',
|
||||||
|
securityType: 'command and control',
|
||||||
|
domain: null,
|
||||||
|
offenderIp: '213.186.33.5',
|
||||||
|
victimIp: '116.178.217.92',
|
||||||
|
offenderDomain: 'baidu.com',
|
||||||
|
victimDomain: 'mi.com',
|
||||||
|
eventSeverity: 'critical',
|
||||||
|
malwareName: 'NetWire RC',
|
||||||
|
cryptominingPool: null,
|
||||||
|
startTime: 1683186600,
|
||||||
|
durationMs: 300000,
|
||||||
|
endTime: 1683186900
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eventId: '1298414830886991873',
|
||||||
|
securityType: 'command and control',
|
||||||
|
domain: null,
|
||||||
|
offenderIp: '213.186.33.5',
|
||||||
|
victimIp: '116.178.217.93',
|
||||||
|
offenderDomain: 'baidu.com',
|
||||||
|
victimDomain: 'mi.com',
|
||||||
|
eventSeverity: 'low',
|
||||||
|
malwareName: 'NetWire RC',
|
||||||
|
cryptominingPool: null,
|
||||||
|
startTime: 1683186600,
|
||||||
|
durationMs: 300000,
|
||||||
|
endTime: 1683186900
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eventId: '1298414830886991873',
|
||||||
|
securityType: 'command and control',
|
||||||
|
domain: null,
|
||||||
|
offenderIp: '213.186.33.5',
|
||||||
|
victimIp: '116.178.217.93',
|
||||||
|
offenderDomain: 'baidu.com',
|
||||||
|
victimDomain: 'mi.com',
|
||||||
|
eventSeverity: 'low',
|
||||||
|
malwareName: 'NetWire RC',
|
||||||
|
cryptominingPool: null,
|
||||||
|
startTime: 1683186600,
|
||||||
|
durationMs: 300000,
|
||||||
|
endTime: 1683186900
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
msg: 'OK'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mockData
|
||||||
Reference in New Issue
Block a user