• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python csp.Csp类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.interfaces.csp.Csp的典型用法代码示例。如果您正苦于以下问题:Python Csp类的具体用法?Python Csp怎么用?Python Csp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Csp类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_get_culprit_directive

    def test_get_culprit_directive(self):
        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            blocked_uri='http://example.com/lol.css',
            effective_directive='style-src'
        ))
        assert result.get_culprit_directive() == ('blocked-uri', 'http://example.com/lol.css')

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            blocked_uri='',
            effective_directive='style-src',
        ))
        assert result.get_culprit_directive() == ('effective-directive', 'style-src')

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='',
        ))
        assert result.get_culprit_directive() == ('blocked-uri', 'self')

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
        ))
        assert result.get_culprit_directive() == ('effective-directive', '<unknown>')
开发者ID:Batterfii,项目名称:sentry,代码行数:26,代码来源:test_csp.py


示例2: test_violated_directive

    def test_violated_directive(self):
        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            violated_directive='style-src http://cdn.example.com',
        ))
        assert result.get_violated_directive() == ('violated-directive', 'style-src http://cdn.example.com')

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            violated_directive='style-src cdn.example.com',
        ))
        assert result.get_violated_directive() == ('violated-directive', 'style-src http://cdn.example.com')

        result = Csp.to_python(dict(
            document_uri='https://example.com/foo',
            violated_directive='style-src cdn.example.com',
        ))
        assert result.get_violated_directive() == ('violated-directive', 'style-src https://cdn.example.com')

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            violated_directive='style-src https://cdn.example.com',
        ))
        assert result.get_violated_directive() == ('violated-directive', 'style-src https://cdn.example.com')

        result = Csp.to_python(dict(
            document_uri='blob:example.com/foo',
            violated_directive='style-src cdn.example.com',
        ))
        assert result.get_violated_directive() == ('violated-directive', 'style-src blob:cdn.example.com')
开发者ID:jango2015,项目名称:sentry,代码行数:30,代码来源:test_csp.py


示例3: test_get_hash

    def test_get_hash(self):
        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='',
        ))
        assert result.get_hash() == ['script-src', "'self'"]

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='self',
        ))
        assert result.get_hash() == ['script-src', "'self'"]

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='http://example.com/lol.js',
        ))
        assert result.get_hash() == ['script-src', 'example.com']

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='img-src',
            blocked_uri='data:foo',
        ))
        assert result.get_hash() == ['img-src', 'data:']

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='img-src',
            blocked_uri='ftp://example.com/foo',
        ))
        assert result.get_hash() == ['img-src', 'ftp://example.com']
开发者ID:ningg,项目名称:sentry,代码行数:35,代码来源:test_csp.py


示例4: validate_data

    def validate_data(self, project, data):
        # All keys are sent with hyphens, so we want to conver to underscores
        report = dict(map(lambda v: (v[0].replace('-', '_'), v[1]), data.iteritems()))

        try:
            inst = Csp.to_python(report)
        except Exception as exc:
            raise APIForbidden('Invalid CSP Report: %s' % exc)

        # Construct a faux Http interface based on the little information we have
        headers = {}
        if self.context.agent:
            headers['User-Agent'] = self.context.agent
        if inst.referrer:
            headers['Referer'] = inst.referrer

        return {
            'logger': 'csp',
            'project': project.id,
            'message': inst.get_message(),
            'culprit': inst.get_culprit(),
            'tags': inst.get_tags(),
            inst.get_path(): inst.to_json(),
            # This is a bit weird, since we don't have nearly enough
            # information to create an Http interface, but
            # this automatically will pick up tags for the User-Agent
            # which is actually important here for CSP
            'sentry.interfaces.Http': {
                'url': inst.document_uri,
                'headers': headers,
            },
            'sentry.interfaces.User': {
                'ip_address': self.context.ip_address,
            }
        }
开发者ID:TonyMistark,项目名称:sentry,代码行数:35,代码来源:coreapi.py


示例5: interface

 def interface(self):
     return Csp.to_python(dict(
         document_uri='http://example.com',
         violated_directive='style-src cdn.example.com',
         blocked_uri='http://example.com/lol.css',
         effective_directive='style-src',
     ))
开发者ID:ningg,项目名称:sentry,代码行数:7,代码来源:test_csp.py


