aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/dns_test.go
AgeCommit message (Collapse)Author
2026-03-26lib/dns: refactoring DoT and DoH to use address instead of portShulhan
Using port makes the IP address of DoT and DoH listen on the same address with UDP. If we set ListenAddress to 0.0.0.0 and TLS termination is handled by proxy, this cause DoT and DoH will also listen on all addresses.
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2024-03-22lib/dns: add test flag to skip running DNS serverShulhan
When we want to test a function or methods that does not interact with DNS server, there is no need to run dummy DNS server.
2023-08-05lib/dns: always initialize the Zone SOA record to default valuesShulhan
Previously, if we parse, create, or remove the SOA record from zone, we assume the SOA records are valid and not touch their values. In this changes, we set the SOA fields to default values if its not set, to make the SOA record consistent and valid, in perspective of client. This changes also export the default OS values for documentation and add new method NewRDataSOA to simplify creating new SOA record.
2022-07-27lib/dns: change the TLS listen port when testingShulhan
This is to prevent the test failed due to the same port number (8053) has already been used (another DNS server already running).
2022-05-30lib/dns: move all caches operations from Server to Caches typeShulhan
Previously all caches operation are tied to the Server type. In order to separate the responsibilities between server and caches, we move all caches operations to Cache type.
2022-05-12all: rewrite all codes to use "var" instead of ":="Shulhan
Using ":=" simplify the code but we lose the type. For example, v := F() The only way we know what the type of v is by inspecting the function F. Another disadvantages of using ":=" may cause extra variables allocation where two or more variables with same type is declared inside body of function where it could be only one. While at it, we split the struct for test case into separate type.
2021-11-14lib/dns: refactoring, create type RecordType to represent type of RRShulhan
Previously, we use uint16 to represent type for ResourceRecord Type or Question type. To make the code more strict, where parameter or return value, must be expected as record type, we add new type to represent the RR type: RecordType. This changes also rename any variable name of QType or qtype to RType or rtype because QType is misleading. The type defined the ResourceRecord to be queried not only question.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2021-01-20dns: replace master word with zoneShulhan
This is for consistency for type and variable names.
2020-08-25dns: add second parameter to PopulateCachesByXXXShulhan
The second parameter uniquely identify the source of caches.
2020-08-18dns: rename MasterFile to ZoneFileShulhan
2020-08-10dns: split between MasterFile and masterParserShulhan
While at it add field Records that contains unpacked ResourceRecord as mapping between domain and ResourceRecord. This is useful for client that need to edit the RR in MasterFile. This changes also unexport the Messages field, to access it use the method Messages().
2020-06-06all: use default linter optionsShulhan
2020-06-04dns: refactoring loading hosts and master filesShulhan
Instead of as methods in Server, we detach the LoadHostDir and LostMasterDir into functions that return list of filename and their content.
2020-02-13dns: check returned error from ListenAndServer in TestMainShulhan
2019-12-18dns: merge Start and Wait into ListenAndServeShulhan
2019-10-17dns: change the server certificate options to load from filesShulhan
Previously, the certificate is initialized by caller. This commit changes the certification initialization by using path to the files.
2019-10-17dns: implement client for DNS over TLSShulhan
There is nothing special with this implementation. Basically, its TCP connection on top of TLS.
2019-10-16dns: refactoring server optionsShulhan
The fields in ServerOptions is refactored to have generic name. * The IPAddress field is renamed to ListenAddress, its value is both IP address and port. * The Port field is removed, merged to ListenAddress. * The DoHPort field renamed to HTTPPort. * The DoHCertificate field is renamed to TLSCertificate. * The DoHAllowInsecure field is renamed to TLSAllowInsecure. All the fields now have ini tag so it can be filled by using ini.Unmarshal().
2019-10-03dns: disable parent name servers on test serverShulhan
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-05-17dns: set log flag to 0, without time prefixShulhan
2019-04-12dns: remove TCPPort on ServerOptionsShulhan
This commit change the ServerOptions to use single port field for UDP and TCP.
2019-04-12dns/server: implement recursion, forwarding request to parent name serversShulhan
The forwarding routines will be running only if there is at least one valid NameServers on ServerOptions. The request will be forwarded only if IsRD (is recursion desired) flag is set.
2019-04-12dns: refactor server to use cachesShulhan
Previously, we use a handler for server, like server in HTTP library, to serve query from client based on request. The idea was to make server more generic which allow custom cache or request handling. This is make sense if DNS response is dynamic, but in real world it is not. DNS record actually static, either loaded from file (hosts or zone file) or from response by recursive server. This commit remove the server Handler and make all request to be handled automatically based on whether the query exist on cache or not.
2019-04-12dns: use direct certificate instance on ServerOptionsShulhan
There are possibility that certificate and private key file may not exist in file system, for example in memory or fetched from other server. This commit replace CertFile and PrivateKeyFile on ServerOptions with direct instance of tls.Certificate.
2019-04-12dns: add caches for serverShulhan
There are two type of answer: local and non-local. Local answer is a DNS record that is loaded from hosts file or master zone file. Non-local answer is a DNS record that is received from parent name servers. Server caches the DNS answers in two storages: map and list. The map caches store local and non local answers, using domain name as a key and list of answers as value, domain-name -> [{A,IN,...},{AAAA,IN,...}] The list caches store non-local answers, ordered by last accessed time, it is used to prune least frequently accessed answers. Local caches will never get pruned.
2019-04-12dns: detach generate test response from test serverHandlerShulhan
The function that generate test responses will save the response in global variables _testResponses. This is required when we refactor unit test later to minimize global variable.
2019-04-12dns: fix data race issue when running testShulhan
2019-04-12dns/server: refactor server to use Start, Wait, and StopShulhan
First, server have the following method exported: ListenAndServe, ListenAndServeDoH, ListenAndServeTCP, and ListenAndServeUDP. The last three methods are actually called by ListenAndServe automatically, so there is no need to export them. Second, instance of ServerOptions is only used for bootstraping listener. After all listener have been setting up, its not used anymore. This commit minimize the memory usage by release the ServerOptions after server has been started. Third, using ListenAndServe method block the caller, unless its running with goroutine. This change make the Start() method to be non-blocking. Server can wait for all listeners to shutting down or error using Wait().
2019-03-01all: fix warnings from linterShulhan
Most of the warnings caused by update to linter which cause global variables declared with grouping "( ... )" and that has been suppressed, are become false-positive again.
2019-01-28lib/dns: remove request poolShulhan
Using request pooling just make the implementation a little bit complex. Implementator must know that request need to be release by using FreeRequest to minimize memory allocation.
2019-01-28lib/dns: change the port number on testShulhan
The previous port number, 5353, is used by another program, which make the test run failed. The new port number is 5300.
2018-11-30all: minimize and suppress linter warnings for global variablesShulhan
2018-11-29all: fix warnings from lintersShulhan
2018-09-27lib/dns: add field Kind to requestShulhan
The kind value indicate from which connection the request is coming from. If Kind is UDP, Sender and UDPAddr must be non nil. If Kind is TCP, Sender must be non nil If Kind is DoH, both Sender and UDPAddr must be nil and ResponseWriter and ChanResponded must be non nil and initialized.
2018-09-27lib/dns: reimplement request pooling for serverShulhan
Previously, we have request pooling but it does not work well (causing data race) when handling DoH request. This commit reimplement them back by adding http ResponseWriter and a channel to notify response has been written, to request fields.
2018-09-26lib/dns: use debug packageShulhan
2018-09-25lib/dns: remove request poolingShulhan
Since implementation of DNS over HTTP, the request contains channel for waiting response from DNS server. The channel message cause data race due to request can be closed on the other side (handler of DNS request). For temporary fix, we disable request pooling until we found the simple way to manage DoH response.
2018-09-25lib/dns: add delay after running test serverShulhan
This is to prevent flaky test on DoH where server is not ready but the test already run in parallel.
2018-09-25lib/dns: add type server options to configure serverShulhan
Since we have three mode for server now (UDP, TCP, DoH), more parameters were added to ListenAndServe. To simplify this we use server options with struct that can be passed directly to ListenAndServer.
2018-09-25lib/dns: implement client and server for DNS over HTTPSShulhan
The implementation is based on latest draft [1]. [1] https://tools.ietf.org/html/draft-ietf-doh-dns-over-https-14
2018-09-05lib/dns: add test for empty answerShulhan
2018-09-05lib/dns: export RDataText valueShulhan
2018-09-05lib/dns: remove ResponseShulhan
Let the client handle how to manage response.
2018-09-03lib/dns: rename method for marshal/unmarshal to Pack/UnpackShulhan
We try to follow Go encoding package conventions, but the BinaryUnmarshaler interface notation does not make sense in our case, where packet is already existed in message itself.
2018-08-24[test] lib/dns: remove sleep and set log flag to microsecondsShulhan
2018-08-24lib/dns: add interface for sender, receiver, and clientShulhan
2018-08-23lib/dns: Implement DNS server with handlerShulhan