forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
DomainHelpers
spec support module for DNS/MX stub (mastodon#32690)
- Loading branch information
1 parent
de1d8dc
commit df3b954
Showing
4 changed files
with
47 additions
and
22 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module DomainHelpers | ||
def configure_mx(domain:, exchange:, ip_v4_addr: '2.3.4.5', ip_v6_addr: 'fd00::2') | ||
resolver = instance_double(Resolv::DNS, :timeouts= => nil) | ||
|
||
allow(resolver).to receive(:getresources) | ||
.with(domain, Resolv::DNS::Resource::IN::MX) | ||
.and_return([double_mx(exchange)]) | ||
allow(resolver) | ||
.to receive(:getresources) | ||
.with(domain, Resolv::DNS::Resource::IN::A) | ||
.and_return([]) | ||
allow(resolver) | ||
.to receive(:getresources) | ||
.with(domain, Resolv::DNS::Resource::IN::AAAA) | ||
.and_return([]) | ||
allow(resolver) | ||
.to receive(:getresources) | ||
.with(exchange, Resolv::DNS::Resource::IN::A) | ||
.and_return([double_resource_v4(ip_v4_addr)]) | ||
allow(resolver) | ||
.to receive(:getresources) | ||
.with(exchange, Resolv::DNS::Resource::IN::AAAA) | ||
.and_return([double_resource_v6(ip_v6_addr)]) | ||
allow(Resolv::DNS) | ||
.to receive(:open) | ||
.and_yield(resolver) | ||
end | ||
|
||
private | ||
|
||
def double_mx(exchange) | ||
instance_double(Resolv::DNS::Resource::MX, exchange: exchange) | ||
end | ||
|
||
def double_resource_v4(addr) | ||
instance_double(Resolv::DNS::Resource::IN::A, address: addr) | ||
end | ||
|
||
def double_resource_v6(addr) | ||
instance_double(Resolv::DNS::Resource::IN::AAAA, address: addr) | ||
end | ||
end |