Files
Heimdall/scripts/ci/renovate-preflight.test.mjs
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

37 lines
1.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { checkGiteaAccess, validateEndpoint } from './renovate-preflight.mjs';
test('accepts an HTTPS Gitea API endpoint and trims its trailing slash', () => {
assert.equal(validateEndpoint('https://forge.example/api/v1/'), 'https://forge.example/api/v1');
});
test('rejects non-HTTPS, malformed, and non-API endpoints', () => {
for (const value of ['http://forge.example/api/v1', 'https://forge.example/', 'not a URL']) {
assert.throws(() => validateEndpoint(value), /HTTPS URL ending in \/api\/v1/);
}
});
test('checks identity and repository reads without exposing the token', async () => {
const calls = [];
await checkGiteaAccess('https://forge.example/api/v1', 'secret-token', async (url, options) => {
calls.push({ url: url.href, authorization: options.headers.Authorization });
return { ok: true, status: 200 };
});
assert.deepEqual(calls.map(call => new URL(call.url).pathname), [
'/api/v1/user', '/api/v1/repos/arnaud.dartois/Heimdall',
]);
assert.ok(calls.every(call => call.authorization === 'token secret-token'));
});
test('reports authentication status without printing response details or credentials', async () => {
await assert.rejects(
checkGiteaAccess('https://forge.example/api/v1', 'secret-token', async () => ({
ok: false, status: 403,
})),
error => error.message.includes('HTTP 403') &&
error.message.includes('repository read and write access') &&
!error.message.includes('secret-token'),
);
});