Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / test / features / step_definitions / dnscrypt-proxy.rb
blobc00bae62c88d0cdbe719d9f1755a289ec512eeb5
2 require 'net/dns/resolver'
4 PROXY_IP = '127.0.0.1'
5 PROXY_PORT = 5300
7 Before do
8   @resolver = Net::DNS::Resolver.new(nameserver: PROXY_IP, port: PROXY_PORT)
9 end
11 After do
12   Process.kill("KILL", @pipe.pid) if @pipe
13   @pipe = nil
14 end
16 Around do |scenario, block|
17   Timeout.timeout(3.0) do
18     block.call
19   end
20 end
22 Given /^a running dnscrypt proxy with options "([^"]*)"$/ do |options|
23   @pipe = IO.popen("dnscrypt-proxy " +
24     "--local-address=#{PROXY_IP}:#{PROXY_PORT} $#{options}", "r")
25   sleep(1.5)
26 end
28 When /^a client asks dnscrypt\-proxy for "([^"]*)"$/ do |name|
29   @answer_section = @resolver.query(name, Net::DNS::A).answer
30 end
32 Then /^dnscrypt\-proxy returns "([^"]*)"$/ do |ip_for_name|
33   @answer_section.collect { |a| a.address.to_s }.should include(ip_for_name)
34 end
36 Then /^dnscrypt\-proxy returns a NXDOMAIN answer$/ do
37   @answer_section.should be_empty
38 end