Skip to content

Added extra test coverage for validate_dnssec_job #2811

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mmeest
Copy link
Contributor

@mmeest mmeest commented Jun 17, 2025

No description provided.

@mmeest
Copy link
Contributor Author

mmeest commented Jun 17, 2025

Pull request testing fails. Probable cause is timing in test method:
rails test test/integration/admin_area/white_ips_test.rb:43
Locally that test runs. But on Github possible cause 'page reload' takes longer.

@mmeest
Copy link
Contributor Author

mmeest commented Jun 18, 2025

Resolved the problem with ENV['nameserver_validation_timeout']

original_timeout = ENV['nameserver_validation_timeout']

# Seadista kindel väärtus testiks
ENV['nameserver_validation_timeout'] = '4'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translate comment to English, because registry is Open Source product.
Also, among the English comments, this one stands out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced this comment with more explanatory English comment.

def test_prepare_validator_configures_dnsruby_resolver_with_correct_parameters
job = ValidateDnssecJob.new

# To store original environment variable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't really add any meaning — it just explains what the code is doing, which is already obvious. So there are two options: either delete the comment, or rewrite it to explain what the nameserver_validation_timeout value does and how it affects the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unnecessary comment.


resolver = job.send(:prepare_validator, "8.8.8.8")

assert_instance_of Dnsruby::Resolver, resolver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we testing type safety or functionality here? Please clarify, because otherwise I don't see the point of this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While Ruby is dynamically typed language, so it is meant that code behaves correctly at runtime. It is functional guarantee we can use resolver object in next steps.

valid_to: 1.year.from_now
)

# Add DNSKEY to domain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

job = ValidateDnssecJob.new
job.define_singleton_method(:logger) { logger }

# Run the job
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

job.perform(domain_name: domain.name)

# Verify that the domain was skipped
assert_match /No related nameservers for this domain/, log_output.string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've overcomplicated the test a bit. If you look at the file app/jobs/validate_dnssec_job.rb, the dns key object has a field called validation_datetime, which gets updated when the validation is successful. You could’ve used that for the check.

Of course, if the goal is to verify the logs, then tracking logs makes sense too. But what's really important here is that the job didn’t make any changes to the database record.

We actually need two clear tests:
One test that confirms the table was updated when a nameserver is present.
And this current test should prove that validation was skipped, meaning no changes happened in the table at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Rewrote test logic.

end

def perform_without_domain_name_executes_else_block
# Use existing domain fixture
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

# Use existing domain fixture
domain = domains(:shop)

# Add DNSKEY if not present
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can rewrite this part more like "ruby-style":

domain.dnskeys << @dnskey unless domain.dnskeys.any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out. Rewrote the code.


ValidateDnssecJob.perform_now()

assert true, "Job finished without errors"
Copy link
Contributor

@OlegPhenomenon OlegPhenomenon Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not quite sure I understand the point of this test. What happens if there’s no nameserver — does it still complete without errors? What exactly is the success criteria here? Just checking that the job runs?

What we really need is to confirm that the job actually did its job — meaning the data we expect to change has actually changed (or hasn’t, depending on the case).

I know the job we’re testing includes exception handling, but those should have their own separate tests. Here, the main check should be whether the expected data changes happened — that's the real sign the job worked correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote those two tests a bit clearer.

)
end

ValidateDnssecJob.perform_now()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

@OlegPhenomenon OlegPhenomenon self-requested a review June 20, 2025 07:54
Copy link
Contributor

@OlegPhenomenon OlegPhenomenon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read my feedback, if you have some question, you can contact with me

@mmeest
Copy link
Contributor Author

mmeest commented Jun 27, 2025

Please read my feedback, if you have some question, you can contact with me

Thank you for really valuable feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants