|
20 | 20 | class TestSecurityCipher(object): |
21 | 21 | def test_passkey_encryption(self): |
22 | 22 | with mock.patch("sonic_py_common.security_cipher.ConfigDBConnector", new=ConfigDBConnector), \ |
23 | | - mock.patch("builtins.open",mock.mock_open()) as mock_file: |
| 23 | + mock.patch("{}.open".format(BUILTINS),mock.mock_open()) as mock_file: |
24 | 24 | temp = security_cipher() |
25 | 25 |
|
26 | 26 | # Use patch to replace the built-in 'open' function with a mock |
27 | | - with mock.patch("builtins.open", mock.mock_open()) as mock_file: |
| 27 | + with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file: |
28 | 28 | encrypt, err = temp.encrypt_passkey("TACPLUS", "passkey1", "TEST1") |
29 | 29 | assert encrypt != "passkey1" |
30 | 30 | assert err == None |
31 | 31 |
|
32 | 32 | def test_passkey_decryption(self): |
33 | 33 | with mock.patch("sonic_py_common.security_cipher.ConfigDBConnector", new=ConfigDBConnector), \ |
34 | | - mock.patch("builtins.open", mock.mock_open()) as mock_file: |
| 34 | + mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file: |
35 | 35 | temp = security_cipher() |
36 | 36 |
|
37 | 37 | # Use patch to replace the built-in 'open' function with a mock |
38 | | - with mock.patch("builtins.open", mock.mock_open()) as mock_file: |
| 38 | + with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file: |
39 | 39 | encrypt, err = temp.encrypt_passkey("RADIUS", "passkey2", EXPECTED_PASSWD) |
40 | 40 | assert err == None |
41 | 41 |
|
42 | 42 | # Use patch to replace the built-in 'open' function with a mock |
43 | | - with mock.patch("builtins.open", mock.mock_open(read_data=EXPECTED_PASSWD)) as mock_file: |
| 43 | + with mock.patch("{}.open".format(BUILTINS), mock.mock_open(read_data=EXPECTED_PASSWD)) as mock_file: |
44 | 44 | decrypt, err = temp.decrypt_passkey("RADIUS", encrypt) |
45 | 45 | assert err == None |
46 | 46 | assert decrypt == "passkey2" |
|
0 commit comments