def test_anonymous_user_delete(self):
"""Test anonymous user is not allowed to delete an oauth token"""
for token in self.auth_providers:
assert_raises(Unauthorized,
ensure_authorized_to, 'delete', 'token', token=token)
python类Unauthorized()的实例源码
def test_anonymous_user_create(self):
"""Test anonymous user is not allowed to create an oauth token"""
for token in self.auth_providers:
assert_raises(Unauthorized,
ensure_authorized_to, 'create', 'token', token=token)
def test_anonymous_user_read(self):
"""Test anonymous user is not allowed to read an oauth token"""
for token in self.auth_providers:
assert_raises(Unauthorized,
ensure_authorized_to, 'read', 'token', token=token)
def test_anonymous_user_cannot_create(self):
"""Test anonymous users cannot projects"""
assert_raises(Unauthorized, ensure_authorized_to, 'create', Project)
def test_anonymous_user_cannot_read_given_draft(self):
"""Test anonymous users cannot read draft projects"""
project = ProjectFactory.create(published=False)
assert_raises(Unauthorized, ensure_authorized_to, 'read', project)
def test_anonymous_user_cannot_update(self):
"""Test anonymous users cannot update a project"""
project = ProjectFactory.create()
assert_raises(Unauthorized, ensure_authorized_to, 'update', project)
def test_anonymous_user_cannot_delete(self):
"""Test anonymous users cannot delete a project"""
project = ProjectFactory.create()
assert_raises(Unauthorized, ensure_authorized_to, 'delete', project)
def test_anonymous_user_create_given_blogpost(self):
"""Test anonymous users cannot create a given blogpost"""
project = ProjectFactory.create()
blogpost = BlogpostFactory.build(project=project, owner=None)
assert_raises(Unauthorized, ensure_authorized_to, 'create', blogpost)
def test_anonymous_user_create_blogposts_for_given_project(self):
"""Test anonymous users cannot create blogposts for a given project"""
project = ProjectFactory.create()
assert_raises(Unauthorized, ensure_authorized_to, 'create', Blogpost, project_id=project.id)
def test_anonymous_user_create_blogposts(self):
"""Test anonymous users cannot create any blogposts"""
assert_raises(Unauthorized, ensure_authorized_to, 'create', Blogpost)
def test_anonymous_user_read_given_blogpost_draft_project(self):
"""Test anonymous users cannot read a given blogpost of a draft project"""
project = ProjectFactory.create(published=False)
blogpost = BlogpostFactory.create(project=project)
assert_raises(Unauthorized, ensure_authorized_to, 'read', blogpost)
def test_anonymous_user_read_blogposts_for_given_draft_project(self):
"""Test anonymous users cannot read blogposts of a given project if is a draft"""
project = ProjectFactory.create(published=False)
assert_raises(Unauthorized, ensure_authorized_to, 'read', Blogpost, project_id=project.id)
def test_anonymous_user_delete_blogpost(self):
"""Test anonymous users cannot delete blogposts"""
blogpost = BlogpostFactory.create()
assert_raises(Unauthorized, ensure_authorized_to, 'delete', blogpost)
def test_ensure_authorized_raises_401_anonymous_non_authorized(self, auth):
auth.return_value = False
assert_raises(Unauthorized, ensure_authorized_to, 'create', User)
def test_missing_fields(self):
# Verify missing field check. The exception will list out all missing fields, so by removing
# a single field, we should only be notified of that one missing.
with self.assertRaises(Unauthorized) as context:
t = template.copy()
del t['salt']
validate_gamecenter_token(t)
self.assertIn("The token is missing required fields: salt.", context.exception.description)
def test_app_bundles(self):
# Verify that the token is issued to the appropriate app.
with self.assertRaises(Unauthorized) as context:
validate_gamecenter_token(template, app_bundles=['dummy'])
self.assertIn("'app_bundle_id' not one of ['dummy']", context.exception.description)
def test_broken_cert(self):
# Verify that broken certs fail.
with self.assertRaises(Unauthorized) as context:
t = template.copy()
t['public_key_url'] = 'broken cert'
validate_gamecenter_token(t)
self.assertIn("Can't load certificate", context.exception.description)
def test_cert_validation(self):
# Make sure cert is issued to a trusted organization.
_tmp = TRUSTED_ORGANIZATIONS[:]
TRUSTED_ORGANIZATIONS[:] = ['Mordor Inc.']
try:
with self.assertRaises(Unauthorized) as context:
validate_gamecenter_token(template)
self.assertIn("Certificate is issued to 'Apple Inc.' which is not one of ['Mordor Inc.'].", context.exception.description)
finally:
TRUSTED_ORGANIZATIONS[:] = _tmp
def abort_unauthorized(description):
"""Raise an Unauthorized exception.
"""
raise Unauthorized(description=description)
def abort_unauthorized(description):
"""Raise an Unauthorized exception.
"""
raise Unauthorized(description=description)
# Steam provider details schema