< Summary - Envilder Core (TypeScript)

Information
Class: src/envilder/core/infrastructure/azure/AzureVaultUrlValidator.ts
Assembly: Default
File(s): src/envilder/core/infrastructure/azure/AzureVaultUrlValidator.ts
Tag: 151_24479375065
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

src/envilder/core/infrastructure/azure/AzureVaultUrlValidator.ts

#LineLine coverage
 1import { InvalidArgumentError } from '../../domain/errors/DomainErrors.js';
 2
 93export const DEFAULT_VAULT_HOSTS = [
 4  '.vault.azure.net',
 5  '.vault.azure.cn',
 6  '.vault.usgovcloudapi.net',
 7  '.vault.microsoftazure.de',
 8];
 9
 10export function validateAzureVaultUrl(
 11  vaultUrl: string,
 12  allowedHosts: string[],
 13): void {
 14  let url: URL;
 2315  try {
 2316    url = new URL(vaultUrl);
 17  } catch {
 218    throw new InvalidArgumentError('vaultUrl must be a valid URL');
 19  }
 20
 2121  if (url.protocol !== 'https:') {
 322    throw new InvalidArgumentError('vaultUrl must use https:// protocol');
 23  }
 24
 1825  const isAllowedHost = allowedHosts.some((suffix) => {
 2126    const normalizedSuffix = suffix.startsWith('.') ? suffix.slice(1) : suffix;
 2127    return (
 28      url.hostname === normalizedSuffix ||
 29      url.hostname.endsWith(`.${normalizedSuffix}`)
 30    );
 31  });
 1832  if (!isAllowedHost) {
 433    throw new InvalidArgumentError(
 34      `vaultUrl hostname must end with one of: ${allowedHosts.join(', ')}`,
 35    );
 36  }
 37}