Browse Source
Do not assume that an address that starts with a number is an IP address and expand validation to cover all FQDNs and IP addresses. Fix #766renovate/lint-staged-8.x
Tom Kirkpatrick
6 years ago
3 changed files with 34 additions and 1 deletions
@ -0,0 +1,13 @@ |
|||
const dns = jest.genMockFromModule('dns') |
|||
|
|||
function lookup(hostname, options, callback = jest.fn()) { |
|||
let cb = callback |
|||
if (typeof options === 'function') { |
|||
cb = options |
|||
} |
|||
process.nextTick(cb, null, hostname) |
|||
} |
|||
|
|||
dns.lookup = lookup |
|||
|
|||
module.exports = dns |
@ -0,0 +1,19 @@ |
|||
import { validateHost } from 'lib/lnd/util' |
|||
|
|||
jest.mock('dns') |
|||
|
|||
describe('Util', function() { |
|||
describe('validateHost', () => { |
|||
it('should resolve true for valid hostnames', async () => { |
|||
await expect(validateHost('example.com')).resolves.toBeTruthy() |
|||
await expect(validateHost('localhost')).resolves.toBeTruthy() |
|||
await expect(validateHost('192.168.0.1')).resolves.toBeTruthy() |
|||
await expect(validateHost('11.111.11.111.rdns.example.com')).resolves.toBeTruthy() |
|||
}) |
|||
it('should reject for invalid hostnames', async () => { |
|||
await expect(validateHost('1+-000invlidhost')).rejects.toThrowErrorMatchingInlineSnapshot( |
|||
`"1+-000invlidhost is not a valid IP address or hostname"` |
|||
) |
|||
}) |
|||
}) |
|||
}) |
Loading…
Reference in new issue