Documentation ¶
Index ¶
- Constants
- Variables
- func InitializeContext(ctx context.Context) context.Context
- type ContextKey
- type Logger
- type Record
- type RecordType
- type Session
- func (s *Session) ConfigureDoHQueryParams(ctx context.Context, params map[string][]string)
- func (s *Session) ConfigureOptions(ctx context.Context, options []dns.EDNS0)
- func (s *Session) ConfigureServer(ctx context.Context, svr, transport string)
- func (s *Session) SendDoHQuery(ctx context.Context, method string, qtype uint16, qdomain string, ...) error
- func (s *Session) SendDoTQuery(ctx context.Context, qtype uint16, qdomain string, recursive bool) error
- func (s *Session) SendUDPQuery(ctx context.Context, qtype uint16, qdomain string, recursive bool) error
- func (s *Session) SetDNSResponseTimeout(ctx context.Context, timeout int)
- func (s *Session) ValidateResponseWithCode(ctx context.Context, expectedCode string) error
- func (s *Session) ValidateResponseWithNumberOfRecords(ctx context.Context, expectedRecords int, recordType RecordType) error
- func (s *Session) ValidateResponseWithOneOfCodes(ctx context.Context, expectedCodes []string) error
- func (s *Session) ValidateResponseWithRecords(ctx context.Context, recordType RecordType, expectedRecords []Record) error
- type Steps
Constants ¶
const ( // Answer record type for DNS response messages Answer RecordType = "answer" // Authority record type for DNS response messages Authority = "authority" // Additional record type for DNS response messages Additional = "additional" )
Variables ¶
var QueryTypes = map[string]uint16{ "A": dns.TypeA, "AAAA": dns.TypeAAAA, "CNAME": dns.TypeCNAME, "MX": dns.TypeMX, "NS": dns.TypeNS, }
QueryTypes is a map of the DNS query type with the correspondence type in dns package.
Functions ¶
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey defines a type to store the Context in context.Context.
type Logger ¶
Logger logs the DNS request and response in a configurable file.
func GetLogger ¶
func GetLogger() *Logger
GetLogger returns the logger for DNS requests and responses. If the logger is not created yet, it creates a new instance of Logger.
func (Logger) LogRequest ¶
LogRequest logs a DNS request in the configured log file.
type Record ¶
Record is an abstraction of a DNS records (based on dns.RR). It aims to checks the most relevant fields of a DNS records.
func (*Record) IsContained ¶
IsContained checks if the record matches with any of the actual DNS records of the slice.
type RecordType ¶
type RecordType string
RecordType enumerates the possible types of DNS records: answer, authority and additional records.
type Session ¶
type Session struct { // Server is the address to the DNS server, including the server port (e.g. 8.8.8.8:53). Server string // Transport is the network protocol used to send the queries // (valid values: UDP, DoT, Doh with GET, DoH with POST) Transport string // DNS query options (EDNS0) Options []dns.EDNS0 // Query parameters DoHQueryParams map[string][]string // Query contains the DNS request message. Query *dns.Msg // Response contains the DNS response message. Response *dns.Msg // RTT is the response time. RTT time.Duration // Timeout is the maximum time to wait for a response. Expressed in Milliseconds Timeout time.Duration }
Session contains the information related to a DNS query and response.
func GetSession ¶
GetSession returns the DNS session stored in context. Note that the context should be previously initialized with InitializeContext function.
func (*Session) ConfigureDoHQueryParams ¶
ConfigureDoHQueryParams stores a table of query parameters in the application context.
func (*Session) ConfigureOptions ¶
ConfigureOptions adds EDNS0 options to be included in the DNS query.
func (*Session) ConfigureServer ¶
ConfigureServer configures the DNS server location and the transport protocol.
func (*Session) SendDoHQuery ¶
func (s *Session) SendDoHQuery( ctx context.Context, method string, qtype uint16, qdomain string, recursive bool, ) error
SendDoHQuery sends a DoH query to resolve a domain.
func (*Session) SendDoTQuery ¶
func (s *Session) SendDoTQuery( ctx context.Context, qtype uint16, qdomain string, recursive bool, ) error
SendDoTQuery sends a DoT query to resolve a domain.
func (*Session) SendUDPQuery ¶
func (s *Session) SendUDPQuery( ctx context.Context, qtype uint16, qdomain string, recursive bool, ) error
SendUDPQuery sends a DNS query to resolve a domain.
func (*Session) SetDNSResponseTimeout ¶
SetDNSResponseTimeout configures a DNS response timeout.
func (*Session) ValidateResponseWithCode ¶
ValidateResponseWithCode validates the code of the DNS response.
func (*Session) ValidateResponseWithNumberOfRecords ¶
func (s *Session) ValidateResponseWithNumberOfRecords( ctx context.Context, expectedRecords int, recordType RecordType, ) error
ValidateResponseWithNumberOfRecords validates the amount of records in a DNS response for one of the record types: answer, authority, additional.
func (*Session) ValidateResponseWithOneOfCodes ¶
func (s *Session) ValidateResponseWithOneOfCodes( ctx context.Context, expectedCodes []string, ) error
ValidateResponseWithOneOfCodes validates the code of the DNS response againt a list of valid codes.
func (*Session) ValidateResponseWithRecords ¶
func (s *Session) ValidateResponseWithRecords( ctx context.Context, recordType RecordType, expectedRecords []Record, ) error
ValidateResponseWithRecords validates that the response contains the following records for one of the record types: answer, authority, additional.
type Steps ¶
type Steps struct { }
Steps type is responsible to initialize the DNS client steps in godog framework.
func (Steps) InitializeSteps ¶
InitializeSteps adds client DNS steps to the scenario context. It implements StepInitializer interface. It returns a new context (context is immutable) with the DNS Context.