-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_secret_store.py
56 lines (42 loc) · 1.5 KB
/
test_secret_store.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sqlite3
import pytest
from exasol.secret_store import (
InvalidPassword,
Secrets,
)
def test_no_database_file(secrets):
assert not secrets.db_file.exists()
def test_database_file_created(secrets):
assert secrets.get("any_key") is None
assert secrets.db_file.exists()
def test_value(secrets):
value = "my value"
secrets.save("key", value).close()
assert secrets.get("key") == value
def test_update(secrets):
initial = "initial value"
secrets.save("key", initial).close()
other = "other value"
secrets.save("key", other).close()
assert secrets.get("key") == other
def test_wrong_password(sample_file):
secrets = Secrets(sample_file, "correct password")
secrets.save("key", "my value").close()
invalid = Secrets(sample_file, "wrong password")
with pytest.raises(InvalidPassword) as ex:
invalid.get("key")
assert "master password is incorrect" in str(ex.value)
def test_plain_access_fails(sample_file):
"""
This test sets up a secret store, secured by a master password and
verifies that plain access to the secret store using sqlite3 without
encryption raises a DatabaseError.
"""
secrets = Secrets(sample_file, "correct password")
secrets.save("key", "my value").close()
con = sqlite3.connect(sample_file)
cur = con.cursor()
with pytest.raises(sqlite3.DatabaseError) as ex:
cur.execute("SELECT * FROM sqlite_master")
cur.close()
assert str(ex.value) == "file is not a database"