2025-04-27 14:28:05 +00:00
|
|
|
import { tap, expect } from '@push.rocks/tapbundle';
|
|
|
|
import { SmartacmeCertMatcher } from '../ts/smartacme.classes.certmatcher.js';
|
|
|
|
|
|
|
|
tap.test('should match 2-level domain', async () => {
|
|
|
|
const matcher = new SmartacmeCertMatcher();
|
|
|
|
expect(matcher.getCertificateDomainNameByDomainName('example.com')).toEqual('example.com');
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should match 3-level domain', async () => {
|
|
|
|
const matcher = new SmartacmeCertMatcher();
|
|
|
|
expect(matcher.getCertificateDomainNameByDomainName('subdomain.example.com')).toEqual('example.com');
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should return undefined for deeper domain', async () => {
|
|
|
|
const matcher = new SmartacmeCertMatcher();
|
|
|
|
// domain with 4 or more levels
|
|
|
|
const result = matcher.getCertificateDomainNameByDomainName('a.b.example.com');
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
2025-05-04 10:29:33 +00:00
|
|
|
// Wildcard domain handling
|
|
|
|
tap.test('should strip wildcard prefix and return base domain', async () => {
|
|
|
|
const matcher = new SmartacmeCertMatcher();
|
|
|
|
expect(matcher.getCertificateDomainNameByDomainName('*.example.com')).toEqual('example.com');
|
|
|
|
expect(matcher.getCertificateDomainNameByDomainName('*.sub.example.com')).toEqual('sub.example.com');
|
|
|
|
expect(matcher.getCertificateDomainNameByDomainName('*.a.b.example.com')).toEqual('a.b.example.com');
|
|
|
|
});
|
|
|
|
|
2025-04-27 14:28:05 +00:00
|
|
|
export default tap.start();
|