Class: MockDnsServer::ActionFactory
- Inherits:
-
Object
- Object
- MockDnsServer::ActionFactory
- Includes:
- MessageBuilder
- Defined in:
- lib/mock_dns_server/action_factory.rb
Overview
Creates and returns actions that will be run upon receiving incoming messages.
Instance Method Summary collapse
-
#constant(constant_object) ⇒ Object
Responds with the same object regardless of the request content.
-
#echo ⇒ Object
Echos the request back to the sender.
- #puts_and_echo ⇒ Object
-
#puts_message ⇒ Object
Outputs the string representation of the incoming message to stdout.
-
#send_message(response) ⇒ Object
Sends a fixed DNSRuby::Message.
-
#send_soa(zone, serial, expire = nil, refresh = nil) ⇒ Object
Sends a SOA response.
- #zone_load(serial_history) ⇒ Object
Methods included from MessageBuilder
axfr_request, dns_update, dummy_a_response, ixfr_request, ixfr_request_soa_rr, notify_message, ns, rr, serial_value, soa_answer, soa_request, soa_response, specified_a_response
Instance Method Details
#constant(constant_object) ⇒ Object
Responds with the same object regardless of the request content.
27 28 29 30 31 |
# File 'lib/mock_dns_server/action_factory.rb', line 27 def constant(constant_object) ->(_, sender, context, protocol) do context.server.send_response(sender, constant_object, protocol) end end |
#echo ⇒ Object
Echos the request back to the sender.
11 12 13 14 15 |
# File 'lib/mock_dns_server/action_factory.rb', line 11 def echo ->(, sender, context, protocol) do context.server.send_response(sender, , protocol) end end |
#puts_and_echo ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/mock_dns_server/action_factory.rb', line 17 def puts_and_echo ->(, sender, context, protocol) do puts "Received #{protocol.to_s.upcase} message from #{sender}:\n#{incoming_message}\n\n" puts "Hex:\n\n" puts "#{incoming_message.encode.hexdump}\n\n" echo.(, sender, context, protocol) end end |
#puts_message ⇒ Object
Outputs the string representation of the incoming message to stdout.
56 57 58 59 60 |
# File 'lib/mock_dns_server/action_factory.rb', line 56 def ->(, sender, context, protocol) do puts end end |
#send_message(response) ⇒ Object
Sends a fixed DNSRuby::Message.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mock_dns_server/action_factory.rb', line 42 def (response) ->(, sender, context, protocol) do if [, response].all? { |m| m.is_a?(Dnsruby::Message) } response.header.id = .header.id end if response.is_a?(Dnsruby::Message) response.header.qr = true end context.server.send_response(sender, response, protocol) end end |
#send_soa(zone, serial, expire = nil, refresh = nil) ⇒ Object
Sends a SOA response.
35 36 37 38 |
# File 'lib/mock_dns_server/action_factory.rb', line 35 def send_soa(zone, serial, expire = nil, refresh = nil) (soa_response( name: zone, serial: serial, expire: expire, refresh: refresh)) end |
#zone_load(serial_history) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mock_dns_server/action_factory.rb', line 63 def zone_load(serial_history) ->(, sender, context, protocol) do mt = MessageTransformer.new() zone = mt.qname type = mt.qtype if serial_history.zone.downcase != zone.downcase raise "Zones differ (history: #{serial_history.zone}, request: #{zone}" end if %w(AXFR IXFR).include?(type) xfr_response = serial_history.xfr_response() (xfr_response).(, sender, context, :tcp) elsif type == 'SOA' send_soa(zone, serial_history.high_serial).(, sender, context, protocol) end end end |