[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [goptlib/master] Add tests for extOrPortSendUserAddr.
commit 25b94879100ca5416a10c7285e3195d2691e4faf
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Tue Nov 26 22:46:12 2013 -0800
Add tests for extOrPortSendUserAddr.
---
pt_test.go | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/pt_test.go b/pt_test.go
index 1201e8a..cd9c280 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -2,6 +2,7 @@ package pt
import (
"bytes"
+ "encoding/binary"
"fmt"
"io/ioutil"
"net"
@@ -431,3 +432,41 @@ func TestExtOrSendCommand(t *testing.T) {
}
}
}
+
+func TestExtOrSendUserAddr(t *testing.T) {
+ addrs := [...]net.TCPAddr{
+ net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: 0},
+ net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 9999},
+ net.TCPAddr{IP: net.ParseIP("255.255.255.255"), Port: 65535},
+ net.TCPAddr{IP: net.ParseIP("::"), Port: 0},
+ net.TCPAddr{IP: net.ParseIP("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"), Port: 65535},
+ }
+
+ for _, addr := range addrs {
+ var buf bytes.Buffer
+ err := extOrPortSendUserAddr(&buf, &addr)
+ if err != nil {
+ t.Errorf("%s unexpectedly returned an error: %s", addr, err)
+ }
+ var cmd, length uint16
+ binary.Read(&buf, binary.BigEndian, &cmd)
+ if cmd != extOrCmdUserAddr {
+ t.Errorf("%s â?? cmd 0x%04x (expected 0x%04x)", addr, cmd, extOrCmdUserAddr)
+ }
+ binary.Read(&buf, binary.BigEndian, &length)
+ p := make([]byte, length+1)
+ n, err := buf.Read(p)
+ if n != int(length) {
+ t.Errorf("%s said length %d but had at least %d", addr, length, n)
+ }
+ // test that parsing the address gives something equivalent to
+ // the original.
+ outputAddr, err := resolveAddr(string(p))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !tcpAddrsEqual(&addr, outputAddr) {
+ t.Errorf("%s â?? %s", addr, outputAddr)
+ }
+ }
+}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits