Commit 8df7bcf5 authored by Drew Blessing's avatar Drew Blessing Committed by Nick Thomas

Allow numeric pages domain

Previously, `PagesDomain` would not allow a domain such as
123.example.com. With this change, this is now allowed, because
it is a perfectly valid domain.
parent e34e5761
class PagesDomain < ActiveRecord::Base class PagesDomain < ActiveRecord::Base
belongs_to :project belongs_to :project
validates :domain, hostname: true validates :domain, hostname: { allow_numeric_hostname: true }
validates :domain, uniqueness: { case_sensitive: false } validates :domain, uniqueness: { case_sensitive: false }
validates :certificate, certificate: true, allow_nil: true, allow_blank: true validates :certificate, certificate: true, allow_nil: true, allow_blank: true
validates :key, certificate_key: true, allow_nil: true, allow_blank: true validates :key, certificate_key: true, allow_nil: true, allow_blank: true
...@@ -98,7 +98,7 @@ class PagesDomain < ActiveRecord::Base ...@@ -98,7 +98,7 @@ class PagesDomain < ActiveRecord::Base
def validate_pages_domain def validate_pages_domain
return unless domain return unless domain
if domain.downcase.ends_with?(".#{Settings.pages.host}".downcase) if domain.downcase.ends_with?(Settings.pages.host.downcase)
self.errors.add(:domain, "*.#{Settings.pages.host} is restricted") self.errors.add(:domain, "*.#{Settings.pages.host} is restricted")
end end
end end
......
---
title: Allow numeric pages domain
merge_request: 11550
author:
...@@ -6,7 +6,7 @@ describe PagesDomain, models: true do ...@@ -6,7 +6,7 @@ describe PagesDomain, models: true do
end end
describe 'validate domain' do describe 'validate domain' do
subject { build(:pages_domain, domain: domain) } subject(:pages_domain) { build(:pages_domain, domain: domain) }
context 'is unique' do context 'is unique' do
let(:domain) { 'my.domain.com' } let(:domain) { 'my.domain.com' }
...@@ -14,36 +14,25 @@ describe PagesDomain, models: true do ...@@ -14,36 +14,25 @@ describe PagesDomain, models: true do
it { is_expected.to validate_uniqueness_of(:domain) } it { is_expected.to validate_uniqueness_of(:domain) }
end end
context 'valid domain' do {
let(:domain) { 'my.domain.com' } 'my.domain.com' => true,
'123.456.789' => true,
it { is_expected.to be_valid } '0x12345.com' => true,
end '0123123' => true,
'_foo.com' => false,
context 'valid hexadecimal-looking domain' do 'reserved.com' => false,
let(:domain) { '0x12345.com'} 'a.reserved.com' => false,
nil => false
it { is_expected.to be_valid } }.each do |value, validity|
end context "domain #{value.inspect} validity" do
before do
context 'no domain' do allow(Settings.pages).to receive(:host).and_return('reserved.com')
let(:domain) { nil } end
it { is_expected.not_to be_valid } let(:domain) { value }
end
it { expect(pages_domain.valid?).to eq(validity) }
context 'invalid domain' do end
let(:domain) { '0123123' }
it { is_expected.not_to be_valid }
end
context 'domain from .example.com' do
let(:domain) { 'my.domain.com' }
before { allow(Settings.pages).to receive(:host).and_return('domain.com') }
it { is_expected.not_to be_valid }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment