Skip to content

Commit

Permalink
Merge pull request #3397 from CVEProject/tat-3394-cve-id
Browse files Browse the repository at this point in the history
#3394 show reserved CVE ID on Search Results page
  • Loading branch information
athu-tran authored Jan 3, 2025
2 parents c264b14 + 713717c commit e4bc271
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 19 deletions.
46 changes: 37 additions & 9 deletions src/stores/cveListSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
cveId: '',
from: 0,
isArecord: undefined,
isAnId: undefined,
isSeachButtonDisabled: true,
isIdOrRecordFound: true,
isPublished: false,
Expand All @@ -19,6 +20,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
isLookUpRecordServerError: false,
isSearchServerError: false,
query: '',
idData: {},
recordData: {},
searchResults: [],
searchType: true,
Expand Down Expand Up @@ -73,36 +75,40 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
this.isSearching = true;
try{

// * 2nd, query search service
// * query search service
this.totalExecutingRequests = 1;
await this.getSearchResults();

// * Check if keyword is CVE ID
if (this.isCveIdPattern()) {
this.totalExecutingRequests = 2;

// 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
// lookup ID to get Record data
this.cveId = this.query.toUpperCase();
await this.getRecordData();
await this.getRecordData();
}

} catch (error) {
throw new Error('search() >> error with getRecordData() and or getSearchResults()');
// if record is not found, find potential reserved ID
if (this.isCveIdPattern() && Object.keys(this.recordData).length === 0) {
await this.getIdData();
}

throw new Error('search() >> error with getSearchResults(), getRecordData(), or getIdData()');
} finally {
this.isSearching = false;
this.setUpInitialPagination();
}
},
async getRecordData() {
this.isLookingUpRecord = true;
const getRecordUrl = `/api/cve/${this.cveId}`;
const getRecordUrl = `${useGenericGlobalsStore().currentServicesUrl}/api/cve/${this.cveId}`;

try {
axios.defaults.baseURL = useGenericGlobalsStore().currentServicesUrl;
const response = await axios.get(getRecordUrl);
const cveRecordData = response?.data || {};
this.isArecord = true;
this.isIdOrRecordFound = false;
this.isIdOrRecordFound = true;

// format description
let descriptions = [];
Expand All @@ -124,20 +130,42 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
this.isRejected = true;
}

} catch (e) {
} catch (error) {
this.isLookUpRecordServerError = true;

this.isPublished = false;
this.isReserved = false;
this.isRejected = false;
this.isIdOrRecordFound = false;
this.isArecord = false;
throw new Error('getRecordData >> throwing wrroe')
throw new Error('getRecordData >> throwing error');
} finally {
this.isLookingUpRecord = false;
this.decrement('totalExecutingRequests');
}
},
async getIdData() {
const getIdUrl = `${useGenericGlobalsStore().currentServicesUrl}/api/cve-id/${this.cveId}`;
try {
const response = await axios.get(getIdUrl);
const idData = response || {};
this.isIdOrRecordFound = true;
this.isAnId = true;
if (idData.status === 200 && idData?.data?.error === undefined) {
this.idData = idData.data;
if (idData.state === 'RESERVED') {
this.isReserved = true;
this.isArecord = false;
} else if (this.$store.state.idData.state === 'REJECTED') {
this.isRejected = true;
this.isArecord = false;
}
}

} catch (error) {
throw new Error('getIdData >> throwing error');
}
},
async getSearchResults() {
this.isQueryingSearchService = true;
const searchUrl = `${import.meta.env.VITE_API_BASE_URL}${import.meta.env.VITE_LIST_SEARCH_PATH}`;
Expand Down
2 changes: 1 addition & 1 deletion src/views/CVERecord/CVERecord.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default {
const errorToStr = error.toString() || '';
if (!errorToStr.match(regex)) {
usecveRecordStore().isPublished = false;
usecveRecordStore().isReserved = false;
usecveRecordStore().isReserved = false; // only a cve-id can be in a 'reserved' state; this should always be false
usecveRecordStore().isRejected = false;
this.handleServerError();
}
Expand Down
49 changes: 40 additions & 9 deletions src/views/CVERecord/SearchResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,36 @@
<p>You are accessing <span class="has-text-weight-bold">Production</span> data from {{ resultUrl }}</p>
</div>
</div>
<div class="mb-3" v-if="Object.keys(cveListSearchStore.recordData).length > 0">
<h2 class="title">CVE Record Found</h2>
<div class="mb-3" v-if="hasRecordData || hasIdData">
<h2 class="title"> CVE {{ getRecordOrIdLabel }} Found</h2>
<p class="cve-help-text">
See the CVE Record below. If you are searching for this CVE ID in other CVE Records, view the Search Results section below.
<span v-if="hasRecordData">View the CVE {{ getRecordOrIdLabel }} below.</span>
<span v-if="hasIdData">
The <router-link to="/ResourcesSupport/Glossary#glossaryCVEID">CVE ID</router-link> below has no corresponding
<router-link to="/ResourcesSupport/Glossary#glossaryRecord">CVE Record</router-link>.
</span>
If you are searching for this CVE ID in other CVE Records, view the Search Results section below.
</p>
<div class="columns cve-columns is-variable is-1-desktop is-0-mobile mt-5 mr-2 mb-0 ml-2">
<div class="columns cve-columns is-variable is-1-desktop is-0-mobile mt-0 mr-2 mb-0 ml-2">
<div class="column cve-column">
<div class="columns cve-columns">
<div class="column cve-column">
<router-link :to="`/CVERecord?id=${cveListSearchStore.recordData.cveId}`" target="_blank">{{ cveListSearchStore.recordData.cveId }}</router-link>
<router-link v-if="hasRecordData"
:to="`/CVERecord?id=${cveListSearchStore.recordData.cveId}`" target="_blank">
{{ cveListSearchStore.recordData.cveId }}
</router-link>
<router-link v-if="hasIdData"
:to="`/CVERecord?id=${cveListSearchStore.idData.cve_id}`" target="_blank">
{{ cveListSearchStore.idData.cve_id}}
</router-link>
</div>
<div class="column cve-column">
<div class="column cve-column" v-if="hasRecordData">
<p>
<span>CNA: </span>
{{ partnerStore.partnerShortLongNameMap[cveListSearchStore.recordData.cnaOrgId] ? partnerStore.partnerShortLongNameMap[cveListSearchStore.recordData.cnaOrgId] : cveListSearchStore.recordData.cna }}</p>
</div>
</div>
<div class="columns cve-columns">
<div class="columns cve-columns" v-if="hasRecordData">
<div class="column cve-column">
<div v-for="(description, index) in cveListSearchStore.recordData.descriptions" :key="description.key" class="mb-0">
<p v-if="!description.showMore" class="mb-0">
Expand All @@ -73,7 +85,7 @@
</div>
<div id="cve-search-results-container" v-if="cveListSearchStore.totalSearchResultCount > 0">
<h2 class="title">Search Results</h2>
<p class="cve-help-text" v-if="Object.keys(cveListSearchStore.recordData).length > 0">
<p class="cve-help-text" v-if="hasRecordData || hasIdData">
Includes all record(s) that reference this CVE ID.
</p>
<div class="mt-4 mb-2">
Expand Down Expand Up @@ -123,7 +135,7 @@
</div>
</div>
</div>
<div v-if="Object.keys(cveListSearchStore.recordData).length > 0 || cveListSearchStore.totalSearchResultCount > 0">
<div v-if="cveListSearchStore.totalSearchResultCount > 0">
<div class="columns cve-columns" v-for="(result, resultIndex) in cveListSearchStore.searchResults" :key="result.index">
<div class="column cve-column">
<div class="column cve-column" :class="{'cve-top-border': resultIndex !== 0}">
Expand Down Expand Up @@ -282,6 +294,25 @@ function backToTop() {
const websiteEnv = computed(() => {
return import.meta.env.VITE_WEBSITE_ENVIRONMENT;
});
let getRecordOrIdLabel = computed(() => {
if (cveListSearchStore?.isArecord){
return 'Record';
} else if (Object.keys(cveListSearchStore.idData).length > 0) {
return 'ID';
} else {
return '';
}
});
let hasRecordData = computed(() => {
return Object.keys(cveListSearchStore.recordData).length > 0;
});
let hasIdData = computed(() => {
return Object.keys(cveListSearchStore.idData).length > 0;
});
</script>
<style lang="scss">
Expand Down

0 comments on commit e4bc271

Please sign in to comment.