|
11 | 11 | from juju.secrets import create_secret_data, read_secret_data |
12 | 12 |
|
13 | 13 |
|
14 | | -class TestCreateSecretData(unittest.TestCase): |
15 | | - def test_bad_key(self): |
| 14 | +class TestCreateSecretData: |
| 15 | + @pytest.mark.parametrize("keyval", ["foo", "=bar", "baz=", "f=bar", "fo=bar", "foo_bar=baz"]) |
| 16 | + def test_bad_key(self, keyval: str): |
16 | 17 | with pytest.raises(ValueError): |
17 | | - create_secret_data(["foo"]) |
18 | | - with pytest.raises(ValueError): |
19 | | - create_secret_data(["=bar"]) |
| 18 | + create_secret_data([keyval]) |
| 19 | + |
| 20 | + |
| 21 | + @pytest.mark.parametrize( |
| 22 | + "keyval,expected_key,expected_val", |
| 23 | + [ |
| 24 | + ("foo=bar", "foo", "YmFy"), |
| 25 | + ("hello=world", "hello", "d29ybGQ="), |
| 26 | + ("goodbye#base64=world", "goodbye", "world"), |
| 27 | + ("equalsign==", "equalsign", "PQ=="), |
| 28 | + ("equalsign#base64=PQ==", "equalsign", "PQ=="), |
| 29 | + ("pq-identity-theorem=P===Q", "pq-identity-theorem", "UD09PVE="), |
| 30 | + ] |
| 31 | + ) |
| 32 | + def test_goo_key_values(self, keyval: str, expected_key: str, expected_val: str): |
| 33 | + actual = create_secret_data([keyval]) |
| 34 | + expected = {expected_key: expected_val} |
| 35 | + assert actual == expected |
20 | 36 |
|
21 | | - def test_good_key_values(self): |
22 | | - self.assertDictEqual( |
23 | | - create_secret_data(["foo=bar", "hello=world", "goodbye#base64=world"]), |
24 | | - {"foo": "YmFy", "hello": "d29ybGQ=", "goodbye": "world"}, |
25 | | - ) |
26 | 37 |
|
27 | 38 | def test_key_content_too_large(self): |
28 | 39 | with pytest.raises(ValueError): |
@@ -50,15 +61,12 @@ def test_secret_key_from_file(self): |
50 | 61 |
|
51 | 62 | data = create_secret_data(["key1=value1", f"key2#file={file_path}"]) |
52 | 63 |
|
53 | | - self.assertDictEqual( |
54 | | - data, |
55 | | - { |
56 | | - "key1": "dmFsdWUx", |
57 | | - "key2": ( |
58 | | - "ICAgICAgICAgIC0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQogICAgICAgICAgTUlJRllqQ0NBMHFnQXdJQkFnSVFLYVBORDlZZ2dJRzYrak9jZ21wazNEQU5CZ2txaGtpRzl3MEJBUXNGQURBegogICAgICAgICAgTVJ3d0dnWURWUVFLRXhOc2FXNTFlR052Ym5SaGFXNWxjbk11YjNKbk1STXdFUVlEVlFRRERBcDBhVzFBWld4MwogICAgICAgICAgLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ==" |
59 | | - ), |
60 | | - }, |
61 | | - ) |
| 64 | + assert data == { |
| 65 | + "key1": "dmFsdWUx", |
| 66 | + "key2": ( |
| 67 | + "ICAgICAgICAgIC0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQogICAgICAgICAgTUlJRllqQ0NBMHFnQXdJQkFnSVFLYVBORDlZZ2dJRzYrak9jZ21wazNEQU5CZ2txaGtpRzl3MEJBUXNGQURBegogICAgICAgICAgTVJ3d0dnWURWUVFLRXhOc2FXNTFlR052Ym5SaGFXNWxjbk11YjNKbk1STXdFUVlEVlFRRERBcDBhVzFBWld4MwogICAgICAgICAgLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ==" |
| 68 | + ), |
| 69 | + } |
62 | 70 |
|
63 | 71 |
|
64 | 72 | class TestReadSecretData(unittest.TestCase): |
|
0 commit comments