MCPcopy
hub / github.com/ddworken/hishtory / testRemoteRedaction

Function testRemoteRedaction

client/integration_test.go:1499–1552  ·  view source on GitHub ↗
(t *testing.T, tester shellTester)

Source from the content-addressed store, hash-verified

1497}
1498
1499func testRemoteRedaction(t *testing.T, tester shellTester) {
1500 // Setup
1501 defer testutils.BackupAndRestore(t)()
1502
1503 // Install hishtory client 1
1504 userSecret := installHishtory(t, tester, "")
1505
1506 // Record some commands
1507 randomCmdUuid := uuid.Must(uuid.NewRandom()).String()
1508 randomCmd := fmt.Sprintf(`echo %v-foo
1509echo %v-bas
1510echo foo
1511ls /tmp`, randomCmdUuid, randomCmdUuid)
1512 tester.RunInteractiveShell(t, randomCmd)
1513
1514 // Check that the previously recorded commands are in hishtory
1515 out := tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
1516 expectedOutput := fmt.Sprintf("echo %s-foo\necho %s-bas\necho foo\nls /tmp\n", randomCmdUuid, randomCmdUuid)
1517 if diff := cmp.Diff(expectedOutput, out); diff != "" {
1518 t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
1519 }
1520
1521 // Install hishtory client 2
1522 restoreInstall1 := testutils.BackupAndRestoreWithId(t, "-1")
1523 installHishtory(t, tester, userSecret)
1524
1525 // And confirm that it has the commands too
1526 out = tester.RunInteractiveShell(t, `hishtory export -pipefail`)
1527 if diff := cmp.Diff(expectedOutput, out); diff != "" {
1528 t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
1529 }
1530
1531 // Restore the first client, and redact some commands
1532 restoreInstall2 := testutils.BackupAndRestoreWithId(t, "-2")
1533 restoreInstall1()
1534 out = tester.RunInteractiveShell(t, `HISHTORY_REDACT_FORCE=1 hishtory redact `+randomCmdUuid)
1535 if out != "Permanently deleting 3 entries\n" {
1536 t.Fatalf("hishtory redact gave unexpected output=%#v", out)
1537 }
1538
1539 // Confirm that client1 doesn't have the commands
1540 out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
1541 expectedOutput = fmt.Sprintf("echo foo\nls /tmp\nHISHTORY_REDACT_FORCE=1 hishtory redact %s\n", randomCmdUuid)
1542 if diff := cmp.Diff(expectedOutput, out); diff != "" {
1543 t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
1544 }
1545
1546 // Swap back to the second client and then confirm it processed the deletion request
1547 restoreInstall2()
1548 out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
1549 if diff := cmp.Diff(expectedOutput, out); diff != "" {
1550 t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
1551 }
1552}
1553
1554func testConfigGetSet(t *testing.T, tester shellTester) {
1555 // Setup

Callers 1

TestParamFunction · 0.85

Calls 5

BackupAndRestoreFunction · 0.92
BackupAndRestoreWithIdFunction · 0.92
installHishtoryFunction · 0.85
StringMethod · 0.80
RunInteractiveShellMethod · 0.65

Tested by

no test coverage detected