From b430be08ed1099eee193b76d8b3d5eca2848980a Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Tue, 14 Dec 2021 17:03:56 -0500 Subject: [PATCH] Ensures that payload is built correctly --- decryptor/reaper_test.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/decryptor/reaper_test.go b/decryptor/reaper_test.go index db70414d..a9807638 100644 --- a/decryptor/reaper_test.go +++ b/decryptor/reaper_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "io/ioutil" "net/http" "net/http/httptest" "testing" @@ -30,6 +31,7 @@ func TestDecryptArguments_NoneEncrypted(t *testing.T) { } func TestDecryptArguments_EncryptedArgsDecoded(t *testing.T) { + commandExecutorId := "7777" encryptedKey := "zzzzzzz" decryptedKey := "aaaaaaa" firstArg := fmt.Sprintf("--arg1=OC_ENCRYPTED%sDETPYRCNE_CO", encryptedKey) @@ -41,6 +43,30 @@ func TestDecryptArguments_EncryptedArgsDecoded(t *testing.T) { w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") + reqBytes, err := ioutil.ReadAll(r.Body) + if err != nil { + t.Errorf("error reading test request: %s", err) + t.FailNow() + } + + var reqObj map[string]interface{} + err = json.Unmarshal(reqBytes, &reqObj) + if err != nil { + t.Errorf("error parsing test request JSON: %s", err) + t.FailNow() + } + + foundId, ok := reqObj["commandExecutorId"] + if !ok { + t.Error("request should contain commandExecutorId") + t.FailNow() + } + + if foundId.(string) != commandExecutorId { + t.Errorf("request should contain commandExecutorId %s, got %s", commandExecutorId, foundId.(string)) + t.FailNow() + } + payloadObj := make(map[string]interface{}) dataObj := make(map[string]interface{}) dataObj["arguments"] = []string{decryptedArg, secondArg} @@ -57,7 +83,7 @@ func TestDecryptArguments_EncryptedArgsDecoded(t *testing.T) { })) defer reaperTestServer.Close() - dec := NewReaperDecryptor(reaperTestServer.URL, string(generateNonce()), "1234") + dec := NewReaperDecryptor(reaperTestServer.URL, string(generateNonce()), commandExecutorId) decryptedArgs, err := dec.DecryptArguments(args) if err != nil { t.Error("EncryptedArgsDecoded should not return an error")