11package challtestsrv
22
33import (
4- "strings "
4+ "github.com/miekg/dns "
55)
66
77// SetDefaultDNSIPv4 sets the default IPv4 address used for A query responses
@@ -43,9 +43,7 @@ func (s *ChallSrv) GetDefaultDNSIPv6() string {
4343func (s * ChallSrv ) AddDNSARecord (host string , addresses []string ) {
4444 s .challMu .Lock ()
4545 defer s .challMu .Unlock ()
46- if ! strings .HasSuffix (host , "." ) {
47- host = host + "."
48- }
46+ host = dns .Fqdn (host )
4947 s .dnsMocks .aRecords [host ] = append (s .dnsMocks .aRecords [host ], addresses ... )
5048}
5149
@@ -54,19 +52,15 @@ func (s *ChallSrv) AddDNSARecord(host string, addresses []string) {
5452func (s * ChallSrv ) DeleteDNSARecord (host string ) {
5553 s .challMu .Lock ()
5654 defer s .challMu .Unlock ()
57- if ! strings .HasSuffix (host , "." ) {
58- host = host + "."
59- }
55+ host = dns .Fqdn (host )
6056 delete (s .dnsMocks .aRecords , host )
6157}
6258
6359// GetDNSARecord returns a slice of IPv4 addresses (in string form) that will be
6460// returned when querying for A records for the given host.
6561func (s * ChallSrv ) GetDNSARecord (host string ) []string {
6662 s .challMu .RLock ()
67- if ! strings .HasSuffix (host , "." ) {
68- host = host + "."
69- }
63+ host = dns .Fqdn (host )
7064 defer s .challMu .RUnlock ()
7165 return s .dnsMocks .aRecords [host ]
7266}
@@ -76,9 +70,7 @@ func (s *ChallSrv) GetDNSARecord(host string) []string {
7670func (s * ChallSrv ) AddDNSAAAARecord (host string , addresses []string ) {
7771 s .challMu .Lock ()
7872 defer s .challMu .Unlock ()
79- if ! strings .HasSuffix (host , "." ) {
80- host = host + "."
81- }
73+ host = dns .Fqdn (host )
8274 s .dnsMocks .aaaaRecords [host ] = append (s .dnsMocks .aaaaRecords [host ], addresses ... )
8375}
8476
@@ -87,9 +79,7 @@ func (s *ChallSrv) AddDNSAAAARecord(host string, addresses []string) {
8779func (s * ChallSrv ) DeleteDNSAAAARecord (host string ) {
8880 s .challMu .Lock ()
8981 defer s .challMu .Unlock ()
90- if ! strings .HasSuffix (host , "." ) {
91- host = host + "."
92- }
82+ host = dns .Fqdn (host )
9383 delete (s .dnsMocks .aaaaRecords , host )
9484}
9585
@@ -98,9 +88,7 @@ func (s *ChallSrv) DeleteDNSAAAARecord(host string) {
9888func (s * ChallSrv ) GetDNSAAAARecord (host string ) []string {
9989 s .challMu .RLock ()
10090 defer s .challMu .RUnlock ()
101- if ! strings .HasSuffix (host , "." ) {
102- host = host + "."
103- }
91+ host = dns .Fqdn (host )
10492 return s .dnsMocks .aaaaRecords [host ]
10593}
10694
@@ -109,9 +97,7 @@ func (s *ChallSrv) GetDNSAAAARecord(host string) []string {
10997func (s * ChallSrv ) AddDNSCAARecord (host string , policies []MockCAAPolicy ) {
11098 s .challMu .Lock ()
11199 defer s .challMu .Unlock ()
112- if ! strings .HasSuffix (host , "." ) {
113- host = host + "."
114- }
100+ host = dns .Fqdn (host )
115101 s .dnsMocks .caaRecords [host ] = append (s .dnsMocks .caaRecords [host ], policies ... )
116102}
117103
@@ -120,9 +106,7 @@ func (s *ChallSrv) AddDNSCAARecord(host string, policies []MockCAAPolicy) {
120106func (s * ChallSrv ) DeleteDNSCAARecord (host string ) {
121107 s .challMu .Lock ()
122108 defer s .challMu .Unlock ()
123- if ! strings .HasSuffix (host , "." ) {
124- host = host + "."
125- }
109+ host = dns .Fqdn (host )
126110 delete (s .dnsMocks .caaRecords , host )
127111}
128112
@@ -131,8 +115,6 @@ func (s *ChallSrv) DeleteDNSCAARecord(host string) {
131115func (s * ChallSrv ) GetDNSCAARecord (host string ) []MockCAAPolicy {
132116 s .challMu .RLock ()
133117 defer s .challMu .RUnlock ()
134- if ! strings .HasSuffix (host , "." ) {
135- host = host + "."
136- }
118+ host = dns .Fqdn (host )
137119 return s .dnsMocks .caaRecords [host ]
138120}
0 commit comments