示例6: validate_data

    def validate_data(self, project, data):
        # All keys are sent with hyphens, so we want to conver to underscores
        report = dict(map(lambda v: (v[0].replace("-", "_"), v[1]), data.iteritems()))

        try:
            inst = Csp.to_python(report)
        except Exception as exc:
            raise APIForbidden("Invalid CSP Report: %s" % exc)

        # Construct a faux Http interface based on the little information we have
        headers = {}
        if self.context.agent:
            headers["User-Agent"] = self.context.agent
        if inst.referrer:
            headers["Referer"] = inst.referrer

        return {
            "logger": "csp",
            "project": project.id,
            "message": inst.get_message(),
            "culprit": inst.get_culprit(),
            "tags": inst.get_tags(),
            inst.get_path(): inst.to_json(),
            # This is a bit weird, since we don't have nearly enough
            # information to create an Http interface, but
            # this automatically will pick up tags for the User-Agent
            # which is actually important here for CSP
            "sentry.interfaces.Http": {"url": inst.document_uri, "headers": headers},
            "sentry.interfaces.User": {"ip_address": self.context.ip_address},
        }
开发者ID:wlcx,项目名称:sentry,代码行数:30,代码来源:coreapi.py


示例7: test_coerce_blocked_uri_if_missing

 def test_coerce_blocked_uri_if_missing(self):
     result = Csp.to_python(
         dict(
             document_uri='http://example.com',
             effective_directive='script-src',
         )
     )
     assert result.blocked_uri == 'self'
开发者ID:alshopov,项目名称:sentry,代码行数:8,代码来源:test_csp.py


示例8: get_metadata

    def get_metadata(self):
        # TODO(dcramer): pull get message into here to avoid instantiation
        # or ensure that these get interfaces passed instead of raw data
        csp = Csp.to_python(self.data['sentry.interfaces.Csp'])

        return {
            'directive': csp.effective_directive,
            'uri': csp._normalized_blocked_uri,
            'message': csp.get_message(),
        }
开发者ID:ForkRepo,项目名称:sentry,代码行数:10,代码来源:csp.py


示例9: test_get_tags_stripe

 def test_get_tags_stripe(self):
     result = Csp.to_python(
         dict(
             blocked_uri='https://api.stripe.com/v1/tokens?card[number]=xxx',
             effective_directive='script-src',
         )
     )
     assert result.get_tags() == (
         ('effective-directive', 'script-src'),
         ('blocked-uri', 'https://api.stripe.com/v1/tokens'),
     )
开发者ID:alshopov,项目名称:sentry,代码行数:11,代码来源:test_csp.py


示例10: validate_data

    def validate_data(self, project, data):
        # pop off our meta data used to hold Sentry specific stuff
        meta = data.pop('_meta', {})

        # All keys are sent with hyphens, so we want to conver to underscores
        report = dict(map(lambda v: (v[0].replace('-', '_'), v[1]), six.iteritems(data)))

        try:
            inst = Csp.to_python(report)
        except Exception as exc:
            raise APIForbidden('Invalid CSP Report: %s' % exc)

        # Construct a faux Http interface based on the little information we have
        headers = {}
        if self.context.agent:
            headers['User-Agent'] = self.context.agent
        if inst.referrer:
            headers['Referer'] = inst.referrer

        data = {
            'logger': 'csp',
            'project': project.id,
            'message': inst.get_message(),
            'culprit': inst.get_culprit(),
            'tags': inst.get_tags(),
            'release': meta.get('release'),
            inst.get_path(): inst.to_json(),
            # This is a bit weird, since we don't have nearly enough
            # information to create an Http interface, but
            # this automatically will pick up tags for the User-Agent
            # which is actually important here for CSP
            'sentry.interfaces.Http': {
                'url': inst.document_uri,
                'headers': headers,
            },
            'sentry.interfaces.User': {
                'ip_address': self.context.ip_address,
            },
            'errors': [],
        }

        # Copy/pasted from above in ClientApiHelper.validate_data
        if data.get('release'):
            data['release'] = six.text_type(data['release'])
            if len(data['release']) > 64:
                data['errors'].append({
                    'type': EventError.VALUE_TOO_LONG,
                    'name': 'release',
                    'value': data['release'],
                })
                del data['release']

        return data
开发者ID:dcvz,项目名称:sentry,代码行数:53,代码来源:coreapi.py


