(t *testing.T, tester shellTester)
| 144 | } |
| 145 | |
| 146 | func testIntegrationWithNewDevice(t *testing.T, tester shellTester) { |
| 147 | // Set up |
| 148 | defer testutils.BackupAndRestore(t)() |
| 149 | |
| 150 | // Run the test |
| 151 | userSecret := testBasicUserFlow(t, tester, Online) |
| 152 | |
| 153 | // Install it again |
| 154 | testutils.ResetLocalState(t) |
| 155 | installHishtory(t, tester, userSecret) |
| 156 | |
| 157 | // Querying should show the history from the previous run |
| 158 | out := tester.RunInteractiveShell(t, `hishtory query`) |
| 159 | expected := []string{"echo thisisrecorded", "hishtory enable", "echo bar", "echo foo", "ls /foo", "ls /bar", "ls /a"} |
| 160 | for _, item := range expected { |
| 161 | require.Contains(t, out, item) |
| 162 | if strings.Count(out, item) != 1 { |
| 163 | t.Fatalf("output has %#v in it multiple times! out=%#v", item, out) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | tester.RunInteractiveShell(t, "echo mynewcommand") |
| 168 | out = hishtoryQuery(t, tester, "") |
| 169 | require.Contains(t, out, "echo mynewcommand") |
| 170 | if strings.Count(out, "echo mynewcommand") != 1 { |
| 171 | t.Fatalf("output has `echo mynewcommand` the wrong number of times") |
| 172 | } |
| 173 | |
| 174 | // Install it a 3rd time |
| 175 | testutils.ResetLocalState(t) |
| 176 | installHishtory(t, tester, "adifferentsecret") |
| 177 | |
| 178 | // Run a command that shouldn't be in the hishtory later on |
| 179 | tester.RunInteractiveShell(t, `echo notinthehistory`) |
| 180 | out = hishtoryQuery(t, tester, "") |
| 181 | require.Contains(t, out, "echo notinthehistory") |
| 182 | require.NotContains(t, out, "mynewcommand") |
| 183 | require.NotContains(t, out, "thisisrecorded") |
| 184 | |
| 185 | // Set the secret key to the previous secret key |
| 186 | out, err := tester.RunInteractiveShellRelaxed(t, ` export HISHTORY_SKIP_INIT_IMPORT=1 |
| 187 | yes | hishtory init `+userSecret) |
| 188 | require.NoError(t, err) |
| 189 | require.Contains(t, out, "Setting secret hishtory key to "+userSecret, "Failed to re-init with the user secret") |
| 190 | |
| 191 | // Querying shouldn't show the entry from the previous account |
| 192 | out = hishtoryQuery(t, tester, "") |
| 193 | require.NotContains(t, out, "notinthehistory", "output contains the unexpected item: notinthehistory") |
| 194 | |
| 195 | // And it should show the history from the previous run on this account |
| 196 | expected = []string{"echo thisisrecorded", "echo mynewcommand", "hishtory enable", "echo bar", "echo foo", "ls /foo", "ls /bar", "ls /a"} |
| 197 | for _, item := range expected { |
| 198 | require.Contains(t, out, item, "output is missing expected item") |
| 199 | if strings.Count(out, item) != 1 { |
| 200 | t.Fatalf("output has %#v in it multiple times! out=%#v", item, out) |
| 201 | } |
| 202 | } |
| 203 |
no test coverage detected