Skip to content

Commit 99d5e80

Browse files
committed
cveRecordSearchModule: use legacy find for "CVERecord" URL in non-production websites
1 parent 3326b37 commit 99d5e80

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/components/cveRecordSearchModule.vue

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="mt-1">
3-
<div v-if="websiteEnv !== 'prd'" role="alert" class="notification is-warning is-light">
3+
<div v-if="!isProductionWebsite" role="alert" class="notification is-warning is-light">
44
<div class="is-flex is-align-items-flex-start mt-1" style="max-width: 820px; column-gap: 1rem;">
55
<div class="pl-3">
66
<p id="alertIconVariousFormts" class="is-hidden">alert</p>
@@ -18,10 +18,10 @@
1818
</div>
1919
<div class="field has-addons mt-1">
2020
<p class="control">
21-
<span v-if="websiteEnv !== 'prd'" class="select cve-search-selector">
21+
<span v-if="!isProductionWebsite" class="select cve-search-selector">
2222
<select v-model="searchType">
23-
<option>Search CVE List</option>
24-
<option>Find a Test CVE Record/ID (Legacy)</option>
23+
<option>{{ searchOptionLabel }}</option>
24+
<option>{{ legacyOptionLabel }}</option>
2525
</select>
2626
</span>
2727
</p>
@@ -65,6 +65,8 @@ import { useGenericGlobalsStore } from '@/stores/genericGlobals';
6565
const cveIdRegex = /^CVE\p{Pd}(?<year>\d{4})\p{Pd}(?<id>\d{4,})$/iu;
6666
const wordRegex = /^[a-z0-9 ]+$/i;
6767
68+
const isProductionWebsite = import.meta.env.VITE_WEBSITE_ENVIRONMENT === 'prd';
69+
6870
// This is the current maximum supported length of the "suffix" portion of
6971
// the CVE ID. The schema defines a suffix length up to 19, but code in
7072
// other modules only supports what's defined here.
@@ -75,20 +77,24 @@ let cveListSearchStore = useCveListSearchStore();
7577
const route = useRoute();
7678
const router = useRouter();
7779
80+
const cveRecordRouteName = 'CVERecord';
81+
const legacyOptionLabel = 'Find a Test CVE Record/ID (Legacy)';
82+
const searchOptionLabel = 'Search CVE List';
83+
7884
let prevSearchValue = ref('');
7985
let queryString = ref('');
8086
let errorMessage = ref('');
8187
8288
let cveGenericGlobalsStore = useGenericGlobalsStore();
8389
let cveRecordStore = usecveRecordStore();
84-
let searchType = ref('Search CVE List');
90+
let searchType = ref(searchOptionLabel);
8591
let cveId = cveRecordStore.cveId;
8692
8793
// this seems redundant, but it fixes an edge case. if a user searches for a
8894
// particular field, then on the results page flips the toggle, THEN refreshes
8995
// without searching, this will keep the correct helper text showing.
9096
let searchTypeBoolean = computed(() => {
91-
return searchType.value == 'Search CVE List' ? true : false;
97+
return searchType.value === searchOptionLabel ? true : false;
9298
});
9399
94100
watch(searchType, () => {
@@ -98,9 +104,21 @@ watch(searchType, () => {
98104
watch(
99105
() => route.query,
100106
() => {
101-
if (searchTypeBoolean.value && route.query?.query) {
102-
queryString.value = route.query.query.trim();
103-
validate();
107+
if (searchTypeBoolean.value) {
108+
109+
// We're currently in "normal" search mode. For non-production websites
110+
// (e.g., test), the "legacy" find is used when a CVEID is given in the
111+
// URL (i.e., the "cveRecordRouteName" route). This is significant if the
112+
// test website uses a different database (cveawg-test) for the legacy
113+
// find than the normal search (cveawg). In this case, we need to switch
114+
// the search type to "legacy". (issue #3426)
115+
116+
if (route?.name === cveRecordRouteName && !isProductionWebsite)
117+
searchType.value = legacyOptionLabel;
118+
else if (route.query?.query) {
119+
queryString.value = route.query.query.trim();
120+
validate();
121+
}
104122
}
105123
}
106124
)
@@ -283,10 +301,6 @@ function resetSearch() {
283301
if (route?.name != 'home' || route?.query)
284302
router.push({name: 'home', query: {}});
285303
}
286-
287-
const websiteEnv = computed(() => {
288-
return import.meta.env.VITE_WEBSITE_ENVIRONMENT;
289-
});
290304
</script>
291305
292306
<style scoped lang="scss">

0 commit comments

Comments
 (0)