diff --git a/lib/tasks/zonefile.rake b/lib/tasks/zonefile.rake index 4aaeaf50e..d045d95dc 100644 --- a/lib/tasks/zonefile.rake +++ b/lib/tasks/zonefile.rake @@ -51,6 +51,7 @@ namespace :zonefile do FROM domains d JOIN nameservers ns ON ns.domain_id = d.id WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter + AND NOT ('{serverHold}' && d.statuses) ORDER BY d.name ), chr(10) @@ -72,6 +73,7 @@ namespace :zonefile do AND ns.hostname LIKE '%.' || d.name AND d.name <> i_origin AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> '' + AND NOT ('{serverHold}' && d.statuses) ), chr(10) ) INTO tmp_var; @@ -91,6 +93,7 @@ namespace :zonefile do AND ns.hostname LIKE '%.' || d.name AND d.name <> i_origin AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> '' + AND NOT ('{serverHold}' && d.statuses) ), chr(10) ) INTO tmp_var; @@ -106,6 +109,7 @@ namespace :zonefile do FROM domains d JOIN dnskeys dk ON dk.domain_id = d.id WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter AND dk.flags = 257 + AND NOT ('{serverHold}' && d.statuses) ), chr(10) ) INTO tmp_var; diff --git a/spec/fabricators/zonefile_setting_fabricator.rb b/spec/fabricators/zonefile_setting_fabricator.rb index b8b04513a..eae2663b3 100644 --- a/spec/fabricators/zonefile_setting_fabricator.rb +++ b/spec/fabricators/zonefile_setting_fabricator.rb @@ -6,5 +6,11 @@ Fabricator(:zonefile_setting) do minimum_ttl 3600 email 'hostmaster.eestiinternet.ee' master_nameserver 'ns.tld.ee' + ns_records "ee. IN NS ns.ut.ee.\nee. IN NS ns.tld.ee.\nee. IN NS sunic.sunet.se.\n" \ + "ee. IN NS ee.aso.ee.\nee. IN NS b.tld.ee.\nee. IN NS ns.eenet.ee.\nee. IN NS e.tld.ee." + a_records "ns.ut.ee. IN A 193.40.5.99\nns.tld.ee. IN A 195.43.87.10\nee.aso.ee. IN A 213.184.51.122\n" \ + "b.tld.ee. IN A 194.146.106.110\nns.eenet.ee. IN A 193.40.56.245\ne.tld.ee. IN A 204.61.216.36" + a4_records "ee.aso.ee. IN AAAA 2a02:88:0:21::2\nb.tld.ee. IN AAAA 2001:67c:1010:28::53\n" \ + "ns.eenet.ee. IN AAAA 2001:bb8::1\ne.tld.ee. IN AAAA 2001:678:94:53::53" after_build { |x| x.retry = 900 } end diff --git a/spec/models/zonefile_setting_spec.rb b/spec/models/zonefile_setting_spec.rb index 013015bbd..564403cdb 100644 --- a/spec/models/zonefile_setting_spec.rb +++ b/spec/models/zonefile_setting_spec.rb @@ -17,6 +17,14 @@ describe ZonefileSetting do )[0]['generate_zonefile'] @zonefile.should_not be_blank + + # origin ns + @zonefile.scan(/ee. IN NS ns.ut.ee.\nee. IN NS ns.tld.ee./).count.should == 1 + # origin a + @zonefile.scan(/ns.ut.ee. IN A 193.40.5.99\nns.tld.ee. IN A 195.43.87.10/).count.should == 1 + # origin aaaa + @zonefile.scan(/ee.aso.ee. IN AAAA 2a02:88:0:21::2\nb.tld.ee. IN AAAA 2001:67c:1010:28::53/).count.should == 1 + @zonefile.scan(/^#{d.name}/).count.should == 5 @zonefile.scan(/ns.#{d.name}/).count.should == 3 @zonefile.scan('123.123.123.123').count.should == 1 @@ -31,6 +39,39 @@ describe ZonefileSetting do @zonefile.scan(/^#{d.name}/).count.should == 0 end + it 'should not place serverHold domains into zonefile' do + Fabricate(:zonefile_setting) + d = Fabricate(:domain_with_dnskeys, name: 'testzone.ee', statuses: ['serverHold', 'serverDeleteProhibited']) + d.nameservers << Nameserver.new({ + hostname: "ns.#{d.name}", + ipv4: '123.123.123.123', + ipv6: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329' + }) + + @zonefile = ActiveRecord::Base.connection.execute( + "select generate_zonefile('ee')" + )[0]['generate_zonefile'] + + @zonefile.should_not be_blank + @zonefile.scan(/^#{d.name}/).count.should == 0 + @zonefile.scan(/ns.#{d.name}/).count.should == 0 + @zonefile.scan('123.123.123.123').count.should == 0 + @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 0 + + d.statuses = ['ok'] + d.save + + @zonefile = ActiveRecord::Base.connection.execute( + "select generate_zonefile('ee')" + )[0]['generate_zonefile'] + + @zonefile.should_not be_blank + @zonefile.scan(/^#{d.name}/).count.should == 5 + @zonefile.scan(/ns.#{d.name}/).count.should == 3 + @zonefile.scan('123.123.123.123').count.should == 1 + @zonefile.scan('FE80:0000:0000:0000:0202:B3FF:FE1E:8329').count.should == 1 + end + it 'does not create duplicate zones' do Fabricate(:zonefile_setting) zs = Fabricate.build(:zonefile_setting)