2015-12-06 05:00:10 -05:00
|
|
|
package dns_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/app/dns"
|
2015-12-10 17:55:39 -05:00
|
|
|
apptesting "github.com/v2ray/v2ray-core/app/testing"
|
2015-12-06 05:00:10 -05:00
|
|
|
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
2016-01-15 09:23:12 -05:00
|
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
2015-12-06 05:00:10 -05:00
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDnsAdd(t *testing.T) {
|
|
|
|
v2testing.Current(t)
|
|
|
|
|
|
|
|
domain := "v2ray.com"
|
2016-01-15 09:23:12 -05:00
|
|
|
cache := dns.NewCache(&dns.CacheConfig{
|
|
|
|
TrustedTags: map[serial.StringLiteral]bool{
|
|
|
|
serial.StringLiteral("testtag"): true,
|
2015-12-11 06:08:07 -05:00
|
|
|
},
|
|
|
|
})
|
2015-12-10 17:55:39 -05:00
|
|
|
ip := cache.Get(&apptesting.Context{}, domain)
|
2015-12-06 05:00:10 -05:00
|
|
|
netassert.IP(ip).IsNil()
|
|
|
|
|
2015-12-11 06:08:07 -05:00
|
|
|
cache.Add(&apptesting.Context{CallerTagValue: "notvalidtag"}, domain, []byte{1, 2, 3, 4})
|
|
|
|
ip = cache.Get(&apptesting.Context{}, domain)
|
|
|
|
netassert.IP(ip).IsNil()
|
|
|
|
|
|
|
|
cache.Add(&apptesting.Context{CallerTagValue: "testtag"}, domain, []byte{1, 2, 3, 4})
|
2015-12-10 17:55:39 -05:00
|
|
|
ip = cache.Get(&apptesting.Context{}, domain)
|
2015-12-06 05:00:10 -05:00
|
|
|
netassert.IP(ip).Equals(net.IP([]byte{1, 2, 3, 4}))
|
|
|
|
}
|