github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/dns/resolver/resolve_test.go (about)

     1  package dns
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/base64"
     6  	"fmt"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestXxx(t *testing.T) {
    12  	domain := "www.google.com."
    13  	for i := strings.IndexByte(domain, '.'); i != -1; i = strings.IndexByte(domain, '.') {
    14  		fmt.Println(domain[:i], i)
    15  		domain = domain[i+1:]
    16  	}
    17  }
    18  
    19  func TestReader(t *testing.T) {
    20  	domain := "www.google.com."
    21  
    22  	b := bytes.NewBuffer(nil)
    23  	for i := strings.IndexByte(domain, '.'); i != -1; i = strings.IndexByte(domain, '.') {
    24  		b.WriteByte(byte(i))
    25  		b.WriteString(domain[:i])
    26  		domain = domain[i+1:]
    27  	}
    28  	b.WriteByte(0)
    29  	b.WriteByte(192)
    30  	b.WriteByte(0)
    31  
    32  	t.Log(b.Bytes())
    33  
    34  	r := newReader(b.Bytes())
    35  
    36  	t.Log(r.domain(r.r))
    37  	t.Log(r.r.Bytes())
    38  	t.Log(r.domain(r.r))
    39  
    40  }
    41  
    42  func TestResolve(t *testing.T) {
    43  	req := []byte{46, 230, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 7, 98, 114, 111, 119, 115, 101, 114, 4, 112, 105, 112, 101, 4, 97, 114, 105, 97, 9, 109, 105, 99, 114, 111, 115, 111, 102, 116, 3, 99, 111, 109, 0, 0, 1, 0, 1, 0, 0, 41, 16, 0, 0, 0, 0, 0, 0, 12, 0, 8, 0, 8, 0, 1, 22, 0, 223, 5, 4, 0}
    44  	ans := []byte{46, 230, 129, 128, 0, 1, 0, 3, 0, 0, 0, 1, 7, 98, 114, 111, 119, 115, 101, 114, 4, 112, 105, 112, 101, 4, 97, 114, 105, 97, 9, 109, 105, 99, 114, 111, 115, 111, 102, 116, 3, 99, 111, 109, 0, 0, 1, 0, 1, 192, 12, 0, 5, 0, 1, 0, 0, 13, 58, 0, 40, 7, 98, 114, 111, 119, 115, 101, 114, 6, 101, 118, 101, 110, 116, 115, 4, 100, 97, 116, 97, 14, 116, 114, 97, 102, 102, 105, 99, 109, 97, 110, 97, 103, 101, 114, 3, 110, 101, 116, 0, 192, 61, 0, 5, 0, 1, 0, 0, 0, 43, 0, 32, 20, 115, 107, 121, 112, 101, 100, 97, 116, 97, 112, 114, 100, 99, 111, 108, 99, 117, 115, 49, 50, 8, 99, 108, 111, 117, 100, 97, 112, 112, 192, 96, 192, 113, 0, 1, 0, 1, 0, 0, 0, 6, 0, 4, 13, 89, 202, 241, 0, 0, 41, 16, 0, 0, 0, 0, 0, 0, 0}
    45  
    46  	t.Log(Resolve(req, ans))
    47  }
    48  
    49  func TestResolveBit(t *testing.T) {
    50  	t.Log(0b10000001)
    51  	t.Log(fmt.Sprintf("%08b", 0b00000011)[4:])
    52  }
    53  
    54  func TestDohGetUrl(t *testing.T) {
    55  	t.Log(base64.URLEncoding.EncodeToString(creatRequest("www.example.com", A, false)))
    56  	t.Log(base64.URLEncoding.EncodeToString(creatRequest("www.google.com", A, false)))
    57  	t.Log(base64.URLEncoding.EncodeToString(creatRequest("a.62characterlabel-makes-base64url-distinct-from-standard-base64.example.com", A, false)))
    58  }