commit 981caf61355876ee9b99b19201a3f96fc1298048
parent 57fb6208d110d21a5b5ae5bfd0dcc6939e516d03
Author: parazyd <parazyd@dyne.org>
Date: Mon, 11 Dec 2017 22:44:24 +0100
Add more test cases
1) Valid message and signature, but the signature does not match the
message.
2) Invalid signature. It is not base64.
Diffstat:
1 file changed, 47 insertions(+), 1 deletion(-)
diff --git a/cmd/dam-dir/main_test.go b/cmd/dam-dir/main_test.go
@@ -8,7 +8,7 @@ import (
"net/http"
"os"
//"os/exec"
- //"strings"
+ "strings"
//"syscall"
"testing"
//"time"
@@ -197,6 +197,52 @@ func TestInvalidAddressFirst(t *testing.T) {
}
}
+func TestInvalidMessageFirst(t *testing.T) {
+ t.SkipNow()
+ // Valid message and signature, but the signature did not sign this message.
+ vals := ValidFirst
+ vals["message"] = "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 == "Request is not valid." {
+ t.Log("Server replied:", m.Secret)
+ } else {
+ t.Fatal("Server replied:", m.Secret)
+ }
+}
+
+func TestInvalidSignatureFirst(t *testing.T) {
+ t.SkipNow()
+ // Invalid signature format.
+ vals := ValidFirst
+ vals["signature"] = "ThisIsNotBase64=="
+ 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 strings.HasPrefix(m.Secret, "illegal base64 data at input byte ") {
+ 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}