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
9 changes: 2 additions & 7 deletions src/helpers/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,9 @@ export function packageYamlToJs(pkgYaml: string) {

export function packageIsVerified(slug: string, pkgVersion: PackageVersion) {
const org: string = slug.split('/')[0];
let verified: boolean = true;
pkgVersion.files.forEach(file => {
return pkgVersion.files.every(file => {
const url: string = file.url.toLowerCase();
const root: string = url.startsWith('https://github.com/') ? 'https://github.com/' + org + '/' : `https://${org}.`;
if (!url.startsWith(root)) {
verified = false;
return;
}
return url.startsWith(root);
});
return verified;
}
19 changes: 19 additions & 0 deletions tests/helpers/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from 'vitest';
import {
packageCompatibleFiles,
packageDownloadsTotal,
packageIsVerified,
packageRecommendations,
packageVersionLatest,
PackageVersionValidator,
Expand Down Expand Up @@ -138,6 +139,24 @@ test('Package compatible files returns empty when only unsupported formats exist
expect(excludedResult).toHaveLength(0);
});

test('Package is verified when every file url matches the org', () => {
expect(packageIsVerified('surge-synthesizer/surge', PLUGIN)).toEqual(true);
});

test('Package is not verified when any file url does not match the org', () => {
const pluginWithForeignFile: PackageVersion = {
...PLUGIN,
files: [
...PLUGIN.files,
{
...PLUGIN.files[0],
url: 'https://github.com/someone-else/unrelated/releases/download/1.0.0/file.deb',
},
],
};
expect(packageIsVerified('surge-synthesizer/surge', pluginWithForeignFile)).toEqual(false);
});

test('Package compatible files respects exclusions when alternatives exist', () => {
const bothFormatsPackage: PackageVersion = {
...PLUGIN,
Expand Down
Loading