From 8510dbad05a07b3257e06de2be5b7a2a63e54937 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 12 Feb 2016 15:35:26 -0500 Subject: [PATCH] Verify that nonces are non-empty in tests --- http/sys_generate_root_test.go | 21 ++++++++++++++------- http/sys_rekey_test.go | 13 +++++++++++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/http/sys_generate_root_test.go b/http/sys_generate_root_test.go index 8f554bb7e..865c74857 100644 --- a/http/sys_generate_root_test.go +++ b/http/sys_generate_root_test.go @@ -32,10 +32,10 @@ func TestSysGenerateRootAttempt_Status(t *testing.T) { "complete": false, "encoded_root_token": "", "pgp_fingerprint": "", + "nonce": "", } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) - expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) } @@ -69,6 +69,9 @@ func TestSysGenerateRootAttempt_Setup_OTP(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) @@ -87,6 +90,9 @@ func TestSysGenerateRootAttempt_Setup_OTP(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) @@ -117,6 +123,9 @@ func TestSysGenerateRootAttempt_Setup_PGP(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) @@ -150,11 +159,13 @@ func TestSysGenerateRootAttempt_Cancel(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) } - initialNonce := expected["nonce"].(string) resp = testHttpDelete(t, token, addr+"/v1/sys/generate-root/attempt") testResponseStatus(t, resp, 204) @@ -172,17 +183,13 @@ func TestSysGenerateRootAttempt_Cancel(t *testing.T) { "complete": false, "encoded_root_token": "", "pgp_fingerprint": "", + "nonce": "", } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) - expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) } - - if expected["nonce"].(string) == initialNonce { - t.Fatalf("Same nonce detected across two invocations") - } } func TestSysGenerateRoot_badKey(t *testing.T) { diff --git a/http/sys_rekey_test.go b/http/sys_rekey_test.go index c375cc9e8..dac0d2fb9 100644 --- a/http/sys_rekey_test.go +++ b/http/sys_rekey_test.go @@ -29,10 +29,10 @@ func TestSysRekeyInit_Status(t *testing.T) { "required": float64(1), "pgp_fingerprints": interface{}(nil), "backup": false, + "nonce": "", } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) - expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) } @@ -62,6 +62,9 @@ func TestSysRekeyInit_Setup(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) @@ -81,6 +84,12 @@ func TestSysRekeyInit_Setup(t *testing.T) { } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } + if actual["nonce"].(string) == "" { + t.Fatalf("nonce was empty") + } expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) @@ -116,10 +125,10 @@ func TestSysRekeyInit_Cancel(t *testing.T) { "required": float64(1), "pgp_fingerprints": interface{}(nil), "backup": false, + "nonce": "", } testResponseStatus(t, resp, 200) testResponseBody(t, resp, &actual) - expected["nonce"] = actual["nonce"] if !reflect.DeepEqual(actual, expected) { t.Fatalf("\nexpected: %#v\nactual: %#v", expected, actual) }