def test_cert_import_nonresolving_url(self):
        with XRDSSTTest() as app:
            cert_controller = CertController()
            cert_controller.app = app
            cert_controller.load_config = (lambda: self.ss_config_with_authcert())
            cert_controller.import_()

            out, err = self.capsys.readouterr()
            assert out.count("SKIPPED 'ssX': no connectivity") > 0
    def test_cert_import_nonexisting_certs(self):
        with XRDSSTTest() as app:
            cert_controller = CertController()
            cert_controller.app = app
            cert_controller.load_config = (lambda: self.ss_config)
            cert_controller.get_server_status = (lambda x, y: StatusTestData.server_status_essentials_complete)
            cert_controller.import_()

            out, err = self.capsys.readouterr()
            assert out.count("references non-existent file") > 0

            with self.capsys.disabled():
                sys.stdout.write(out)
                sys.stderr.write(err)
    def test_cert_import_permission_denied(self):
        class PermissionDeniedResponse:
            status = 403
            data = '{"status":403,"error":{"code":"permission_denied"}}'
            reason = None
            def getheaders(self): return None

        with XRDSSTTest() as app:
            with mock.patch('xrdsst.api.tokens_api.TokensApi.get_token',
                            return_value=CertTestData.single_auth_key_with_cert_token_response):
                with mock.patch('xrdsst.api.token_certificates_api.TokenCertificatesApi.import_certificate',
                                side_effect=ApiException(http_resp=PermissionDeniedResponse())):
                    cert_controller = CertController()
                    cert_controller.app = app
                    cert_controller.load_config = (lambda: self.ss_config_with_authcert())
                    cert_controller.get_server_status = (lambda x, y: StatusTestData.server_status_essentials_complete)
                    cert_controller.import_()

                    out, err = self.capsys.readouterr()
                    assert err.count("permission") > 0

                    with self.capsys.disabled():
                        sys.stdout.write(out)
                        sys.stderr.write(err)
 def step_cert_import(self):
     with XRDSSTTest() as app:
         cert_controller = CertController()
         cert_controller.app = app
         cert_controller.load_config = (lambda: self.config)
         cert_controller.import_()