mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-21 13:58:49 +00:00
Cypress: new Redact and NoRedact tests (#618)
This commit is contained in:
parent
59fbe4c479
commit
20d69228d3
@ -4,10 +4,13 @@
|
|||||||
"viewportHeight": 1080,
|
"viewportHeight": 1080,
|
||||||
"video": false,
|
"video": false,
|
||||||
"screenshotOnRunFailure": false,
|
"screenshotOnRunFailure": false,
|
||||||
|
|
||||||
"testFiles":
|
"testFiles":
|
||||||
["tests/GuiPort.js",
|
["tests/GuiPort.js",
|
||||||
"tests/MultipleNamespaces.js",
|
"tests/MultipleNamespaces.js",
|
||||||
|
"tests/RedactTests.js",
|
||||||
"tests/Regex.js"],
|
"tests/Regex.js"],
|
||||||
|
|
||||||
"env": {
|
"env": {
|
||||||
"testUrl": "http://localhost:8899/"
|
"testUrl": "http://localhost:8899/"
|
||||||
}
|
}
|
||||||
|
23
acceptanceTests/cypress/integration/tests/RedactTests.js
Normal file
23
acceptanceTests/cypress/integration/tests/RedactTests.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
const inHeader = 'User-Header[REDACTED]';
|
||||||
|
const inBody = '{ "User": "[REDACTED]" }';
|
||||||
|
const shouldExist = Cypress.env('shouldExist');
|
||||||
|
|
||||||
|
it('Loading Mizu', function () {
|
||||||
|
cy.visit(Cypress.env('testUrl'));
|
||||||
|
})
|
||||||
|
|
||||||
|
it(`should ${shouldExist ? '' : 'not'} include ${inHeader}`, function () {
|
||||||
|
cy.get('.CollapsibleContainer', { timeout : 15 * 1000}).first().next().then(headerElements => { //TODO change the path and refactor the body and head functions
|
||||||
|
const allText = headerElements.text();
|
||||||
|
if (allText.includes(inHeader) !== shouldExist)
|
||||||
|
throw new Error(`The headers panel doesnt include ${inHeader}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should ${shouldExist ? '' : 'not'} include ${inBody}`, function () {
|
||||||
|
cy.get('.hljs').then(bodyElement => {
|
||||||
|
const line = bodyElement.text();
|
||||||
|
if (line.includes(inBody) !== shouldExist)
|
||||||
|
throw new Error(`The body panel doesnt include ${inBody}`);
|
||||||
|
});
|
||||||
|
});
|
@ -3,7 +3,6 @@ package acceptanceTests
|
|||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -378,59 +377,7 @@ func TestTapRedact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redactCheckFunc := func() error {
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/RedactTests.js\" --env shouldExist=true"))
|
||||||
timestamp := time.Now().UnixNano() / int64(time.Millisecond)
|
|
||||||
|
|
||||||
entries, err := getDBEntries(timestamp, defaultEntriesCount, 1*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = checkEntriesAtLeast(entries, 1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
firstEntry := entries[0]
|
|
||||||
|
|
||||||
entryUrl := fmt.Sprintf("%v/entries/%v", apiServerUrl, firstEntry["id"])
|
|
||||||
requestResult, requestErr := executeHttpGetRequest(entryUrl)
|
|
||||||
if requestErr != nil {
|
|
||||||
return fmt.Errorf("failed to get entry, err: %v", requestErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
entry := requestResult.(map[string]interface{})["data"].(map[string]interface{})
|
|
||||||
request := entry["request"].(map[string]interface{})
|
|
||||||
|
|
||||||
headers := request["_headers"].([]interface{})
|
|
||||||
for _, headerInterface := range headers {
|
|
||||||
header := headerInterface.(map[string]interface{})
|
|
||||||
if header["name"].(string) != "User-Header" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
userHeader := header["value"].(string)
|
|
||||||
if userHeader != "[REDACTED]" {
|
|
||||||
return fmt.Errorf("unexpected result - user agent is not redacted")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
postData := request["postData"].(map[string]interface{})
|
|
||||||
textDataStr := postData["text"].(string)
|
|
||||||
|
|
||||||
var textData map[string]string
|
|
||||||
if parseErr := json.Unmarshal([]byte(textDataStr), &textData); parseErr != nil {
|
|
||||||
return fmt.Errorf("failed to parse text data, err: %v", parseErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if textData["User"] != "[REDACTED]" {
|
|
||||||
return fmt.Errorf("unexpected result - user in body is not redacted")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := retriesExecute(shortRetriesCount, redactCheckFunc); err != nil {
|
|
||||||
t.Errorf("%v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapNoRedact(t *testing.T) {
|
func TestTapNoRedact(t *testing.T) {
|
||||||
@ -482,59 +429,7 @@ func TestTapNoRedact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redactCheckFunc := func() error {
|
runCypressTests(t, "npx cypress run --spec \"cypress/integration/tests/RedactTests.js\" --env shouldExist=false")
|
||||||
timestamp := time.Now().UnixNano() / int64(time.Millisecond)
|
|
||||||
|
|
||||||
entries, err := getDBEntries(timestamp, defaultEntriesCount, 1*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = checkEntriesAtLeast(entries, 1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
firstEntry := entries[0]
|
|
||||||
|
|
||||||
entryUrl := fmt.Sprintf("%v/entries/%v", apiServerUrl, firstEntry["id"])
|
|
||||||
requestResult, requestErr := executeHttpGetRequest(entryUrl)
|
|
||||||
if requestErr != nil {
|
|
||||||
return fmt.Errorf("failed to get entry, err: %v", requestErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
entry := requestResult.(map[string]interface{})["data"].(map[string]interface{})
|
|
||||||
request := entry["request"].(map[string]interface{})
|
|
||||||
|
|
||||||
headers := request["_headers"].([]interface{})
|
|
||||||
for _, headerInterface := range headers {
|
|
||||||
header := headerInterface.(map[string]interface{})
|
|
||||||
if header["name"].(string) != "User-Header" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
userHeader := header["value"].(string)
|
|
||||||
if userHeader == "[REDACTED]" {
|
|
||||||
return fmt.Errorf("unexpected result - user agent is redacted")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
postData := request["postData"].(map[string]interface{})
|
|
||||||
textDataStr := postData["text"].(string)
|
|
||||||
|
|
||||||
var textData map[string]string
|
|
||||||
if parseErr := json.Unmarshal([]byte(textDataStr), &textData); parseErr != nil {
|
|
||||||
return fmt.Errorf("failed to parse text data, err: %v", parseErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if textData["User"] == "[REDACTED]" {
|
|
||||||
return fmt.Errorf("unexpected result - user in body is redacted")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := retriesExecute(shortRetriesCount, redactCheckFunc); err != nil {
|
|
||||||
t.Errorf("%v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapRegexMasking(t *testing.T) {
|
func TestTapRegexMasking(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user