本文整理匯總了Python中openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES.override方法的典型用法代碼示例。如果您正苦於以下問題:Python ENFORCE_JWT_SCOPES.override方法的具體用法?Python ENFORCE_JWT_SCOPES.override怎麽用?Python ENFORCE_JWT_SCOPES.override使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES
的用法示例。
在下文中一共展示了ENFORCE_JWT_SCOPES.override方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_inactive_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_inactive_user(self, auth_type, scopes_enforced):
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
self.student.is_active = False
self.student.save()
resp = self._get_response(self.student, auth_type)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
示例2: test_dot_create_jwt_for_token
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_dot_create_jwt_for_token(self, scopes_enforced, client_restricted):
with ENFORCE_JWT_SCOPES.override(scopes_enforced):
jwt_token = self._create_jwt_for_token(
DOTAdapter(),
use_asymmetric_key=None,
client_restricted=client_restricted,
)
self._assert_jwt_is_valid(jwt_token, should_be_asymmetric_key=scopes_enforced and client_restricted)
示例3: test_another_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_another_user(self, auth_type, scopes_enforced, mock_log):
"""
Returns 200 with empty list for OAuth, Session, and JWT auth.
Returns 200 for jwt_restricted and user:me filter unset.
"""
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
resp = self.get_response(auth_type, requesting_user=self.other_student)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
self.assertEqual(len(resp.data), 0)
示例4: test_jwt_no_filter
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_jwt_no_filter(self, auth_type, scopes_enforced, mock_log):
""" Returns 403 when scopes are enforced with JwtHasContentOrgFilterForRequestedCourse. """
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
jwt_token = self._create_jwt_token(self.student, auth_type, include_org_filter=False)
resp = self.get_response(AuthType.jwt, token=jwt_token)
is_enforced = scopes_enforced and auth_type == AuthType.jwt_restricted
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN if is_enforced else status.HTTP_200_OK)
if is_enforced:
self._assert_in_log("JwtHasContentOrgFilterForRequestedCourse", mock_log.warning)
示例5: test_jwt_no_scopes
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_jwt_no_scopes(self, auth_type, scopes_enforced, mock_log):
""" Returns 403 when scopes are enforced with JwtHasScope. """
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
jwt_token = self._create_jwt_token(self.student, auth_type, scopes=[])
resp = self._get_response(self.student, AuthType.jwt, token=jwt_token)
is_enforced = scopes_enforced and auth_type == AuthType.jwt_restricted
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN if is_enforced else status.HTTP_200_OK)
if is_enforced:
self._assert_in_log("JwtHasScope", mock_log.warning)
示例6: test_jwt_on_behalf_of_other_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_jwt_on_behalf_of_other_user(self, auth_type, scopes_enforced, mock_log):
""" Returns 403 when scopes are enforced with JwtHasUserFilterForRequestedUser. """
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
jwt_token = self._create_jwt_token(self.other_student, auth_type, include_me_filter=True)
resp = self.get_response(AuthType.jwt, token=jwt_token)
if scopes_enforced and auth_type == AuthType.jwt_restricted:
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
self._assert_in_log("JwtHasUserFilterForRequestedUser", mock_log.warning)
else:
self.assertEqual(resp.status_code, status.HTTP_200_OK)
self.assertEqual(len(resp.data), 0)
示例7: test_jwt_on_behalf_of_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_jwt_on_behalf_of_user(self, auth_type, scopes_enforced):
"""
We have to override this super method due to this API
being restricted to staff users only.
"""
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
jwt_token = self._create_jwt_token(self.student, auth_type, include_me_filter=True)
# include_me_filter=True means a JWT filter will require the username
# of the requesting user to be in the requested URL
url = self.get_url(self.student) + '?username={}'.format(self.student.username)
resp = self.get_response(AuthType.jwt, token=jwt_token, url=url)
assert status.HTTP_200_OK == resp.status_code
示例8: test_another_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_another_user(self, auth_type, scopes_enforced, mock_log):
""" Returns 403 for OAuth and Session auth with IsUserInUrl. """
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
resp = self._get_response(self.student_no_cert, auth_type)
# Restricted JWT tokens without the user:me filter have access to other users
expected_jwt_access_granted = scopes_enforced and auth_type == AuthType.jwt_restricted
self.assertEqual(
resp.status_code,
status.HTTP_200_OK if expected_jwt_access_granted else status.HTTP_403_FORBIDDEN,
)
if not expected_jwt_access_granted:
self._assert_in_log("IsUserInUrl", mock_log.info)
示例9: test_restricted_non_jwt_access_token_fields
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_restricted_non_jwt_access_token_fields(self, enforce_jwt_scopes_enabled):
with ENFORCE_JWT_SCOPES.override(enforce_jwt_scopes_enabled):
response = self._post_request(self.user, self.restricted_dot_app)
self.assertEqual(response.status_code, 200)
data = json.loads(response.content)
self.assertIn('access_token', data)
self.assertIn('expires_in', data)
self.assertIn('scope', data)
self.assertIn('token_type', data)
# Verify token expiration.
self.assertEqual(data['expires_in'] < 0, True)
access_token = dot_models.AccessToken.objects.get(token=data['access_token'])
self.assertEqual(
models.RestrictedApplication.verify_access_token_as_expired(access_token),
True
)
示例10: test_another_user_with_certs_shared_public
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_another_user_with_certs_shared_public(self, auth_type, scopes_enforced):
"""
Returns 200 with cert list for OAuth, Session, and JWT auth.
Returns 200 for jwt_restricted and user:me filter unset.
"""
self.student.profile.year_of_birth = 1977
self.student.profile.save()
UserPreferenceFactory.build(
user=self.student,
key='account_privacy',
value='all_users',
).save()
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
resp = self.get_response(auth_type, requesting_user=self.other_student)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
self.assertEqual(len(resp.data), 1)
示例11: test_restricted_jwt_access_token
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_restricted_jwt_access_token(self, enforce_jwt_scopes_enabled, expiration_expected):
"""
Verify that when requesting a JWT token from a restricted Application
within the DOT subsystem, that our claims is marked as already expired
(i.e. expiry set to Jan 1, 1970)
"""
with ENFORCE_JWT_SCOPES.override(enforce_jwt_scopes_enabled):
response = self._post_request(self.user, self.restricted_dot_app, token_type='jwt')
self.assertEqual(response.status_code, 200)
data = json.loads(response.content)
self.assertIn('expires_in', data)
self.assertEqual(data['expires_in'] < 0, expiration_expected)
self.assertEqual(data['token_type'], 'JWT')
self.assert_valid_jwt_access_token(
data['access_token'],
self.user,
data['scope'].split(' '),
should_be_expired=expiration_expected,
should_be_asymmetric_key=enforce_jwt_scopes_enabled,
should_be_restricted=True,
)
示例12: test_jwt_on_behalf_of_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_jwt_on_behalf_of_user(self, auth_type, scopes_enforced):
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
jwt_token = self._create_jwt_token(self.student, auth_type, include_me_filter=True)
resp = self.get_response(AuthType.jwt, token=jwt_token)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
示例13: test_staff_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_staff_user(self, auth_type, scopes_enforced):
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
resp = self.get_response(auth_type, requesting_user=self.global_staff)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
self.assert_success_response_for_student(resp)
示例14: test_staff_user
# 需要導入模塊: from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES [as 別名]
# 或者: from openedx.core.djangoapps.oauth_dispatch.toggles.ENFORCE_JWT_SCOPES import override [as 別名]
def test_staff_user(self, auth_type, scopes_enforced):
with ENFORCE_JWT_SCOPES.override(active=scopes_enforced):
resp = self._get_response(self.staff_user, auth_type)
self.assertEqual(resp.status_code, status.HTTP_200_OK)