Fix hostname validation
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user