mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-25 15:54:43 +00:00
Cypress: two new tests --> IgnoredUserAgents and RegexMasking (#663)
This commit is contained in:
parent
acf3894824
commit
cc4638afe6
@ -4,17 +4,19 @@
|
|||||||
"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/Redact.js",
|
||||||
"tests/Redact.js",
|
|
||||||
"tests/NoRedact.js",
|
"tests/NoRedact.js",
|
||||||
"tests/Regex.js"],
|
"tests/Regex.js",
|
||||||
|
"tests/RegexMasking.js"
|
||||||
|
],
|
||||||
|
|
||||||
"env": {
|
"env": {
|
||||||
"testUrl": "http://localhost:8899/",
|
"testUrl": "http://localhost:8899/",
|
||||||
"redactHeaderContent": "User-Header[REDACTED]",
|
"redactHeaderContent": "User-Header[REDACTED]",
|
||||||
"redactBodyContent": "{ \"User\": \"[REDACTED]\" }"
|
"redactBodyContent": "{ \"User\": \"[REDACTED]\" }",
|
||||||
|
"regexMaskingBodyContent": "[REDACTED]"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"watchForFileChanges":false,
|
||||||
|
"viewportWidth": 1920,
|
||||||
|
"viewportHeight": 3500,
|
||||||
|
"video": false,
|
||||||
|
"screenshotOnRunFailure": false,
|
||||||
|
"testFiles": [
|
||||||
|
"tests/IgnoredUserAgents.js"
|
||||||
|
],
|
||||||
|
|
||||||
|
"env": {
|
||||||
|
"testUrl": "http://localhost:8899/"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
import {isValueExistsInElement} from "../testHelpers/TrafficHelper";
|
||||||
|
|
||||||
|
it('Loading Mizu', function () {
|
||||||
|
cy.visit(Cypress.env('testUrl'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('going through each entry', function () {
|
||||||
|
cy.get('#total-entries').then(number => {
|
||||||
|
const getNum = () => {
|
||||||
|
const numOfEntries = number.text();
|
||||||
|
return parseInt(numOfEntries);
|
||||||
|
};
|
||||||
|
cy.wrap({ there: getNum }).invoke('there').should('be.gte', 25);
|
||||||
|
|
||||||
|
checkThatAllEntriesShown();
|
||||||
|
|
||||||
|
const entriesNum = getNum();
|
||||||
|
[...Array(entriesNum).keys()].map(checkEntry);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function checkThatAllEntriesShown() {
|
||||||
|
cy.get('#entries-length').then(number => {
|
||||||
|
if (number.text() === '1')
|
||||||
|
cy.get('[title="Fetch old records"]').click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkEntry(entryIndex) {
|
||||||
|
cy.get(`#entry-${entryIndex}`).click();
|
||||||
|
cy.get('#tbody-Headers').should('be.visible');
|
||||||
|
isValueExistsInElement(false, 'Ignored-User-Agent', '#tbody-Headers');
|
||||||
|
}
|
@ -15,4 +15,3 @@ function doItFunc(number) {
|
|||||||
findLineAndCheck(getExpectedDetailsDict(podName, namespace));
|
findLineAndCheck(getExpectedDetailsDict(podName, namespace));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
import {isValueExistsInElement} from "../testHelpers/TrafficHelper";
|
||||||
|
|
||||||
|
it('Loading Mizu', function () {
|
||||||
|
cy.visit(Cypress.env('testUrl'));
|
||||||
|
})
|
||||||
|
|
||||||
|
isValueExistsInElement(true, Cypress.env('regexMaskingBodyContent'), '.hljs');
|
@ -138,7 +138,7 @@ func TestTapGuiPort(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/GuiPort.js\" --env port=%d", guiPort))
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/GuiPort.js\" --env port=%d --config-file cypress/integration/configurations/Default.json", guiPort))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ func TestTapAllNamespaces(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/MultipleNamespaces.js\" --env name1=%v,name2=%v,name3=%v,namespace1=%v,namespace2=%v,namespace3=%v",
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/MultipleNamespaces.js\" --env name1=%v,name2=%v,name3=%v,namespace1=%v,namespace2=%v,namespace3=%v --config-file cypress/integration/configurations/Default.json",
|
||||||
expectedPods[0].Name, expectedPods[1].Name, expectedPods[2].Name, expectedPods[0].Namespace, expectedPods[1].Namespace, expectedPods[2].Namespace))
|
expectedPods[0].Name, expectedPods[1].Name, expectedPods[2].Name, expectedPods[0].Namespace, expectedPods[1].Namespace, expectedPods[2].Namespace))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ func TestTapMultipleNamespaces(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/MultipleNamespaces.js\" --env name1=%v,name2=%v,name3=%v,namespace1=%v,namespace2=%v,namespace3=%v",
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/MultipleNamespaces.js\" --env name1=%v,name2=%v,name3=%v,namespace1=%v,namespace2=%v,namespace3=%v --config-file cypress/integration/configurations/Default.json",
|
||||||
expectedPods[0].Name, expectedPods[1].Name, expectedPods[2].Name, expectedPods[0].Namespace, expectedPods[1].Namespace, expectedPods[2].Namespace))
|
expectedPods[0].Name, expectedPods[1].Name, expectedPods[2].Name, expectedPods[0].Namespace, expectedPods[1].Namespace, expectedPods[2].Namespace))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ func TestTapRegex(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/Regex.js\" --env name=%v,namespace=%v",
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/Regex.js\" --env name=%v,namespace=%v --config-file cypress/integration/configurations/Default.json",
|
||||||
expectedPods[0].Name, expectedPods[0].Namespace))
|
expectedPods[0].Name, expectedPods[0].Namespace))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ func TestTapRedact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/Redact.js\""))
|
runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/Redact.js\" --config-file cypress/integration/configurations/Default.json"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapNoRedact(t *testing.T) {
|
func TestTapNoRedact(t *testing.T) {
|
||||||
@ -429,7 +429,7 @@ func TestTapNoRedact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runCypressTests(t, "npx cypress run --spec \"cypress/integration/tests/NoRedact.js\"")
|
runCypressTests(t, "npx cypress run --spec \"cypress/integration/tests/NoRedact.js\" --config-file cypress/integration/configurations/Default.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapRegexMasking(t *testing.T) {
|
func TestTapRegexMasking(t *testing.T) {
|
||||||
@ -480,41 +480,8 @@ func TestTapRegexMasking(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redactCheckFunc := func() error {
|
runCypressTests(t, "npx cypress run --spec \"cypress/integration/tests/RegexMasking.js\" --config-file cypress/integration/configurations/Default.json")
|
||||||
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{})
|
|
||||||
|
|
||||||
postData := request["postData"].(map[string]interface{})
|
|
||||||
textData := postData["text"].(string)
|
|
||||||
|
|
||||||
if textData != "[REDACTED]" {
|
|
||||||
return fmt.Errorf("unexpected result - body is not redacted")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := retriesExecute(shortRetriesCount, redactCheckFunc); err != nil {
|
|
||||||
t.Errorf("%v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapIgnoredUserAgents(t *testing.T) {
|
func TestTapIgnoredUserAgents(t *testing.T) {
|
||||||
@ -575,45 +542,7 @@ func TestTapIgnoredUserAgents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoredUserAgentsCheckFunc := func() error {
|
runCypressTests(t, "npx cypress run --spec \"cypress/integration/tests/IgnoredUserAgents.js\" --config-file cypress/integration/configurations/HugeMizu.json")
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, entryInterface := range entries {
|
|
||||||
entryUrl := fmt.Sprintf("%v/entries/%v", apiServerUrl, entryInterface["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) != ignoredUserAgentCustomHeader {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("unexpected result - user agent is not ignored")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := retriesExecute(shortRetriesCount, ignoredUserAgentsCheckFunc); err != nil {
|
|
||||||
t.Errorf("%v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTapDumpLogs(t *testing.T) {
|
func TestTapDumpLogs(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user