Skip to content

Commit 542754a

Browse files
committed
fixed build issues
1 parent b7f4f1d commit 542754a

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/sonic-py-common/tests/test_security_cipher.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@
1515
else:
1616
BUILTINS = "__builtin__"
1717

18-
EXPECTED_PASSWD = "TEST2"
18+
DEFAULT_FILE = [
19+
"#Auto generated file for storing the encryption passwords",
20+
"TACPLUS : ",
21+
"RADIUS : ",
22+
"LDAP :"
23+
]
24+
25+
UPDATED_FILE = [
26+
"#Auto generated file for storing the encryption passwords",
27+
"TACPLUS : ",
28+
"RADIUS : TEST2",
29+
"LDAP :"
30+
]
31+
1932

2033
class TestSecurityCipher(object):
2134
def test_passkey_encryption(self):
@@ -25,6 +38,9 @@ def test_passkey_encryption(self):
2538

2639
# Use patch to replace the built-in 'open' function with a mock
2740
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
41+
mock_fd = mock.MagicMock()
42+
mock_fd.readlines = mock.MagicMock(return_value=DEFAULT_FILE)
43+
mock_file.return_value.__enter__.return_value = mock_fd
2844
encrypt, err = temp.encrypt_passkey("TACPLUS", "passkey1", "TEST1")
2945
assert encrypt != "passkey1"
3046
assert err == None
@@ -36,11 +52,18 @@ def test_passkey_decryption(self):
3652

3753
# Use patch to replace the built-in 'open' function with a mock
3854
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
39-
encrypt, err = temp.encrypt_passkey("RADIUS", "passkey2", EXPECTED_PASSWD)
55+
mock_fd = mock.MagicMock()
56+
mock_fd.readlines = mock.MagicMock(return_value=DEFAULT_FILE)
57+
mock_file.return_value.__enter__.return_value = mock_fd
58+
encrypt, err = temp.encrypt_passkey("RADIUS", "passkey2", "TEST2")
4059
assert err == None
4160

4261
# Use patch to replace the built-in 'open' function with a mock
43-
with mock.patch("{}.open".format(BUILTINS), mock.mock_open(read_data=EXPECTED_PASSWD)) as mock_file:
62+
#with mock.patch("{}.open".format(BUILTINS), mock.mock_open(read_data=EXPECTED_PASSWD)) as mock_file:
63+
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
64+
mock_fd = mock.MagicMock()
65+
mock_fd.readlines = mock.MagicMock(return_value=UPDATED_FILE)
66+
mock_file.return_value.__enter__.return_value = mock_fd
4467
decrypt, err = temp.decrypt_passkey("RADIUS", encrypt)
4568
assert err == None
4669
assert decrypt == "passkey2"

0 commit comments

Comments
 (0)