2025-05-27 11:31:12 +00:00
|
|
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
2016-11-15 21:39:21 +01:00
|
|
|
|
2024-06-02 15:34:19 +02:00
|
|
|
import * as smartdns from '../ts_client/index.js';
|
2016-11-15 21:39:21 +01:00
|
|
|
|
2025-05-27 11:39:22 +00:00
|
|
|
let testDnsClient: smartdns.Smartdns;
|
2016-11-15 21:39:21 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should create an instance of Dnsly', async () => {
|
2025-05-27 11:39:22 +00:00
|
|
|
testDnsClient = new smartdns.Smartdns({});
|
|
|
|
expect(testDnsClient).toBeInstanceOf(smartdns.Smartdns);
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2016-11-15 21:39:21 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should get an A DNS Record', async () => {
|
2025-05-27 12:15:17 +00:00
|
|
|
const records = await testDnsClient.getRecordsA('google.com');
|
|
|
|
expect(records).toBeInstanceOf(Array);
|
|
|
|
expect(records.length).toBeGreaterThan(0);
|
|
|
|
expect(records[0]).toHaveProperty('name', 'google.com');
|
|
|
|
expect(records[0]).toHaveProperty('type', 'A');
|
|
|
|
expect(records[0]).toHaveProperty('value');
|
|
|
|
expect(records[0]).toHaveProperty('dnsSecEnabled');
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2017-01-27 00:11:13 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should get an AAAA Record', async () => {
|
2025-05-27 12:15:17 +00:00
|
|
|
const records = await testDnsClient.getRecordsAAAA('google.com');
|
|
|
|
expect(records).toBeInstanceOf(Array);
|
|
|
|
expect(records.length).toBeGreaterThan(0);
|
|
|
|
expect(records[0]).toHaveProperty('name', 'google.com');
|
|
|
|
expect(records[0]).toHaveProperty('type', 'AAAA');
|
|
|
|
expect(records[0]).toHaveProperty('value');
|
|
|
|
expect(records[0]).toHaveProperty('dnsSecEnabled');
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2016-11-15 21:39:21 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should get a txt record', async () => {
|
2025-05-27 12:15:17 +00:00
|
|
|
const records = await testDnsClient.getRecordsTxt('google.com');
|
|
|
|
expect(records).toBeInstanceOf(Array);
|
|
|
|
expect(records.length).toBeGreaterThan(0);
|
|
|
|
expect(records[0]).toHaveProperty('name', 'google.com');
|
|
|
|
expect(records[0]).toHaveProperty('type', 'TXT');
|
|
|
|
expect(records[0]).toHaveProperty('value');
|
|
|
|
expect(records[0]).toHaveProperty('dnsSecEnabled');
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2016-11-15 22:40:40 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should, get a mx record for a domain', async () => {
|
2025-05-27 11:39:22 +00:00
|
|
|
const res = await testDnsClient.getRecords('bleu.de', 'MX');
|
2018-05-13 15:51:04 +02:00
|
|
|
console.log(res);
|
|
|
|
});
|
2017-01-27 00:11:13 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should check until DNS is available', async () => {
|
2025-05-27 12:15:17 +00:00
|
|
|
const records = await testDnsClient.getRecordsTxt('google.com');
|
|
|
|
if (records.length > 0) {
|
|
|
|
const result = await testDnsClient.checkUntilAvailable('google.com', 'TXT', records[0].value);
|
|
|
|
expect(result).toBeTrue();
|
|
|
|
}
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2017-01-27 00:11:13 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should check until DNS is available an return false if it fails', async () => {
|
2023-03-23 01:41:35 +01:00
|
|
|
return expect(
|
2025-05-27 12:15:17 +00:00
|
|
|
await testDnsClient.checkUntilAvailable('google.com', 'TXT', 'this-txt-record-does-not-exist')
|
2023-03-23 01:41:35 +01:00
|
|
|
).toBeFalse();
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2017-01-27 00:37:32 +01:00
|
|
|
|
2017-07-18 15:45:06 +02:00
|
|
|
tap.test('should check until DNS is available an return false if it fails', async () => {
|
2023-03-23 01:41:35 +01:00
|
|
|
return expect(
|
2025-05-27 12:15:17 +00:00
|
|
|
await testDnsClient.checkUntilAvailable('nonexistent.example.com', 'TXT', 'sometext_txt2')
|
2023-03-23 01:41:35 +01:00
|
|
|
).toBeFalse();
|
2018-05-13 15:51:04 +02:00
|
|
|
});
|
2017-07-18 15:45:06 +02:00
|
|
|
|
2018-05-13 15:51:04 +02:00
|
|
|
tap.test('should get name server for hostname', async () => {
|
2025-05-27 11:39:22 +00:00
|
|
|
let result = await testDnsClient.getNameServers('bleu.de');
|
2018-05-13 15:51:04 +02:00
|
|
|
console.log(result);
|
|
|
|
});
|
|
|
|
|
2020-02-15 16:41:37 +00:00
|
|
|
tap.test('should detect dns sec', async () => {
|
2025-05-27 11:39:22 +00:00
|
|
|
const result = await testDnsClient.getRecordsA('lossless.com');
|
2020-02-15 16:41:37 +00:00
|
|
|
console.log(result[0]);
|
2022-07-27 08:59:29 +02:00
|
|
|
expect(result[0].dnsSecEnabled).toBeTrue();
|
2020-02-15 16:46:04 +00:00
|
|
|
});
|
2020-02-15 16:41:37 +00:00
|
|
|
|
2025-05-27 11:31:12 +00:00
|
|
|
export default tap.start();
|