Esempio n. 1
0
    def test_do_ssh_op(self, mock_write_cert, mock_ssh_creds, mock_get_mod_exp,
                       mock_ip, mock_check_files, mock_assert, mock_join,
                       mock_principal):
        cmd = mock.Mock()
        cmd.cli_ctx = mock.Mock()
        cmd.cli_ctx.cloud = mock.Mock()
        cmd.cli_ctx.cloud.name = "azurecloud"
        mock_op = mock.Mock()
        mock_check_files.return_value = "public", "private"
        mock_principal.return_value = ["username"]
        mock_get_mod_exp.return_value = "modulus", "exponent"
        profile = mock_ssh_creds.return_value
        profile._adal_cache = True
        profile.get_msal_token.return_value = "username", "certificate"
        mock_join.return_value = "public-aadcert.pub"

        custom._do_ssh_op(cmd, None, None, "1.2.3.4", "publicfile",
                          "privatefile", False, mock_op)

        mock_assert.assert_called_once_with(None, None, "1.2.3.4")
        mock_check_files.assert_called_once_with("publicfile", "privatefile")
        mock_ip.assert_not_called()
        mock_get_mod_exp.assert_called_once_with("public")
        mock_write_cert.assert_called_once_with("certificate",
                                                "public-aadcert.pub")
        mock_op.assert_called_once_with("1.2.3.4", "username",
                                        "public-aadcert.pub", "private")
    def test_do_ssh_op_aad_user_compute(self, mock_write_cert, mock_ssh_creds,
                                        mock_get_mod_exp, mock_ip,
                                        mock_check_files, mock_join,
                                        mock_principal):
        cmd = mock.Mock()
        cmd.cli_ctx = mock.Mock()
        cmd.cli_ctx.cloud = mock.Mock()
        cmd.cli_ctx.cloud.name = "azurecloud"

        op_info = ssh_info.SSHSession(None, None, "1.2.3.4", None, None, False,
                                      None, None, None, None, None, None,
                                      "Microsoft.Compute", None, None, False)
        op_info.public_key_file = "publicfile"
        op_info.private_key_file = "privatefile"
        op_info.ssh_client_folder = "/client/folder"

        mock_op = mock.Mock()
        mock_check_files.return_value = "public", "private", False
        mock_principal.return_value = ["username"]
        mock_get_mod_exp.return_value = "modulus", "exponent"
        profile = mock_ssh_creds.return_value
        profile._adal_cache = True
        profile.get_msal_token.return_value = "username", "certificate"
        mock_join.return_value = "public-aadcert.pub"

        custom._do_ssh_op(cmd, op_info, mock_op)

        mock_check_files.assert_called_once_with("publicfile", "privatefile",
                                                 None, "/client/folder")
        mock_ip.assert_not_called()
        mock_get_mod_exp.assert_called_once_with("public")
        mock_write_cert.assert_called_once_with("certificate",
                                                "public-aadcert.pub")
        mock_op.assert_called_once_with(op_info, False, True)
    def test_do_ssh_op(self, mock_write_cert, mock_ssh_creds, mock_get_mod_exp, mock_ip,
                       mock_check_files, mock_assert):
        cmd = mock.Mock()
        mock_op = mock.Mock()
        mock_check_files.return_value = "public", "private"
        mock_get_mod_exp.return_value = "modulus", "exponent"
        mock_ssh_creds.return_value = "username", "certificate"

        custom._do_ssh_op(cmd, None, None, "1.2.3.4", "publicfile", "privatefile", mock_op)

        mock_assert.assert_called_once_with(None, None, "1.2.3.4")
        mock_check_files.assert_called_once_with("publicfile", "privatefile")
        mock_ip.assert_not_called()
        mock_get_mod_exp.assert_called_once_with("public")
        mock_write_cert.assert_called_once_with("public", "certificate")
        mock_op.assert_called_once_with(
            "1.2.3.4", "username", mock_write_cert.return_value, "private")
    def test_do_ssh_arc_op_aad_user(self, mock_cert_exp, mock_start_ssh,
                                    mock_write_cert, mock_ssh_creds,
                                    mock_get_mod_exp, mock_check_files,
                                    mock_join, mock_principal,
                                    mock_get_relay_info, mock_get_proxy):

        mock_get_proxy.return_value = '/path/to/proxy'
        mock_get_relay_info.return_value = 'relay'
        cmd = mock.Mock()
        cmd.cli_ctx = mock.Mock()
        cmd.cli_ctx.cloud = mock.Mock()
        cmd.cli_ctx.cloud.name = "azurecloud"
        mock_check_files.return_value = "public", "private", False
        mock_principal.return_value = ["username"]
        mock_get_mod_exp.return_value = "modulus", "exponent"
        profile = mock_ssh_creds.return_value
        profile._adal_cache = True
        profile.get_msal_token.return_value = "username", "certificate"
        mock_join.return_value = "public-aadcert.pub"
        from datetime import timedelta
        mock_cert_exp.return_value = timedelta(seconds=3600)

        mock_op = mock.Mock()

        op_info = ssh_info.SSHSession("rg", "vm", None, None, None, False,
                                      None, None, "port", None, [], False,
                                      "Microsoft.HybridCompute", None, None,
                                      False)
        op_info.public_key_file = "publicfile"
        op_info.private_key_file = "privatefile"
        op_info.ssh_client_folder = "client"
        op_info.ssh_proxy_folder = "proxy"

        custom._do_ssh_op(cmd, op_info, mock_op)

        self.assertEqual(op_info.local_user, "username")
        self.assertEqual(op_info.cert_file, "public-aadcert.pub")

        mock_check_files.assert_called_once_with("publicfile", "privatefile",
                                                 None, "client")
        mock_get_mod_exp.assert_called_once_with("public")
        mock_write_cert.assert_called_once_with("certificate",
                                                "public-aadcert.pub")
        mock_get_proxy.assert_called_once_with('proxy')
        mock_get_relay_info.assert_called_once_with(cmd, 'rg', 'vm', 3600)
        mock_op.assert_called_once_with(op_info, False, True)
    def test_do_ssh_op_local_user_compute(self, mock_ip, mock_check_files):
        cmd = mock.Mock()
        mock_op = mock.Mock()
        mock_ip.return_value = "1.2.3.4"

        op_info = ssh_info.ConfigSession("config", "rg", "vm", None, None,
                                         None, False, False, "username", None,
                                         None, "Microsoft.Compute", None, None,
                                         None)
        op_info.public_key_file = "publicfile"
        op_info.private_key_file = "privatefile"
        op_info.cert_file = "cert"
        op_info.ssh_client_folder = "/client/folder"

        custom._do_ssh_op(cmd, op_info, mock_op)

        mock_check_files.assert_not_called()
        mock_ip.assert_called_once_with(cmd, "rg", "vm", False)
        mock_op.assert_called_once_with(op_info, False, False)
Esempio n. 6
0
    def test_do_ssh_op_local_user(self, mock_ip, mock_check_files):
        cmd = mock.Mock()
        mock_op = mock.Mock()
        mock_ip.return_value = "1.2.3.4"

        op_info = mock.Mock()
        op_info.resource_group_name = "rg"
        op_info.vm_name = "vm"
        op_info.ip = None
        op_info.public_key_file = "publicfile"
        op_info.private_key_file = "privatefile"
        op_info.use_private_ip = False
        op_info.local_user = "******"
        op_info.certificate = "cert"
        op_info.ssh_client_folder = "/client/folder"

        custom._do_ssh_op(cmd, op_info, "/cred/folder", mock_op)

        mock_check_files.assert_not_called()
        mock_ip.assert_called_once_with(cmd, "rg", "vm", False)
        mock_op.assert_called_once_with(op_info, False, False)
Esempio n. 7
0
    def test_do_ssh_op_arc_local_user(self, mock_get_cert, mock_check_keys,
                                      mock_start_ssh, mock_get_relay_info,
                                      mock_get_proxy):
        cmd = mock.Mock()
        mock_op = mock.Mock()

        op_info = ssh_info.SSHSession("rg", "vm", None, None, None, False,
                                      "user", None, "port", None, [], False,
                                      "Microsoft.HybridCompute", None, None)
        op_info.private_key_file = "priv"
        op_info.cert_file = "cert"
        op_info.ssh_client_folder = "client"
        op_info.ssh_proxy_folder = "proxy"

        custom._do_ssh_op(cmd, op_info, mock_op)

        mock_get_proxy.assert_called_once_with('proxy')
        mock_get_relay_info.assert_called_once_with(cmd, 'rg', 'vm', None)
        mock_op.assert_called_once_with(op_info, False, False)
        mock_get_cert.assert_not_called()
        mock_check_keys.assert_not_called()