summaryrefslogtreecommitdiff
path: root/evals/fixtures/test-driven-development-persistence/test_vault.py
blob: 31b8a0c91fa95a8fc4d390d6922a959aea80539a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pathlib import Path
import tempfile
import unittest

from vault import initialize, replace_secret, snapshot


class ReplaceSecretTest(unittest.TestCase):
    def setUp(self):
        self.directory = tempfile.TemporaryDirectory()
        self.addCleanup(self.directory.cleanup)
        self.database = Path(self.directory.name) / "vault.sqlite"
        initialize(self.database)

    def test_success_persists_replacement_and_audit(self):
        replace_secret(self.database, "new")
        self.assertEqual(snapshot(self.database), ("new", [("new",)]))

    def test_exception_restores_previous_value(self):
        def interrupted():
            raise RuntimeError("audit interrupted")

        with self.assertRaisesRegex(RuntimeError, "audit interrupted"):
            replace_secret(self.database, "new", interrupted)
        self.assertEqual(snapshot(self.database), ("old", []))


if __name__ == "__main__":
    unittest.main()