Files
renovate/lib/modules/manager/bundler/host-rules.spec.ts
Sebastian Poxhofer 4add67e86e test: add linter for as any in test files (#44658)
* ci(linter): add prefer-partial-in-specs oxlint rule

Flags object literals cast to `any` (`{...} as any`) in spec/test files and steers toward `partial<T>()` from `test/util`. Enabled at error in the spec-files override so CI blocks new occurrences.

Closes #44646

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: drop unnecessary object-literal `as any` casts

The casts masked values already assignable to the expected type (migration configs accepted as Record<string, unknown>, all-optional param types, etc.); removing them restores real type checking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: replace object-literal `as any` casts with partial<T>()

Uses partial<T>() from test/util so incomplete mock/config objects keep proper typing. Azure API mocks switch to mockResolvedValue(partial<T>()) and their inner method mocks to mockResolvedValue(), matching the sibling-file idiom.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: suppress prefer-partial-in-specs for intentionally-invalid inputs

Some tests deliberately pass malformed or legacy data to exercise validation/error paths, where no real type fits; keep the cast with a reasoned oxlint-disable-next-line.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 10:47:30 +00:00

114 lines
3.0 KiB
TypeScript

import type { HostRule } from '../../../types/index.ts';
import { add, clear } from '../../../util/host-rules.ts';
import {
findAllAuthenticatable,
getAuthenticationHeaderValue,
} from './host-rules.ts';
describe('modules/manager/bundler/host-rules', () => {
beforeEach(() => {
clear();
});
describe('getAuthenticationHeaderValue()', () => {
it('returns the authentication header with the password', () => {
expect(
getAuthenticationHeaderValue({
username: 'test',
password: 'password',
}),
).toBe('test:password');
});
it('returns the authentication header with the token', () => {
expect(
getAuthenticationHeaderValue({
token: 'token',
}),
).toBe('token');
});
it('escapes special characters in the username but not the password', () => {
expect(
getAuthenticationHeaderValue({
username: 'test@example.com',
password: 'p@ssword',
}),
).toBe('test%40example.com:p@ssword');
});
});
describe('findAllAuthenticatable()', () => {
let hostRule: HostRule;
beforeEach(() => {
hostRule = {
hostType: 'nuget',
matchHost: 'nuget.org',
username: 'root',
password: 'p4$$w0rd',
token: 'token',
};
});
it('returns an empty array if matchHost is missing', () => {
delete hostRule.matchHost;
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toBeEmptyArray();
});
it('returns an empty array if username is missing and password is present', () => {
delete hostRule.username;
delete hostRule.token;
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toBeEmptyArray();
});
it('returns an empty array if password and token are missing', () => {
delete hostRule.password;
delete hostRule.token;
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toBeEmptyArray();
});
it('returns the hostRule if using matchHost and password', () => {
delete hostRule.token;
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toMatchObject([
hostRule,
]);
});
it('returns the hostRule if using matchHost and token', () => {
delete hostRule.password;
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toMatchObject([
hostRule,
]);
});
it('returns the hostRule if using baseUrl and password', () => {
hostRule.matchHost = 'https://nuget.com';
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toMatchObject([
hostRule,
]);
});
it('returns the hostRule if using baseUrl and token', () => {
hostRule.matchHost = 'https://nuget.com';
add(hostRule);
expect(findAllAuthenticatable({ hostType: 'nuget' })).toMatchObject([
hostRule,
]);
});
});
});