示例11: get_metadata

    def get_metadata(self):
        # TODO(dcramer): we need to avoid importing interfaces in this module
        # due to recursion at top level
        from sentry.interfaces.csp import Csp
        # TODO(dcramer): pull get message into here to avoid instantiation
        # or ensure that these get interfaces passed instead of raw data
        csp = Csp.to_python(self.data['sentry.interfaces.Csp'])

        return {
            'directive': csp.effective_directive,
            'uri': csp._normalized_blocked_uri,
            'message': csp.get_message(),
        }
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:13,代码来源:csp.py


示例12: test_get_message

    def test_get_message(self):
        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='img-src',
            blocked_uri='http://google.com/foo',
        ))
        assert result.get_message() == "Blocked 'image' from 'google.com'"

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='style-src',
            blocked_uri='',
        ))
        assert result.get_message() == "Blocked inline 'style'"

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='',
            violated_directive="script-src 'unsafe-inline'",
        ))
        assert result.get_message() == "Blocked unsafe eval() 'script'"

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='',
            violated_directive="script-src 'unsafe-eval'",
        ))
        assert result.get_message() == "Blocked unsafe inline 'script'"

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='',
            violated_directive="script-src example.com",
        ))
        assert result.get_message() == "Blocked unsafe (eval() or inline) 'script'"

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D',
        ))
        assert result.get_message() == "Blocked 'script' from 'data:'"

        result = Csp.to_python(dict(
            document_uri='http://example.com/foo',
            effective_directive='script-src',
            blocked_uri='data',
        ))
        assert result.get_message() == "Blocked 'script' from 'data:'"
开发者ID:nakamura41,项目名称:sentry,代码行数:52,代码来源:test_csp.py


示例13: test_get_culprit

    def test_get_culprit(self):
        result = Csp.to_python(
            dict(
                document_uri='http://example.com/foo',
                violated_directive='style-src http://cdn.example.com',
                effective_directive='style-src',
            )
        )
        assert result.get_culprit() == 'style-src http://cdn.example.com'

        result = Csp.to_python(
            dict(
                document_uri='http://example.com/foo',
                violated_directive='style-src cdn.example.com',
                effective_directive='style-src',
            )
        )
        assert result.get_culprit() == 'style-src cdn.example.com'

        result = Csp.to_python(
            dict(
                document_uri='https://example.com/foo',
                violated_directive='style-src cdn.example.com',
                effective_directive='style-src',
            )
        )
        assert result.get_culprit() == 'style-src cdn.example.com'

        result = Csp.to_python(
            dict(
                document_uri='http://example.com/foo',
                violated_directive='style-src https://cdn.example.com',
                effective_directive='style-src',
            )
        )
        assert result.get_culprit() == 'style-src https://cdn.example.com'

        result = Csp.to_python(
            dict(
                document_uri='http://example.com/foo',
                violated_directive='style-src http://example.com',
                effective_directive='style-src',
            )
        )
        assert result.get_culprit() == "style-src 'self'"

        result = Csp.to_python(
            dict(
                document_uri='http://example.com/foo',
                violated_directive='style-src http://example2.com example.com',
                effective_directive='style-src',
            )
        )
        assert result.get_culprit() == "style-src http://example2.com 'self'"
开发者ID:alshopov,项目名称:sentry,代码行数:54,代码来源:test_csp.py


示例14: validate_data

    def validate_data(self, data):
        # pop off our meta data used to hold Sentry specific stuff
        meta = data.pop('_meta', {})

        # All keys are sent with hyphens, so we want to conver to underscores
        report = {k.replace('-', '_'): v for k, v in six.iteritems(data)}

        try:
            inst = Csp.to_python(report)
        except Exception as exc:
            raise APIForbidden('Invalid CSP Report: %s' % exc)

        # Construct a faux Http interface based on the little information we have
        headers = {}
        if self.context.agent:
            headers['User-Agent'] = self.context.agent
        if inst.referrer:
            headers['Referer'] = inst.referrer

        data = {
            'logger': 'csp',
            'message': inst.get_message(),
            'culprit': inst.get_culprit(),
            'release': meta.get('release'),
            'tags': inst.get_tags(),
            inst.get_path(): inst.to_json(),
            # This is a bit weird, since we don't have nearly enough
            # information to create an Http interface, but
            # this automatically will pick up tags for the User-Agent
            # which is actually important here for CSP
            'sentry.interfaces.Http': {
                'url': inst.document_uri,
                'headers': headers,
            },
            'sentry.interfaces.User': {
                'ip_address': self.context.ip_address,
            },
        }

        return data
