-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
olegphenomenon
committed
Jan 12, 2022
1 parent
20a86ed
commit b7c1c76
Showing
2 changed files
with
43 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,50 @@ | ||
$VERBOSE=nil | ||
require 'test_helper' | ||
|
||
class ZoneAnswer | ||
def initialize | ||
@answer = [] | ||
|
||
algorithm = OpenStruct.new(code: 13) | ||
|
||
answer = OpenStruct.new | ||
answer.data = "some0 some1 some2 257 some4 some5 some6 mdsswUyr3DPW132mOi8V9xESWE8jTo0dxCjjnopKl+GqJxpVXckHAeF+KkxLbxILfDLUT0rAK9iUzy1L53eKGQ== some" | ||
answer.flags = 257 | ||
answer.protocol = 3 | ||
answer.algorithm = algorithm | ||
|
||
@answer << answer | ||
end | ||
|
||
def each_answer | ||
@answer.each {|rec| | ||
yield rec | ||
} | ||
end | ||
end | ||
|
||
class ValidateDnssecJobTest < ActiveJob::TestCase | ||
setup do | ||
@domain = domains(:shop) | ||
@dnskey = dnskeys(:one) | ||
end | ||
|
||
def test_job_should_return_successfully_validated_dnskeys | ||
# @domain.dnskeys << @dnskey | ||
# @domain.save | ||
# @domain.reload | ||
# | ||
# mock_zone_data = [ | ||
# { | ||
# flags: @dnskey.flags, | ||
# protocol: @dnskey.protocol, | ||
# alg: @dnskey.alg, | ||
# public_key: @dnskey.public_key | ||
# }] | ||
# | ||
# resolver = Spy.mock(Dnsruby::Recursor) | ||
# Spy.on(resolver, :query).and_return true | ||
# Spy.on_instance_method(ValidateDnssecJob, :parse_response).and_return(mock_zone_data) | ||
# # Spy.on_instance_method(ValidateDnssecJob, :prepare_validator).and_return(true) | ||
# | ||
# | ||
# ValidateDnssecJob.perform_now(domain_name: @domain.name) | ||
# | ||
# @domain.reload | ||
# p @domain.dnskeys | ||
end | ||
@domain.nameservers.each do |n| | ||
n.update(validation_datetime: Time.zone.now - 1.minute) | ||
end | ||
@domain.dnskeys << @dnskey | ||
@domain.save | ||
|
||
@domain.reload | ||
|
||
mock_zone_data = ZoneAnswer.new | ||
|
||
# def test_job_discarded_after_error | ||
# assert_no_enqueued_jobs | ||
# assert_performed_jobs 1 do | ||
# TestDiscardedJob.perform_later | ||
# end | ||
# assert_no_enqueued_jobs | ||
# end | ||
Spy.on_instance_method(ValidateDnssecJob, :prepare_validator).and_return(Dnsruby::Resolver.new) | ||
Spy.on_instance_method(Dnsruby::Resolver, :query).and_return(mock_zone_data) | ||
|
||
ValidateDnssecJob.perform_now(domain_name: @domain.name) | ||
|
||
@domain.reload | ||
assert_not_nil @domain.dnskeys.first.validation_datetime | ||
end | ||
end |