Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable trimming for dnskey and email values #2453

Merged
merged 3 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/dnskey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def validate_flags
errors.add(:flags, :invalid, values: "Valid flags are: #{FLAGS.join(', ')}")
end

def public_key=(value)
super(value&.strip&.delete(' '))
end

def generate_digest
return unless flags == 257 || flags == 256 # require ZoneFlag, but optional SecureEntryPoint

Expand Down
8 changes: 8 additions & 0 deletions test/models/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ def test_whois_gets_updated_after_contact_save
assert_equal domain.whois_record.try(:json).try(:[], 'registrant'), @contact.name
end

def test_remove_email_whitespaces
contact = valid_contact
contact.email = ' test@test.test '
contact.save

assert_equal contact.email, 'test@test.test'
end

private

def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)
Expand Down
14 changes: 14 additions & 0 deletions test/models/dnskey_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ def test_ds_digest_type_one
assert_equal dns.ds_digest_type, 1
assert_equal dns.ds_digest, '640D173A44D9AF2856FBE282EE64CE11A76DBB84'
end

def test_remove_public_key_whitespaces
dnskey = " AwEAAddt 2AkLfYGKgiEZ B5SmIF8Evr jxNMH6HtxWEA4RJ9Ao6LCWheg8 \n "

dns = Dnskey.new
dns.domain_id = @domain.id
dns.flags = 257
dns.protocol = 3
dns.alg = 8
dns.public_key = dnskey
dns.save

assert_equal dns.public_key, @dnskey
end
end