开发者ID:gencer,项目名称:sentry,代码行数:40,代码来源:coreapi.py


示例15: test_to_python_validation_errors

    def test_to_python_validation_errors(self):
        with self.assertRaises(InterfaceValidationError):
            Csp.to_python(dict(
                effective_directive='style-src',
                blocked_uri='about',
            ))

        with self.assertRaises(InterfaceValidationError):
            Csp.to_python(dict(
                effective_directive='lol',
            ))

        with self.assertRaises(InterfaceValidationError):
            Csp.to_python(dict(
                effective_directive='style-src',
                source_file='chrome-extension://fdasfdsafdsfdsa',
            ))
开发者ID:ningg,项目名称:sentry,代码行数:17,代码来源:test_csp.py


示例16: validate_data

    def validate_data(self, data):
        # pop off our meta data used to hold Sentry specific stuff
        meta = data.pop('_meta', {})

        # All keys are sent with hyphens, so we want to conver to underscores
        report = {k.replace('-', '_'): v for k, v in six.iteritems(data)}

        try:
            inst = Csp.to_python(report)
        except Exception as exc:
            raise APIForbidden('Invalid CSP Report: %s' % exc)

        # Construct a faux Http interface based on the little information we have
        headers = {}
        if self.context.agent:
            headers['User-Agent'] = self.context.agent
        if inst.referrer:
            headers['Referer'] = inst.referrer

        data = {
            'logger': 'csp',
            'message': inst.get_message(),
            'culprit': inst.get_culprit(),
            'release': meta.get('release'),
            inst.get_path(): inst.to_json(),
            # This is a bit weird, since we don't have nearly enough
            # information to create an Http interface, but
            # this automatically will pick up tags for the User-Agent
            # which is actually important here for CSP
            'sentry.interfaces.Http': {
                'url': inst.document_uri,
                'headers': headers,
            },
            'sentry.interfaces.User': {
                'ip_address': self.context.ip_address,
            },
            'errors': [],
        }

        # Copy/pasted from above in ClientApiHelper.validate_data
        if data.get('release'):
            data['release'] = six.text_type(data['release'])
            if len(data['release']) > 64:
                data['errors'].append(
                    {
                        'type': EventError.VALUE_TOO_LONG,
                        'name': 'release',
                        'value': data['release'],
                    }
                )
                del data['release']

        tags = []
        for k, v in inst.get_tags():
            if not v:
                continue
            if len(v) > MAX_TAG_VALUE_LENGTH:
                self.log.debug('Discarded invalid tag: %s=%s', k, v)
                data['errors'].append(
                    {
                        'type': EventError.INVALID_DATA,
                        'name': 'tags',
                        'value': (k, v),
                    }
                )
                continue
            if not tagstore.is_valid_value(v):
                self.log.debug('Discard invalid tag value: %s', v)
                data['errors'].append(
                    {
                        'type': EventError.INVALID_DATA,
                        'name': 'tags',
                        'value': (k, v),
                    }
                )
                continue
            tags.append((k, v))

        if tags:
            data['tags'] = tags

        return data
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:82,代码来源:coreapi.py


示例17: test_coerce_blocked_uri_if_script_src

 def test_coerce_blocked_uri_if_script_src(self):
     result = Csp.to_python(dict(
         effective_directive='script-src'
     ))
     assert result.blocked_uri == 'self'
开发者ID:jango2015,项目名称:sentry,代码行数:5,代码来源:test_csp.py


示例18: test_to_python_validation_errors

    def test_to_python_validation_errors(self):
        with self.assertRaises(InterfaceValidationError):
            Csp.to_python(dict(blocked_uri='about'))

        with self.assertRaises(InterfaceValidationError):
            Csp.to_python(dict(effective_directive='lol'))
开发者ID:noah-lee,项目名称:sentry,代码行数:6,代码来源:test_csp.py



注:本文中的sentry.interfaces.csp.Csp类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python exception.Exception类代码示例发布时间:2022-05-27
下一篇:
Python base.get_interface函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap