InvalidRR + s/InvalidZone/DomainNotFound/ + domain regex with final ".".

master
Philippe Pittoli 2023-07-11 04:09:46 +02:00
parent 01a1dbc522
commit 9be374b492
3 changed files with 12 additions and 6 deletions

View File

@ -78,5 +78,13 @@ class DNSManager::Response
end
end
DNSManager.responses << RRAdded
IPC::JSON.message InvalidRR, 20 do
# For now, Error is just an alias on String.
property errors : Array(Storage::Zone::Error)
def initialize(@errors)
end
end
DNSManager.responses << InvalidRR
end

View File

@ -164,7 +164,7 @@ class DNSManager::Storage
rr.get_errors.tap do |errors|
unless errors.empty?
Baguette::Log.warning "add RR with errors: #{errors}"
return Response::InvalidZone.new errors
return Response::InvalidRR.new errors
end
end
@ -201,7 +201,7 @@ class DNSManager::Storage
rr.get_errors.tap do |errors|
unless errors.empty?
Baguette::Log.warning "update RR with errors: #{errors}"
return Response::InvalidZone.new errors
return Response::InvalidRR.new errors
end
end
@ -233,9 +233,7 @@ class DNSManager::Storage
# Zone must exist.
zone = zones_by_domain.get? domain
unless zone
return Response::InvalidZone.new ["Domain not found."]
end
return Response::DomainNotFound.new unless zone
# User must own the zone.
unless user_data.domains.includes?(domain) || user_data.admin

View File

@ -332,7 +332,7 @@ class DNSManager::Storage::Zone
# This regex only is "good enough for now".
def self.is_domain_valid?(domain) : Bool
if domain =~ /^(((?!-))(xn--|_{1,1})?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*((xn--)?[a-z0-9][a-z0-9\-]{0,60}[a-z0-9]|(xn--)?[a-z0-9]{1,60})\.[a-z]{2,}$/
if domain =~ /^(((?!-))(xn--|_{1,1})?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*((xn--)?[a-z0-9][a-z0-9\-]{0,60}[a-z0-9]|(xn--)?[a-z0-9]{1,60})\.[a-z]{2,}\.?$/
true
else
false