2
0

dns_server_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package nebula
  2. import (
  3. "testing"
  4. "github.com/miekg/dns"
  5. "github.com/slackhq/nebula/config"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestParsequery(t *testing.T) {
  9. //TODO: This test is basically pointless
  10. hostMap := &HostMap{}
  11. ds := newDnsRecords(hostMap)
  12. ds.Add("test.com.com", "1.2.3.4")
  13. m := new(dns.Msg)
  14. m.SetQuestion("test.com.com", dns.TypeA)
  15. //parseQuery(m)
  16. }
  17. func Test_getDnsServerAddr(t *testing.T) {
  18. c := config.NewC(nil)
  19. c.Settings["lighthouse"] = map[interface{}]interface{}{
  20. "dns": map[interface{}]interface{}{
  21. "host": "0.0.0.0",
  22. "port": "1",
  23. },
  24. }
  25. assert.Equal(t, "0.0.0.0:1", getDnsServerAddr(c))
  26. c.Settings["lighthouse"] = map[interface{}]interface{}{
  27. "dns": map[interface{}]interface{}{
  28. "host": "::",
  29. "port": "1",
  30. },
  31. }
  32. assert.Equal(t, "[::]:1", getDnsServerAddr(c))
  33. c.Settings["lighthouse"] = map[interface{}]interface{}{
  34. "dns": map[interface{}]interface{}{
  35. "host": "[::]",
  36. "port": "1",
  37. },
  38. }
  39. assert.Equal(t, "[::]:1", getDnsServerAddr(c))
  40. // Make sure whitespace doesn't mess us up
  41. c.Settings["lighthouse"] = map[interface{}]interface{}{
  42. "dns": map[interface{}]interface{}{
  43. "host": "[::] ",
  44. "port": "1",
  45. },
  46. }
  47. assert.Equal(t, "[::]:1", getDnsServerAddr(c))
  48. }