本文整理汇总了Python中sentry.interfaces.csp.Csp.to_python方法的典型用法代码示例。如果您正苦于以下问题:Python Csp.to_python方法的具体用法?Python Csp.to_python怎么用?Python Csp.to_python使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry.interfaces.csp.Csp
的用法示例。
在下文中一共展示了Csp.to_python方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_culprit_directive
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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>')
示例2: test_violated_directive
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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')
示例3: test_get_hash
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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']
示例4: validate_data
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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,
}
}
示例5: interface
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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',
))
示例6: validate_data
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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},
}
示例7: test_coerce_blocked_uri_if_missing
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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'
示例8: get_metadata
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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(),
}
示例9: test_get_tags_stripe
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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'),
)
示例10: validate_data
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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
示例11: get_metadata
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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(),
}
示例12: test_get_message
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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:'"
示例13: test_get_culprit
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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'"
示例14: validate_data
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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
示例15: test_to_python_validation_errors
# 需要导入模块: from sentry.interfaces.csp import Csp [as 别名]
# 或者: from sentry.interfaces.csp.Csp import to_python [as 别名]
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',
))