Skip to content

Commit 53662c9

Browse files
committed
Fix tests where domain name is needed
1 parent 013c703 commit 53662c9

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

src/dns/DMARC.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dns from 'dns';
22
import Test, { TestParameters, Result } from '../Test';
33
import logger from '../logger';
4+
import getDomain from '../functions/getDomain';
45

56
class DMARC extends Test {
67
public name = 'DMARC';
@@ -9,7 +10,7 @@ class DMARC extends Test {
910
logger.info(`Starting ${this.constructor.name} test...`);
1011

1112
const response: any = await new Promise((resolve, reject) => {
12-
dns.resolveTxt(`_dmarc.${(new URL(url).hostname)}`, (err, records) => {
13+
dns.resolveTxt(`_dmarc.${getDomain(url)}`, (err, records) => {
1314
if (err) {
1415
reject(err);
1516
}

src/dns/NS.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import whois from 'whois';
22
import Test, { TestParameters, Result } from '../Test';
33
import logger from '../logger';
4+
import getDomain from '../functions/getDomain';
45

56
class NS extends Test {
67
public name = 'NS';
78

89
public async test({ url }: TestParameters): Promise<Result> {
910
logger.info(`Starting ${this.constructor.name} test...`);
1011

11-
const nameServers = await this.getNameServers((new URL(url).hostname));
12+
const nameServers = await this.getNameServers(getDomain(url));
1213

1314
return {
1415
status: 'SUCCESS',

src/dns/RegistrationDate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import whois from 'whois';
22
import Test, { TestParameters, Result } from '../Test';
33
import logger from '../logger';
4+
import getDomain from '../functions/getDomain';
45

56
class RegistrationDate extends Test {
67
public name = 'RegistrationDate';
78

89
public async test({ url }: TestParameters): Promise<Result> {
910
logger.info(`Starting ${this.constructor.name} test...`);
1011

11-
const registrationDate = await this.getRegistrationDate((new URL(url).hostname));
12+
const registrationDate = await this.getRegistrationDate(getDomain(url));
1213

1314
const diffInMs = (new Date(registrationDate)).getTime() - (new Date()).getTime();
1415
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);

src/functions/getDomain.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const getDomain = (url: string): string => {
2+
const hostname = (new URL(url)).hostname;
3+
const parts = hostname.split('.');
4+
5+
if (parts.length === 2) {
6+
return hostname;
7+
}
8+
9+
if (parts.length === 3 && parts[1].length > parts[2].length) {
10+
return hostname.replace(`${parts[0]}.`, '');
11+
}
12+
13+
return hostname;
14+
}
15+
16+
export default getDomain;

0 commit comments

Comments
 (0)