def test_gen_keys_with_passphrase(self): with patch("M2Crypto.RSA.RSA.save_pem", MagicMock()) as save_pem: with patch("M2Crypto.RSA.RSA.save_pub_key", MagicMock()) as save_pub: with patch("os.path.isfile", return_value=True): self.assertEqual( crypt.gen_keys( "/keydir", "keyname", 2048, passphrase="password" ), "/keydir{0}keyname.pem".format(os.sep), ) save_pem.assert_not_called() save_pub.assert_not_called() with patch("os.path.isfile", return_value=False): self.assertEqual( crypt.gen_keys( "/keydir", "keyname", 2048, passphrase="password" ), "/keydir{0}keyname.pem".format(os.sep), ) callback = save_pem.call_args[1]["callback"] save_pem.assert_called_once_with( "/keydir{0}keyname.pem".format(os.sep), cipher="des_ede3_cbc", callback=callback, ) self.assertEqual(callback(None), b"password") save_pub.assert_called_once_with( "/keydir{0}keyname.pub".format(os.sep) )
def test_gen_keys_with_passphrase(self): with patch('M2Crypto.RSA.RSA.save_pem', MagicMock()) as save_pem: with patch('M2Crypto.RSA.RSA.save_pub_key', MagicMock()) as save_pub: with patch('os.path.isfile', return_value=True): self.assertEqual( crypt.gen_keys('/keydir', 'keyname', 2048, passphrase='password'), '/keydir{0}keyname.pem'.format(os.sep)) save_pem.assert_not_called() save_pub.assert_not_called() with patch('os.path.isfile', return_value=False): self.assertEqual( crypt.gen_keys('/keydir', 'keyname', 2048, passphrase='password'), '/keydir{0}keyname.pem'.format(os.sep)) callback = save_pem.call_args[1]['callback'] save_pem.assert_called_once_with( '/keydir{0}keyname.pem'.format(os.sep), cipher='des_ede3_cbc', callback=callback) self.assertEqual(callback(None), b'password') save_pub.assert_called_once_with( '/keydir{0}keyname.pub'.format(os.sep))
def test_gen_keys_with_passphrase(self): key_path = os.path.join(os.sep, "keydir") open_priv_wb = MockCall(os.path.join(key_path, "keyname.pem"), "wb+") open_pub_wb = MockCall(os.path.join(key_path, "keyname.pub"), "wb+") with patch("salt.utils.files.fopen", mock_open()) as m_open, patch("os.path.isfile", return_value=True): self.assertEqual( crypt.gen_keys(key_path, "keyname", 2048, passphrase="password"), os.path.join(key_path, "keyname.pem"), ) result = crypt.gen_keys(key_path, "keyname", 2048, passphrase="password") assert result == os.path.join(key_path, "keyname.pem"), result assert open_priv_wb not in m_open.calls assert open_pub_wb not in m_open.calls with patch("salt.utils.files.fopen", mock_open()) as m_open, patch("os.path.isfile", return_value=False): crypt.gen_keys(key_path, "keyname", 2048) assert open_priv_wb in m_open.calls assert open_pub_wb in m_open.calls
def test_gen_keys_with_passphrase(self): key_path = os.path.join(os.sep, 'keydir') open_priv_wb = MockCall(os.path.join(key_path, 'keyname.pem'), 'wb+') open_pub_wb = MockCall(os.path.join(key_path, 'keyname.pub'), 'wb+') with patch('salt.utils.files.fopen', mock_open()) as m_open, \ patch('os.path.isfile', return_value=True): self.assertEqual( crypt.gen_keys(key_path, 'keyname', 2048, passphrase='password'), os.path.join(key_path, 'keyname.pem')) result = crypt.gen_keys(key_path, 'keyname', 2048, passphrase='password') assert result == os.path.join(key_path, 'keyname.pem'), result assert open_priv_wb not in m_open.calls assert open_pub_wb not in m_open.calls with patch('salt.utils.files.fopen', mock_open()) as m_open, \ patch('os.path.isfile', return_value=False): crypt.gen_keys(key_path, 'keyname', 2048) assert open_priv_wb in m_open.calls assert open_pub_wb in m_open.calls
def test_gen_keys_with_passphrase(self): with patch('salt.utils.files.fopen', mock_open()): open_priv_wb = call('/keydir/keyname.pem', 'wb+') open_pub_wb = call('/keydir/keyname.pub', 'wb+') with patch('os.path.isfile', return_value=True): self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048, passphrase='password'), '/keydir/keyname.pem') self.assertNotIn(open_priv_wb, salt.utils.files.fopen.mock_calls) self.assertNotIn(open_pub_wb, salt.utils.files.fopen.mock_calls) with patch('os.path.isfile', return_value=False): with patch('salt.utils.files.fopen', mock_open()): crypt.gen_keys('/keydir', 'keyname', 2048) salt.utils.files.fopen.assert_has_calls([open_priv_wb, open_pub_wb], any_order=True)
def test_gen_keys(self): with patch('salt.utils.fopen', mock_open()): open_priv_wb = call('/keydir/keyname.pem', 'wb+') open_pub_wb = call('/keydir/keyname.pub', 'wb+') with patch('os.path.isfile', return_value=True): self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048), '/keydir/keyname.pem') self.assertNotIn(open_priv_wb, salt.utils.fopen.mock_calls) self.assertNotIn(open_pub_wb, salt.utils.fopen.mock_calls) with patch('os.path.isfile', return_value=False): with patch('salt.utils.fopen', mock_open()): crypt.gen_keys('/keydir', 'keyname', 2048) salt.utils.fopen.assert_has_calls([open_priv_wb, open_pub_wb], any_order=True)
def test_gen_keys(self): with patch.multiple(os, umask=MagicMock(), chmod=MagicMock(), access=MagicMock(return_value=True)): with patch('salt.utils.files.fopen', mock_open()): open_priv_wb = call('/keydir{0}keyname.pem'.format(os.sep), 'wb+') open_pub_wb = call('/keydir{0}keyname.pub'.format(os.sep), 'wb+') with patch('os.path.isfile', return_value=True): self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048), '/keydir{0}keyname.pem'.format(os.sep)) self.assertNotIn(open_priv_wb, salt.utils.files.fopen.mock_calls) self.assertNotIn(open_pub_wb, salt.utils.files.fopen.mock_calls) with patch('os.path.isfile', return_value=False): with patch('salt.utils.files.fopen', mock_open()): crypt.gen_keys('/keydir', 'keyname', 2048) salt.utils.files.fopen.assert_has_calls([open_priv_wb, open_pub_wb], any_order=True)
def test_gen_keys(self): with patch('M2Crypto.RSA.RSA.save_pem', MagicMock()) as save_pem: with patch('M2Crypto.RSA.RSA.save_pub_key', MagicMock()) as save_pub: with patch('os.path.isfile', return_value=True): self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048), '/keydir{0}keyname.pem'.format(os.sep)) save_pem.assert_not_called() save_pub.assert_not_called() with patch('os.path.isfile', return_value=False): self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048), '/keydir{0}keyname.pem'.format(os.sep)) save_pem.assert_called_once_with('/keydir{0}keyname.pem'.format(os.sep), cipher=None) save_pub.assert_called_once_with('/keydir{0}keyname.pub'.format(os.sep))
def test_gen_keys(self): open_priv_wb = MockCall('/keydir{0}keyname.pem'.format(os.sep), 'wb+') open_pub_wb = MockCall('/keydir{0}keyname.pub'.format(os.sep), 'wb+') with patch.multiple(os, umask=MagicMock(), chmod=MagicMock(), access=MagicMock(return_value=True)): with patch('salt.utils.files.fopen', mock_open()) as m_open, \ patch('os.path.isfile', return_value=True): result = crypt.gen_keys('/keydir', 'keyname', 2048) assert result == '/keydir{0}keyname.pem'.format(os.sep), result assert open_priv_wb not in m_open.calls assert open_pub_wb not in m_open.calls with patch('salt.utils.files.fopen', mock_open()) as m_open, \ patch('os.path.isfile', return_value=False): crypt.gen_keys('/keydir', 'keyname', 2048) assert open_priv_wb in m_open.calls assert open_pub_wb in m_open.calls
def test_gen_keys(self): with patch("M2Crypto.RSA.RSA.save_pem", MagicMock()) as save_pem: with patch("M2Crypto.RSA.RSA.save_pub_key", MagicMock()) as save_pub: with patch("os.path.isfile", return_value=True): self.assertEqual( crypt.gen_keys("/keydir", "keyname", 2048), "/keydir{}keyname.pem".format(os.sep), ) save_pem.assert_not_called() save_pub.assert_not_called() with patch("os.path.isfile", return_value=False): self.assertEqual( crypt.gen_keys("/keydir", "keyname", 2048), "/keydir{}keyname.pem".format(os.sep), ) save_pem.assert_called_once_with( "/keydir{}keyname.pem".format(os.sep), cipher=None) save_pub.assert_called_once_with( "/keydir{}keyname.pub".format(os.sep))
def test_gen_keys(self): open_priv_wb = MockCall("/keydir{}keyname.pem".format(os.sep), "wb+") open_pub_wb = MockCall("/keydir{}keyname.pub".format(os.sep), "wb+") with patch.multiple( os, umask=MagicMock(), chmod=MagicMock(), access=MagicMock(return_value=True), ): with patch("salt.utils.files.fopen", mock_open()) as m_open, patch("os.path.isfile", return_value=True): result = crypt.gen_keys("/keydir", "keyname", 2048) assert result == "/keydir{}keyname.pem".format(os.sep), result assert open_priv_wb not in m_open.calls assert open_pub_wb not in m_open.calls with patch("salt.utils.files.fopen", mock_open()) as m_open, patch("os.path.isfile", return_value=False): crypt.gen_keys("/keydir", "keyname", 2048) assert open_priv_wb in m_open.calls assert open_pub_wb in m_open.calls