Files
cloudron-box/src/test/dns-test.js

105 lines
4.0 KiB
JavaScript
Raw Normal View History

2016-11-30 15:35:58 +01:00
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
2021-08-13 17:22:28 -07:00
const common = require('./common.js'),
dns = require('../dns.js'),
expect = require('expect.js');
2016-11-30 15:35:58 +01:00
2021-08-13 17:22:28 -07:00
describe('DNS', function () {
const { setup, cleanup, app, domain } = common;
2021-08-13 10:41:10 -07:00
before(setup);
after(cleanup);
2016-11-30 15:35:58 +01:00
2021-08-13 17:22:28 -07:00
describe('validateHostname', function () {
it('does not allow admin subdomain', function () {
expect(dns.validateHostname('my', domain)).to.be.an(Error);
2018-05-07 16:09:00 -07:00
});
2021-08-13 17:22:28 -07:00
it('cannot have >63 length subdomains', function () {
2021-08-20 09:19:44 -07:00
const s = Array(64).fill('s').join('');
2021-08-13 17:22:28 -07:00
expect(dns.validateHostname(s, domain)).to.be.an(Error);
2021-08-20 09:19:44 -07:00
const domainCopy = Object.assign({}, domain, { zoneName: `dev.${s}.example.com` });
expect(dns.validateHostname(`dev.${s}`, domainCopy)).to.be.an(Error);
2018-05-07 16:09:00 -07:00
});
2021-08-13 17:22:28 -07:00
it('allows only alphanumerics and hypen', function () {
expect(dns.validateHostname('#2r', domain)).to.be.an(Error);
expect(dns.validateHostname('a%b', domain)).to.be.an(Error);
expect(dns.validateHostname('ab_', domain)).to.be.an(Error);
expect(dns.validateHostname('ab.', domain)).to.be.an(Error);
expect(dns.validateHostname('ab..c', domain)).to.be.an(Error);
expect(dns.validateHostname('.ab', domain)).to.be.an(Error);
expect(dns.validateHostname('-ab', domain)).to.be.an(Error);
expect(dns.validateHostname('ab-', domain)).to.be.an(Error);
2018-05-09 18:13:21 +02:00
});
2021-08-13 17:22:28 -07:00
it('total length cannot exceed 255', function () {
2021-08-20 09:19:44 -07:00
let s = '';
2021-08-13 17:22:28 -07:00
for (var i = 0; i < (255 - 'example.com'.length); i++) s += 's';
2018-05-09 18:13:21 +02:00
2021-08-13 17:22:28 -07:00
expect(dns.validateHostname(s, domain)).to.be.an(Error);
2018-05-09 18:13:21 +02:00
});
2021-08-13 17:22:28 -07:00
it('allow valid domains', function () {
expect(dns.validateHostname('a', domain)).to.be(null);
expect(dns.validateHostname('a0-x', domain)).to.be(null);
expect(dns.validateHostname('a0.x', domain)).to.be(null);
expect(dns.validateHostname('a0.x.y', domain)).to.be(null);
expect(dns.validateHostname('01', domain)).to.be(null);
2018-05-09 18:13:21 +02:00
});
});
2021-08-13 17:22:28 -07:00
describe('getName', function () {
it('works with zoneName==domain', function () {
const d = {
domain: 'example.com',
zoneName: 'example.com',
config: {}
2019-01-16 18:05:42 +02:00
};
2021-08-13 17:22:28 -07:00
expect(dns.getName(d, '', 'A')).to.be('');
expect(dns.getName(d, 'www', 'A')).to.be('www');
expect(dns.getName(d, 'www.dev', 'A')).to.be('www.dev');
2019-01-16 18:05:42 +02:00
2021-08-13 17:22:28 -07:00
expect(dns.getName(d, '', 'MX')).to.be('');
2019-02-08 11:24:33 -08:00
2021-08-13 17:22:28 -07:00
expect(dns.getName(d, '', 'TXT')).to.be('');
expect(dns.getName(d, 'www', 'TXT')).to.be('www');
expect(dns.getName(d, 'www.dev', 'TXT')).to.be('www.dev');
2019-01-16 18:05:42 +02:00
});
2021-08-13 17:22:28 -07:00
it('works when zoneName!=domain', function () {
const d = {
domain: 'dev.example.com',
zoneName: 'example.com',
config: {}
2017-11-27 18:05:16 -08:00
};
2021-08-13 17:22:28 -07:00
expect(dns.getName(d, '', 'A')).to.be('dev');
expect(dns.getName(d, 'www', 'A')).to.be('www.dev');
expect(dns.getName(d, 'www.dev', 'A')).to.be('www.dev.dev');
2016-11-30 18:04:47 +01:00
2021-08-13 17:22:28 -07:00
expect(dns.getName(d, '', 'MX')).to.be('dev');
2016-11-30 18:04:47 +01:00
2021-08-13 17:22:28 -07:00
expect(dns.getName(d, '', 'TXT')).to.be('dev');
expect(dns.getName(d, 'www', 'TXT')).to.be('www.dev');
expect(dns.getName(d, 'www.dev', 'TXT')).to.be('www.dev.dev');
2016-11-30 18:04:47 +01:00
});
});
2017-09-05 22:23:24 +02:00
2021-08-13 17:22:28 -07:00
describe('register', function () {
it('registers subdomain', async function () {
await dns.registerLocations([ { subdomain: app.subdomain, domain: app.domain } ], { overwriteDns: true }, (/*progress*/) => {});
2017-09-05 22:23:24 +02:00
});
it('unregisters subdomain', async function () {
await dns.unregisterLocations([ { subdomain: app.subdomain, domain: app.domain } ], (/*progress*/) => {});
2017-09-05 22:23:24 +02:00
});
});
2016-11-30 15:35:58 +01:00
});