mirror of
https://github.com/spf13/cobra
synced 2025-05-05 04:47:22 +00:00
Ensures that payload is built correctly
This commit is contained in:
parent
f927bb8b1f
commit
b430be08ed
1 changed files with 27 additions and 1 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue