Skip to content

Commit

Permalink
Merge pull request #61 from internetee/55-respond-to-1-letter-queries…
Browse files Browse the repository at this point in the history
…-with-proper-error-message

Return Policy error if domain entry in wrong format
  • Loading branch information
vohmar authored Mar 30, 2020
2 parents 6d6c397 + 9aa1c29 commit 824ef70
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/whois_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,31 @@ def receive_data(data)
send_data whois_record.unix_body
else
logger.info "#{ip}: requested: #{data} [searched by: #{name}; No record found]"
send_data no_entries_msg
provide_data_body(name)
end
close_connection_after_writing
end

private

def provide_data_body(domain_name)
return send_data(no_entries_msg) if domain_valid_format?(domain_name)

send_data(policy_error_msg)
end

def domain_valid_format?(domain_name)
domain_name_regexp = /\A[a-z0-9\-\u00E4\u00F5\u00F6\u00FC\u0161\u017E]{2,61}\.
([a-z0-9\-\u00E4\u00F5\u00F6\u00FC\u0161\u017E]{2,61}\.)?[a-z0-9]{1,61}\z/x

formatted_domain_name = domain_name.strip.downcase
nil != (formatted_domain_name =~ domain_name_regexp)
end

def policy_error_msg
"\nPolicy error" + footer_msg
end

def no_entries_msg
"\nDomain not found" + footer_msg
end
Expand Down

0 comments on commit 824ef70

Please sign in to comment.