dns_helper

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dns_helper contains helpers to interact with the Domain Name System.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DNSFindNameservers

func DNSFindNameservers(t testing.TestingT, fqdn string, resolvers []string) []string

DNSFindNameservers tries to find the NS record for the given FQDN, iterating down the domain hierarchy until it founds the NS records and returns it. Fails if there's any error or no NS record is found up to the apex domain.

func DNSFindNameserversE

func DNSFindNameserversE(t testing.TestingT, fqdn string, resolvers []string) ([]string, error)

DNSFindNameserversE tries to find the NS record for the given FQDN, iterating down the domain hierarchy until it founds the NS records and returns it. Returns the last error if the apex domain is reached with no result.

func DNSLookupAuthoritativeAllWithRetry

func DNSLookupAuthoritativeAllWithRetry(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration)

DNSLookupAuthoritativeAllWithRetry repeatedly sends DNS requests for the specified record and type, until ALL authoritative nameservers reply with the exact same non-empty answers or until max retries has been exceeded. If defined, uses the given resolvers instead of the default system ones to find the authoritative nameservers. Fails when max retries has been exceeded.

func DNSLookupAuthoritativeAllWithValidation

func DNSLookupAuthoritativeAllWithValidation(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers)

DNSLookupAuthoritativeAllWithValidation gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers and match the expectedAnswers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any underlying error from DNSLookupAuthoritativeAllWithValidationE.

func DNSLookupAuthoritativeAllWithValidationE

func DNSLookupAuthoritativeAllWithValidationE(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers) error

DNSLookupAuthoritativeAllWithValidationE gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers and match the expectedAnswers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns ValidationError when expectedAnswers differ from the obtained ones. Returns any underlying error from DNSLookupAuthoritativeAllE.

func DNSLookupAuthoritativeAllWithValidationRetry

func DNSLookupAuthoritativeAllWithValidationRetry(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers, maxRetries int, sleepBetweenRetries time.Duration)

DNSLookupAuthoritativeAllWithValidationRetry repeatedly gets authoritative answers for the specified record and type until ALL the authoritative nameservers found give the same answers and match the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails when max retries has been exceeded.

func DNSLookupAuthoritativeAllWithValidationRetryE

func DNSLookupAuthoritativeAllWithValidationRetryE(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers, maxRetries int, sleepBetweenRetries time.Duration) error

DNSLookupAuthoritativeAllWithValidationRetryE repeatedly gets authoritative answers for the specified record and type until ALL the authoritative nameservers found give the same answers and match the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers.

Types

type DNSAnswer

type DNSAnswer struct {
	Type, Value string
}

DNSAnswer type

func (DNSAnswer) String

func (a DNSAnswer) String() string

type DNSAnswers

type DNSAnswers []DNSAnswer

DNSAnswers type

func DNSLookup

func DNSLookup(t testing.TestingT, query DNSQuery, resolvers []string) DNSAnswers

DNSLookup sends a DNS query for the specified record and type using the given resolvers. Fails on any error. Supported record types: A, AAAA, CNAME, MX, NS, TXT

func DNSLookupAuthoritative

func DNSLookupAuthoritative(t testing.TestingT, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupAuthoritative gets authoritative answers for the specified record and type. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeE.

func DNSLookupAuthoritativeAll

func DNSLookupAuthoritativeAll(t testing.TestingT, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupAuthoritativeAll gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeAllE.

func DNSLookupAuthoritativeAllE

func DNSLookupAuthoritativeAllE(t testing.TestingT, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupAuthoritativeAllE gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns InconsistentAuthoritativeError when any authoritative nameserver gives a different answer. Returns any underlying error.

func DNSLookupAuthoritativeAllWithRetryE

func DNSLookupAuthoritativeAllWithRetryE(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) (DNSAnswers, error)

DNSLookupAuthoritativeAllWithRetryE repeatedly sends DNS requests for the specified record and type, until ALL authoritative nameservers reply with the exact same non-empty answers or until max retries has been exceeded. If defined, uses the given resolvers instead of the default system ones to find the authoritative nameservers.

func DNSLookupAuthoritativeE

func DNSLookupAuthoritativeE(t testing.TestingT, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupAuthoritativeE gets authoritative answers for the specified record and type. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns NotFoundError when no answer found in any authoritative nameserver. Returns any underlying error from individual lookups.

func DNSLookupAuthoritativeWithRetry

func DNSLookupAuthoritativeWithRetry(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) DNSAnswers

DNSLookupAuthoritativeWithRetry repeatedly gets authoritative answers for the specified record and type until ANY of the authoritative nameservers found replies with non-empty answer matching the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeWithRetryE.

func DNSLookupAuthoritativeWithRetryE

func DNSLookupAuthoritativeWithRetryE(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) (DNSAnswers, error)

DNSLookupAuthoritativeWithRetryE repeatedly gets authoritative answers for the specified record and type until ANY of the authoritative nameservers found replies with non-empty answer matching the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers.

func DNSLookupE

func DNSLookupE(t testing.TestingT, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupE sends a DNS query for the specified record and type using the given resolvers. Returns QueryTypeError when record type is not supported. Returns any underlying error. Supported record types: A, AAAA, CNAME, MX, NS, TXT

func (DNSAnswers) Sort

func (a DNSAnswers) Sort()

Sort sorts the answers by type and value

type DNSQuery

type DNSQuery struct {
	Type, Name string
}

DNSQuery type

type InconsistentAuthoritativeError

type InconsistentAuthoritativeError struct {
	Query           DNSQuery
	Answers         DNSAnswers
	Nameserver      string
	PreviousAnswers DNSAnswers
}

InconsistentAuthoritativeError is an error that occurs if an authoritative answer is different from another

func (InconsistentAuthoritativeError) Error

type MaxRetriesExceeded

type MaxRetriesExceeded struct {
	Description string
	MaxRetries  int
}

MaxRetriesExceeded is an error that occurs when the maximum amount of retries is exceeded.

func (MaxRetriesExceeded) Error

func (err MaxRetriesExceeded) Error() string

type NSNotFoundError

type NSNotFoundError struct {
	FQDN       string
	Nameserver string
}

NSNotFoundError is an error that occurs if no NS records found

func (NSNotFoundError) Error

func (err NSNotFoundError) Error() string

type NoResolversError

type NoResolversError struct{}

NoResolversError is an error that occurs if no resolvers have been set for DNSLookupE

func (NoResolversError) Error

func (err NoResolversError) Error() string

type NotFoundError

type NotFoundError struct {
	Query      DNSQuery
	Nameserver string
}

NotFoundError is an error that occurs if no answer found

func (NotFoundError) Error

func (err NotFoundError) Error() string

type QueryTypeError

type QueryTypeError struct {
	Type string
}

QueryTypeError is an error that occurs if the DNS query type is not supported

func (QueryTypeError) Error

func (err QueryTypeError) Error() string

type ValidationError

type ValidationError struct {
	Query           DNSQuery
	Answers         DNSAnswers
	ExpectedAnswers DNSAnswers
}

ValidationError is an error that occurs when answers validation fails

func (ValidationError) Error

func (err ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL