Exemple #1
0
    def test_success(self, mock_tmp_store):
        mock_tmp_store.return_value = self.mock_tmpfile
        self.mock_runner.run.return_value = ("tool output", "", 0)

        lib.client_import_certificate_and_key(self.mock_runner,
                                              "pk12 certificate")

        mock_tmp_store.assert_called_once_with(
            "pk12 certificate", reports.qdevice_certificate_import_error)
        self.mock_runner.run.assert_called_once_with(
            [_client_cert_tool, "-m", "-c", self.mock_tmpfile.name])
Exemple #2
0
def client_net_import_certificate(lib_env, certificate):
    """
    Import qnetd client certificate to local node certificate storage
    certificate base64 encoded qnetd client certificate
    """
    try:
        certificate_data = base64.b64decode(certificate)
    except (TypeError, binascii.Error):
        raise LibraryError(
            reports.invalid_option_value("qnetd client certificate",
                                         certificate,
                                         ["base64 encoded certificate"]))
    qdevice_net.client_import_certificate_and_key(lib_env.cmd_runner(),
                                                  certificate_data)
Exemple #3
0
    def test_import_error(self, mock_tmp_store):
        mock_tmp_store.return_value = self.mock_tmpfile
        self.mock_runner.run.return_value = ("stdout", "tool output error", 1)

        assert_raise_library_error(
            lambda: lib.client_import_certificate_and_key(
                self.mock_runner, "pk12 certificate"
            ),
            (
                severity.ERROR,
                report_codes.QDEVICE_CERTIFICATE_IMPORT_ERROR,
                {
                    "reason": "tool output error\nstdout",
                },
            ),
        )

        mock_tmp_store.assert_called_once_with(
            "pk12 certificate",
            reports.messages.QdeviceCertificateImportError,
        )
        mock_tmp_store.assert_called_once_with(
            "pk12 certificate",
            reports.messages.QdeviceCertificateImportError,
        )
        self.mock_runner.run.assert_called_once_with(
            [_client_cert_tool, "-m", "-c", self.mock_tmpfile.name]
        )
Exemple #4
0
    def test_import_error(self, mock_tmp_store):
        mock_tmp_store.return_value = self.mock_tmpfile
        self.mock_runner.run.return_value = ("stdout", "tool output error", 1)

        assert_raise_library_error(
            lambda: lib.client_import_certificate_and_key(
                self.mock_runner,
                "pk12 certificate"
            ),
            (
                severity.ERROR,
                report_codes.QDEVICE_CERTIFICATE_IMPORT_ERROR,
                {
                    "reason": "tool output error\nstdout",
                }
            )
        )

        mock_tmp_store.assert_called_once_with(
            "pk12 certificate",
            reports.qdevice_certificate_import_error
        )
        mock_tmp_store.assert_called_once_with(
            "pk12 certificate",
            reports.qdevice_certificate_import_error
        )
        self.mock_runner.run.assert_called_once_with([
            _client_cert_tool, "-m", "-c", self.mock_tmpfile.name
        ])
Exemple #5
0
    def test_success(self, mock_tmp_store):
        mock_tmp_store.return_value = self.mock_tmpfile
        self.mock_runner.run.return_value = ("tool output", "", 0)

        lib.client_import_certificate_and_key(
            self.mock_runner,
            "pk12 certificate"
        )

        mock_tmp_store.assert_called_once_with(
            "pk12 certificate",
            reports.qdevice_certificate_import_error
        )
        self.mock_runner.run.assert_called_once_with([
            _client_cert_tool, "-m", "-c", self.mock_tmpfile.name
        ])
Exemple #6
0
def client_net_import_certificate(lib_env: LibraryEnvironment, certificate):
    """
    Import qnetd client certificate to local node certificate storage
    certificate base64 encoded qnetd client certificate
    """
    try:
        certificate_data = base64.b64decode(certificate)
    except (TypeError, binascii.Error):
        raise LibraryError(
            ReportItem.error(
                reports.messages.InvalidOptionValue(
                    "qnetd client certificate",
                    certificate,
                    ["base64 encoded certificate"],
                )))
    qdevice_net.client_import_certificate_and_key(lib_env.cmd_runner(),
                                                  certificate_data)
Exemple #7
0
def client_net_import_certificate(lib_env, certificate):
    """
    Import qnetd client certificate to local node certificate storage
    certificate base64 encoded qnetd client certificate
    """
    try:
        certificate_data = base64.b64decode(certificate)
    except (TypeError, binascii.Error):
        raise LibraryError(reports.invalid_option_value(
            "qnetd client certificate",
            certificate,
            ["base64 encoded certificate"]
        ))
    qdevice_net.client_import_certificate_and_key(
        lib_env.cmd_runner(),
        certificate_data
    )
Exemple #8
0
    def test_input_write_error(self, mock_tmp_store):
        mock_tmp_store.side_effect = LibraryError

        self.assertRaises(
            LibraryError, lambda: lib.client_import_certificate_and_key(
                self.mock_runner, "pk12 certificate"))

        mock_tmp_store.assert_called_once_with(
            "pk12 certificate", reports.qdevice_certificate_import_error)
        self.mock_runner.run.assert_not_called()
Exemple #9
0
    def test_not_initialized(self, mock_tmp_store):
        assert_raise_library_error(
            lambda: lib.client_import_certificate_and_key(
                self.mock_runner, "pk12 certificate"),
            (severity.ERROR, report_codes.QDEVICE_NOT_INITIALIZED, {
                "model": "net",
            }))

        mock_tmp_store.assert_not_called()
        self.mock_runner.run.assert_not_called()
Exemple #10
0
    def test_input_write_error(self, mock_tmp_store):
        mock_tmp_store.side_effect = LibraryError

        self.assertRaises(
            LibraryError,
            lambda: lib.client_import_certificate_and_key(
                self.mock_runner,
                "pk12 certificate"
            )
        )

        mock_tmp_store.assert_called_once_with(
            "pk12 certificate",
            reports.qdevice_certificate_import_error
        )
        self.mock_runner.run.assert_not_called()
Exemple #11
0
    def test_not_initialized(self, mock_tmp_store):
        assert_raise_library_error(
            lambda: lib.client_import_certificate_and_key(
                self.mock_runner,
                "pk12 certificate"
            ),
            (
                severity.ERROR,
                report_codes.QDEVICE_NOT_INITIALIZED,
                {
                    "model": "net",
                }
            )
        )

        mock_tmp_store.assert_not_called()
        self.mock_runner.run.assert_not_called()