From f33e515991a32885622b217bf2ed1d1b0d9d6832 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 7 Feb 2022 11:21:25 +0100 Subject: Correctly check import target URL IP --- server/tests/api/check-params/video-imports.ts | 3 ++- server/tests/helpers/dns.ts | 17 +++++++++++++++++ server/tests/helpers/index.ts | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 server/tests/helpers/dns.ts (limited to 'server/tests') diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 156a612ee..7893f5cc5 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -120,7 +120,8 @@ describe('Test video imports API validator', function () { 'http://127.0.0.1', 'http://127.0.0.1/hello', 'https://192.168.1.42', - 'http://192.168.1.42' + 'http://192.168.1.42', + 'http://127.0.0.1.cpy.re' ] for (const targetUrl of targetUrls) { diff --git a/server/tests/helpers/dns.ts b/server/tests/helpers/dns.ts new file mode 100644 index 000000000..309de5426 --- /dev/null +++ b/server/tests/helpers/dns.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import { expect } from 'chai' +import { isResolvingToUnicastOnly } from '@server/helpers/dns' + +describe('DNS helpers', function () { + + it('Should correctly check unicast IPs', async function () { + expect(await isResolvingToUnicastOnly('cpy.re')).to.be.true + expect(await isResolvingToUnicastOnly('framasoft.org')).to.be.true + expect(await isResolvingToUnicastOnly('8.8.8.8')).to.be.true + + expect(await isResolvingToUnicastOnly('127.0.0.1')).to.be.false + expect(await isResolvingToUnicastOnly('127.0.0.1.cpy.re')).to.be.false + }) +}) diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts index 91d11e25d..951208842 100644 --- a/server/tests/helpers/index.ts +++ b/server/tests/helpers/index.ts @@ -1,5 +1,6 @@ import './image' import './core-utils' +import './dns' import './comment-model' import './markdown' import './request' -- cgit v1.2.3