Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions nodes/DependencyAnalytics/Actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ describe('Tests for actions/advisory.ts', () => {
fakeCredential,
expect.objectContaining({
method: 'GET',
url: `${fakeBase}/advisory`,
qs: { limit: 2 },
url: `${fakeBase}/advisory?limit=2`,
returnFullResponse: false,
headers: defaultJsonHeaders,
}),
);
Expand Down Expand Up @@ -356,8 +356,8 @@ describe('Tests for actions/sbom.ts', () => {
fakeCredential,
expect.objectContaining({
method: 'GET',
url: `${fakeBase}/sbom`,
qs: { limit: 3 },
url: `${fakeBase}/sbom?limit=3`,
returnFullResponse: false,
headers: defaultJsonHeaders,
}),
);
Expand Down Expand Up @@ -463,8 +463,8 @@ describe('Tests for actions/vulnerability.ts', () => {
fakeCredential,
expect.objectContaining({
method: 'GET',
url: `${fakeBase}/vulnerability`,
qs: { limit: 2 },
url: `${fakeBase}/vulnerability?limit=2`,
returnFullResponse: false,
headers: defaultJsonHeaders,
}),
);
Expand Down
1 change: 1 addition & 0 deletions nodes/DependencyAnalytics/DependencyAnalytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test('It contains all expected displayNames in properties', () => {
'Sorting',
'Selected Fields',
'Selected Fields',
'Selected Fields',
'Operation',
'Input Type',
'PURLs',
Expand Down
24 changes: 12 additions & 12 deletions nodes/DependencyAnalytics/Utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ describe('Tests for simplify.ts', () => {
packages: 5,
size: 12345,
sha256: 'abc123',
describedBy: [
described_by: [
{
id: null,
name: 'desc name',
version: '1.0',
purl: [{ uuid: null, purl: 'pkg:example@1.0' }],
},
],
documentId: 'doc-1',
document_id: 'doc-1',
});
});

Expand All @@ -240,8 +240,8 @@ describe('Tests for simplify.ts', () => {
packages: null,
size: null,
sha256: null,
describedBy: null,
documentId: null,
described_by: null,
document_id: null,
});
});

Expand Down Expand Up @@ -365,7 +365,7 @@ describe('Tests for simplify.ts', () => {
expect(result).toHaveProperty('name', 'Test SBOM');
expect(result).toHaveProperty('version', '1.0.0');
expect(result).toHaveProperty('packages', 10);
expect((result as any)?.describedBy?.[0]?.purl?.[0]?.purl).toBe('pkg:npm/test@1.0.0');
expect((result as any)?.described_by?.[0]?.purl?.[0]?.purl).toBe('pkg:npm/test@1.0.0');
});

test('It should call simplifyVuln when resource is vulnerability', () => {
Expand Down Expand Up @@ -471,7 +471,7 @@ describe('Tests for parsePurls.ts', () => {
});

describe('Tests for http.ts', () => {
test('It should remove trailing slashes from baseURL', () => {
test('It should normalize baseURL and append /api/v2 when missing', () => {
const mockCtx = {
getNodeParameter: jest.fn().mockReturnValue('https://api.foobar.com///'),
};
Expand All @@ -481,15 +481,15 @@ describe('Tests for http.ts', () => {
0,
'https://rhtpa.stage.devshift.net/api/v2/',
);
expect(result).toBe('https://api.foobar.com');
expect(result).toBe('https://api.foobar.com/api/v2');
});

test('It should return unchanged URL if no trailing slash', () => {
test('It should avoid duplicating /api/v2 when already present', () => {
const mockCtx = {
getNodeParameter: jest.fn().mockReturnValue('https://api.foobar.com'),
getNodeParameter: jest.fn().mockReturnValue('https://api.foobar.com/api/v2/'),
};
const result = getBase(mockCtx as any, 1);
expect(result).toBe('https://api.foobar.com');
expect(result).toBe('https://api.foobar.com/api/v2');
});

test('It should return `trustifyClientCredsOAuth2Api`', () => {
Expand Down Expand Up @@ -577,15 +577,15 @@ describe('Tests for output.ts', () => {
packages: null,
size: null,
sha256: null,
describedBy: [
described_by: [
{
id: null,
name: 'inner',
version: '1.0',
purl: [{ uuid: null, purl: 'pkg:abc' }],
},
],
documentId: null,
document_id: null,
};
const ctx = {
getNodeParameter: jest.fn().mockReturnValue('simplified'),
Expand Down
7 changes: 3 additions & 4 deletions nodes/DependencyAnalytics/actions/advisory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export async function getMany({ ctx, itemIndex }: { ctx: IExecuteFunctions; item

const options: IHttpRequestOptions = {
method: 'GET',
url: `${base}/advisory`,
qs: { limit },
url: `${base}/advisory?limit=${limit}`,
returnFullResponse: false,
headers: defaultJsonHeaders,
};
Expand Down Expand Up @@ -305,8 +304,8 @@ export async function analyze({ ctx, itemIndex }: { ctx: IExecuteFunctions; item
? item.status.map((s: any) => ({
identifier: item?.identifier ?? null,
title: s?.title ?? null,
averageSeverity: s?.average_severity ?? null,
averageScore: s?.average_score ?? null,
average_severity: s?.average_severity ?? null,
average_score: s?.average_score ?? null,
status: s?.status ?? null,
packages: simplifyPackages(s?.packages),
score: toScores(item?.scores) ?? toScores(s?.scores),
Expand Down
3 changes: 1 addition & 2 deletions nodes/DependencyAnalytics/actions/sbom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export async function getMany({ ctx, itemIndex }: { ctx: IExecuteFunctions; item

const options: IHttpRequestOptions = {
method: 'GET',
url: `${base}/sbom`,
qs: { limit },
url: `${base}/sbom?limit=${limit}`,
returnFullResponse: false,
headers: defaultJsonHeaders,
};
Expand Down
3 changes: 1 addition & 2 deletions nodes/DependencyAnalytics/actions/vulnerability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export async function getMany({ ctx, itemIndex }: { ctx: IExecuteFunctions; item

const options: IHttpRequestOptions = {
method: 'GET',
url: `${base}/vulnerability`,
qs: { limit },
url: `${base}/vulnerability?limit=${limit}`,
returnFullResponse: false,
headers: defaultJsonHeaders,
};
Expand Down
33 changes: 31 additions & 2 deletions nodes/DependencyAnalytics/descriptions/advisory.properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ export const advisoryProperties: INodeProperties[] = [
},
},

{
displayName: 'Selected Fields',
name: 'advisorySelectedFields',
type: 'multiOptions',
default: [],
description: "Advisory fields to include when 'Selected Fields' output mode is selected",
options: [
{ name: 'Document ID', value: 'document_id' },
{ name: 'Identifier', value: 'identifier' },
{ name: 'Issuer', value: 'issuer' },
{ name: 'Issuer Name', value: 'issuer.name' },
{ name: 'Labels', value: 'labels' },
{ name: 'Modified', value: 'modified' },
{ name: 'Published', value: 'published' },
{ name: 'Released', value: 'released' },
{ name: 'Reserved', value: 'reserved' },
{ name: 'Status', value: 'status' },
{ name: 'Title', value: 'title' },
{ name: 'UUID', value: 'uuid' },
{ name: 'Withdrawn', value: 'withdrawn' },
],
displayOptions: {
show: {
resource: ['advisory'],
operation: ['analyze'],
inputType: ['sbomSha'],
outputMode: ['selected'],
},
},
},
{
displayName: 'Selected Fields',
name: 'advisorySelectedFields',
Expand All @@ -58,7 +88,6 @@ export const advisoryProperties: INodeProperties[] = [
{ name: 'Released', value: 'released' },
{ name: 'Reserved', value: 'reserved' },
{ name: 'Scores', value: 'scores' },
{ name: 'Size (Bytes)', value: 'size' },
{ name: 'Status', value: 'status' },
{ name: 'Title', value: 'title' },
{ name: 'UUID', value: 'uuid' },
Expand All @@ -68,7 +97,7 @@ export const advisoryProperties: INodeProperties[] = [
show: {
resource: ['advisory'],
operation: ['analyze'],
inputType: ['purls', 'sbomSha'],
inputType: ['purls'],
outputMode: ['selected'],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const vulnerabilityProperties: INodeProperties[] = [
description: "Fields to include when 'Selected Fields' output mode is selected",
options: [
{ name: 'Advisories', value: 'advisories' },
{ name: 'Average Score', value: 'average_score' },
{ name: 'Average Severity', value: 'average_severity' },
{ name: 'CWEs', value: 'cwes' },
{ name: 'Description', value: 'description' },
{ name: 'Identifier', value: 'identifier' },
Expand Down
4 changes: 3 additions & 1 deletion nodes/DependencyAnalytics/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export function getBase(ctx: IExecuteFunctions, itemIndex: number): string {
itemIndex,
'https://rhtpa.stage.devshift.net/api/v2/',
) as string;
return baseURLRaw.replace(/\/+$/, '');
const normalized = baseURLRaw.replace(/\/+$/, '');
const apiSuffix = '/api/v2';
return normalized.endsWith(apiSuffix) ? normalized : `${normalized}${apiSuffix}`;
}

export function chooseCredential(ctx: IExecuteFunctions, itemIndex: number): string {
Expand Down
4 changes: 0 additions & 4 deletions nodes/DependencyAnalytics/utils/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export function shapeOutput(ctx: IExecuteFunctions, i: number, resource: Resourc

// selected fields
let selected = readSelectedFields(ctx, i, resource);
// If selecting for advisory but no advisory fields configured, fall back to vulnerability selection
if (resource === 'advisory' && (!selected || selected.length === 0)) {
selected = readSelectedFields(ctx, i, 'vulnerability');
}
selected = ensureId(resource, selected);
const source = resource === 'sbom' ? deriveSbomFields(obj) : obj;
return project(source, selected);
Expand Down
6 changes: 3 additions & 3 deletions nodes/DependencyAnalytics/utils/simplify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function simplifySbom(item: SBOM) {
packages: item.number_of_packages ?? null,
size: item.size ?? null,
sha256: item.sha256 ?? null,
describedBy: simplifyDescribedBy(item?.described_by) ?? null,
documentId: item.document_id ?? null,
described_by: simplifyDescribedBy(item?.described_by) ?? null,
document_id: item.document_id ?? null,
};
}

Expand All @@ -53,7 +53,7 @@ export function simplifyVuln(item: Vuln) {
? a.sboms.map((sb: any) => ({
id: sb?.id ?? null,
labels: sb?.labels ?? null,
dataLicenses: sb?.data_licenses ?? null,
data_licenses: sb?.data_licenses ?? null,
}))
: null,
purls: {
Expand Down