Fix hostname validation

This commit is contained in:
Girish Ramakrishnan
2017-12-06 07:13:46 +05:30
parent 91ede59241
commit 5d34559f0a
2 changed files with 23 additions and 21 deletions

View File

@@ -159,35 +159,35 @@ describe('Apps', function () {
describe('validateHostname', function () {
it('does not allow admin subdomain', function () {
expect(apps._validateHostname('my.example.com')).to.be.an(Error);
expect(apps._validateHostname('my', 'example.com')).to.be.an(Error);
});
it('cannot have >63 length subdomains', function () {
var s = '';
for (var i = 0; i < 64; i++) s += 's';
expect(apps._validateHostname(s + '.example.com')).to.be.an(Error);
expect(apps._validateHostname(s, 'example.com')).to.be.an(Error);
});
it('allows only alphanumerics and hypen', function () {
expect(apps._validateHostname('#2r.example.com')).to.be.an(Error);
expect(apps._validateHostname('a%b.example.com')).to.be.an(Error);
expect(apps._validateHostname('ab_.example.com')).to.be.an(Error);
expect(apps._validateHostname('a.b.example.com')).to.be.an(Error);
expect(apps._validateHostname('-ab.example.com')).to.be.an(Error);
expect(apps._validateHostname('ab-.example.com')).to.be.an(Error);
expect(apps._validateHostname('#2r', 'example.com')).to.be.an(Error);
expect(apps._validateHostname('a%b', 'example.com')).to.be.an(Error);
expect(apps._validateHostname('ab_', 'example.com')).to.be.an(Error);
expect(apps._validateHostname('a.b', 'example.com')).to.be.an(Error);
expect(apps._validateHostname('-ab', 'example.com')).to.be.an(Error);
expect(apps._validateHostname('ab-', 'example.com')).to.be.an(Error);
});
it('total length cannot exceed 255', function () {
var s = '';
for (var i = 0; i < (255 - 'example.com'.length); i++) s += 's';
expect(apps._validateHostname(s + '.example.com')).to.be.an(Error);
expect(apps._validateHostname(s, 'example.com')).to.be.an(Error);
});
it('allow valid domains', function () {
expect(apps._validateHostname('a.example.com')).to.be(null);
expect(apps._validateHostname('a0-x.example.com')).to.be(null);
expect(apps._validateHostname('01.example.com')).to.be(null);
expect(apps._validateHostname('a', 'example.com')).to.be(null);
expect(apps._validateHostname('a0-x', 'example.com')).to.be(null);
expect(apps._validateHostname('01', 'example.com')).to.be(null);
});
});