tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit 4a243dbcda09078c75236333aa81479e614b6968
parent 16efc093cb29433c52d3a1bfca018883c07f466a
Author: parazyd <parazyd@dyne.org>
Date:   Mon, 11 Dec 2017 22:32:44 +0100

Test case for invalid nodetype

Diffstat:
Mcmd/dam-dir/main.go | 5+++++
Mcmd/dam-dir/main_test.go | 22++++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go @@ -92,6 +92,11 @@ func handlePost(rw http.ResponseWriter, request *http.Request) { case "directory": log.Println("Client of type:", n.Nodetype) default: + log.Println("Invalid nodetype:", n.Nodetype) + ret = map[string]string{"secret": "Invalid nodetype."} + if err := postback(rw, ret, 400); err != nil { + lib.CheckError(err) + } return } diff --git a/cmd/dam-dir/main_test.go b/cmd/dam-dir/main_test.go @@ -61,6 +61,7 @@ func firstAnnValid() (*http.Response, error) { } func TestValidFirstHandshake(t *testing.T) { + t.SkipNow() resp, err := firstAnnValid() if err != nil { t.Fatal(err) @@ -91,6 +92,7 @@ func TestValidFirstHandshake(t *testing.T) { } func TestValidSecondHandshake(t *testing.T) { + t.SkipNow() resp, err := firstAnnValid() if err != nil { t.Fatal(err) @@ -151,6 +153,26 @@ func TestValidSecondHandshake(t *testing.T) { } } +func TestInvalidNodetypeFirst(t *testing.T) { + vals := ValidFirst + vals["nodetype"] = "foobar" + resp, err := postReq(vals) + if err != nil { + t.Fatal(err) + } + if resp.StatusCode != 400 { + t.Fatal("Server did not respond with HTTP 400") + } + m, err := getRespText(resp) + if err != nil { + t.Fatal(err) + } + if m.Secret == "Invalid nodetype." { + t.Log("Server replied:", m.Secret) + } else { + t.Fatal("Server replied:", m.Secret) + } +} func TestMain(m *testing.M) { //cmd := exec.Command("./dam-dir") //cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}