Example #1
0
    def test_ssh_key_file_permissions(self):
        with patch('builtins.open', new_callable=mock_open()), \
             patch('aws_gate.ssh_common.os.chmod') as m:
            key = SshKey()
            key.generate()
            key.write_to_file()

            self.assertTrue(m.called)
            self.assertEqual(call(DEFAULT_GATE_KEY_PATH, 0o600), m.call_args)
Example #2
0
def test_ssh_key_file_permissions(mocker):
    mocker.patch("builtins.open", new_callable=mocker.mock_open())
    m = mocker.patch("aws_gate.ssh_common.os.chmod")

    key = SshKey()
    key.generate()
    key.write_to_file()

    assert m.called
    assert mocker.call(DEFAULT_GATE_KEY_PATH, 0o600) == m.call_args_list[0]
Example #3
0
    def test_delete_key(self):
        with patch('builtins.open', new_callable=mock_open()), \
             patch('aws_gate.ssh_common.os', new_callable=MagicMock()) as m:
            key = SshKey()
            key.generate()
            key.write_to_file()
            key.delete()

            self.assertTrue(m.remove.called)
            self.assertEqual(m.remove.call_args, call(DEFAULT_GATE_KEY_PATH))
Example #4
0
def test_delete_key(mocker):
    mocker.patch("builtins.open", new_callable=mocker.mock_open())
    m = mocker.patch("aws_gate.ssh_common.os", new_callable=mocker.MagicMock())

    key = SshKey()
    key.generate()
    key.write_to_file()
    key.delete()

    assert m.remove.called
    assert m.remove.call_args == mocker.call(DEFAULT_GATE_KEY_PATH)