Skip to content

Commit

Permalink
test: increase timeout for DNS results
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed May 12, 2024
1 parent 8919cf7 commit 4693119
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// determine the ASN of the connecting IP

// node built-ins
const dns = require('dns').promises
const fs = require('fs/promises')
const path = require('path')
const dns = require('node:dns').promises
const fs = require('node:fs/promises')
const path = require('node:path')

let test_ip = '66.128.51.163'
const providers = []
Expand Down Expand Up @@ -137,7 +136,6 @@ exports.get_result = function (zone, first) {
}

exports.lookup_via_dns = function (next, connection) {
const plugin = this
if (connection.remote.is_private) return next()

const promises = []
Expand All @@ -148,7 +146,7 @@ exports.lookup_via_dns = function (next, connection) {
// connection.logdebug(plugin, `zone: ${zone}`);

try {
plugin.get_dns_results(zone, connection.remote.ip).then((r) => {
this.get_dns_results(zone, connection.remote.ip).then((r) => {
if (!r) return resolve()

const results = { emit: true }
Expand All @@ -173,11 +171,11 @@ exports.lookup_via_dns = function (next, connection) {
break
}

connection.results.add(plugin, results)
connection.results.add(this, results)
resolve(results)
})
} catch (err) {
connection.results.add(plugin, { err })
connection.results.add(this, { err })
resolve()
}
}),
Expand Down
7 changes: 2 additions & 5 deletions test/asn.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

// node build-in modules
const assert = require('assert')
const assert = require('node:assert')

// npm installed modules
const fixtures = require('haraka-test-fixtures')
Expand Down Expand Up @@ -109,12 +108,12 @@ describe('parse_rspamd', function () {
})

describe('get_dns_results', function () {
this.timeout(5000)
const asn = new fixtures.plugin('asn')
asn.cfg = { main: {}, protocols: { dns: true } }
asn.connection = fixtures.connection.createConnection()

it('origin.asn.cymru.com', function (done) {
this.timeout(4000)
asn.get_dns_results('origin.asn.cymru.com', '8.8.8.8').then((obj) => {
if (obj) {
assert.equal('15169', obj.asn)
Expand All @@ -140,7 +139,6 @@ describe('get_dns_results', function () {
})

it('asn.rspamd.com', function (done) {
this.timeout(3000)
asn.get_dns_results('asn.rspamd.com', '8.8.8.8').then((obj, zone) => {

Check warning on line 142 in test/asn.js

View workflow job for this annotation

GitHub Actions / lint / lint

'zone' is defined but never used

Check warning on line 142 in test/asn.js

View workflow job for this annotation

GitHub Actions / lint / lint

'zone' is defined but never used
if (obj) {
assert.equal('15169', obj.asn)
Expand All @@ -153,7 +151,6 @@ describe('get_dns_results', function () {
})

it('origin.asn.spameatingmonkey.net', (done) => {
this.timeout(3000)
asn
.get_dns_results('origin.asn.spameatingmonkey.net', '8.8.8.8')
.then((obj, zone) => {

Check warning on line 156 in test/asn.js

View workflow job for this annotation

GitHub Actions / lint / lint

'zone' is defined but never used

Check warning on line 156 in test/asn.js

View workflow job for this annotation

GitHub Actions / lint / lint

'zone' is defined but never used
Expand Down

0 comments on commit 4693119

Please sign in to comment.