mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
fix(ui): load package details from the single-package endpoint
The details page filtered the grouped package list to find its row. It
now requests /api/packages/{registry}/{name}/{version}, which also
resolves Go modules and PyPI release versions.
This commit is contained in:
@@ -190,15 +190,13 @@ async function load() {
|
|||||||
report.value = null
|
report.value = null
|
||||||
try {
|
try {
|
||||||
const encoded = `${registry.value}/${packageName.value}/${version.value}`
|
const encoded = `${registry.value}/${packageName.value}/${version.value}`
|
||||||
const [details, list] = await Promise.all([
|
const [details, single] = await Promise.all([
|
||||||
axios.get<PackageReport>(`/api/packages/${encoded}/vulnerabilities`),
|
axios.get<PackageReport>(`/api/packages/${encoded}/vulnerabilities`),
|
||||||
axios
|
axios.get<Package>(`/api/packages/${encoded}`).catch(() => null),
|
||||||
.get<{ packages: Package[] }>(`/api/packages?registry=${encodeURIComponent(registry.value)}&q=${encodeURIComponent(packageName.value)}`)
|
|
||||||
.catch(() => null),
|
|
||||||
system.load(),
|
system.load(),
|
||||||
])
|
])
|
||||||
report.value = details.data
|
report.value = details.data
|
||||||
row.value = list?.data.packages?.find((p) => p.name === packageName.value && p.version === version.value) ?? null
|
row.value = single?.data ?? null
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const e = err as { response?: { data?: { error?: string } }; message?: string }
|
const e = err as { response?: { data?: { error?: string } }; message?: string }
|
||||||
error.value = e.response?.data?.error || e.message || 'Failed to load package details'
|
error.value = e.response?.data?.error || e.message || 'Failed to load package details'
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ function respond(url: string) {
|
|||||||
if (url.endsWith('/vulnerabilities')) return { data: VULNERABILITY_REPORT }
|
if (url.endsWith('/vulnerabilities')) return { data: VULNERABILITY_REPORT }
|
||||||
if (url.startsWith('/api/admin/bypasses')) return { data: { bypasses: BYPASSES } }
|
if (url.startsWith('/api/admin/bypasses')) return { data: { bypasses: BYPASSES } }
|
||||||
if (url.includes('layout=rows')) return { data: serveRows(url, PACKAGES) }
|
if (url.includes('layout=rows')) return { data: serveRows(url, PACKAGES) }
|
||||||
|
const single = /^\/api\/packages\/([^/]+)\/(.+)\/([^/?]+)$/.exec(url)
|
||||||
|
if (single) {
|
||||||
|
const row = PACKAGES.find((p) => p.registry === single[1] && p.name === single[2] && p.version === single[3])
|
||||||
|
if (!row) throw Object.assign(new Error('not found'), { response: { status: 404 } })
|
||||||
|
return { data: row }
|
||||||
|
}
|
||||||
if (url.startsWith('/api/packages')) return { data: { packages: PACKAGES } }
|
if (url.startsWith('/api/packages')) return { data: { packages: PACKAGES } }
|
||||||
throw new Error(`unexpected request: ${url}`)
|
throw new Error(`unexpected request: ${url}`)
|
||||||
}
|
}
|
||||||
@@ -161,6 +167,15 @@ describe('view smoke tests (strict mode throw, fixture data)', () => {
|
|||||||
expect(wrapper.text()).toContain('No fix available')
|
expect(wrapper.text()).toContain('No fix available')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('PackageDetails reads its own row, not the grouped package list', async () => {
|
||||||
|
const { wrapper, problems } = await smoke(PackageDetails, '/package/npm/left-pad/1.3.0')
|
||||||
|
expect(problems).toEqual([])
|
||||||
|
const urls = vi.mocked(axios.get).mock.calls.map((c) => String(c[0]))
|
||||||
|
expect(urls).toContain('/api/packages/npm/left-pad/1.3.0')
|
||||||
|
expect(urls.filter((u) => u.startsWith('/api/packages?'))).toEqual([])
|
||||||
|
expect(wrapper.text()).toContain('2 KB')
|
||||||
|
})
|
||||||
|
|
||||||
it('PackageDetails Inspectors tab shows one row per scanner', async () => {
|
it('PackageDetails Inspectors tab shows one row per scanner', async () => {
|
||||||
const { wrapper, problems } = await smoke(PackageDetails, '/package/npm/left-pad/1.3.0?tab=inspectors')
|
const { wrapper, problems } = await smoke(PackageDetails, '/package/npm/left-pad/1.3.0?tab=inspectors')
|
||||||
const router = (wrapper.vm as unknown as { $router: Awaited<ReturnType<typeof createTestRouter>> }).$router
|
const router = (wrapper.vm as unknown as { $router: Awaited<ReturnType<typeof createTestRouter>> }).$router
|
||||||
@@ -381,6 +396,7 @@ describe('PyPI rows show the release version, not the file name', () => {
|
|||||||
return { data: { ...VULNERABILITY_REPORT, package: { release_version: '1.17.0' } } } as never
|
return { data: { ...VULNERABILITY_REPORT, package: { release_version: '1.17.0' } } } as never
|
||||||
}
|
}
|
||||||
if (url.includes('layout=rows')) return { data: serveRows(url, [SIX as never]) } as never
|
if (url.includes('layout=rows')) return { data: serveRows(url, [SIX as never]) } as never
|
||||||
|
if (url === `/api/packages/pypi/six/${FILE}`) return { data: SIX } as never
|
||||||
if (url.startsWith('/api/packages')) return { data: { packages: [SIX] } } as never
|
if (url.startsWith('/api/packages')) return { data: { packages: [SIX] } } as never
|
||||||
return respond(url) as never
|
return respond(url) as never
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user