Remove deprecated JwtBuilder

ARCH-248
This commit is contained in:
Nimisha Asthagiri
2018-10-14 00:32:18 -04:00
parent f5a643f53b
commit dc56a63e03
16 changed files with 38 additions and 142 deletions

View File

@@ -15,8 +15,8 @@ from django.utils.translation import ugettext as _
from edx_rest_api_client.client import EdxRestApiClient
from slumber.exceptions import HttpClientError, HttpNotFoundError, HttpServerError
from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.lib.token_utils import JwtBuilder
from openedx.features.enterprise_support.utils import get_cache_key
from third_party_auth.pipeline import get as get_partial_pipeline
from third_party_auth.provider import Registry
@@ -49,7 +49,7 @@ class ConsentApiClient(object):
Initialize an authenticated Consent service API client by using the
provided user.
"""
jwt = JwtBuilder(user).build_token([])
jwt = create_jwt_for_user(user)
url = configuration_helpers.get_value('ENTERPRISE_CONSENT_API_URL', settings.ENTERPRISE_CONSENT_API_URL)
self.client = EdxRestApiClient(
url,
@@ -127,7 +127,7 @@ class EnterpriseApiClient(object):
provided user.
"""
self.user = user
jwt = JwtBuilder(user).build_token([])
jwt = create_jwt_for_user(user)
self.client = EdxRestApiClient(
configuration_helpers.get_value('ENTERPRISE_API_URL', settings.ENTERPRISE_API_URL),
jwt=jwt

View File

@@ -67,7 +67,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
Verify that the provided api client uses the enterprise service user to generate
JWT token for auth.
"""
mocked_jwt_builder.return_value.build_token.return_value = 'test-token'
mocked_jwt_builder.return_value = 'test-token'
enterprise_service_user = User.objects.get(username=settings.ENTERPRISE_SERVICE_WORKER_USERNAME)
enterprise_api_service_client = api_client()
@@ -80,7 +80,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
Verify that the provided api client uses the expected user to generate
JWT token for auth.
"""
mocked_jwt_builder.return_value.build_token.return_value = 'test-token'
mocked_jwt_builder.return_value = 'test-token'
dummy_enterprise_user = UserFactory.create(
username='dummy-enterprise-user',
email='dummy-enterprise-user@example.com',
@@ -117,10 +117,10 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
self.assertEqual(cached_enterprise_customer, enterprise_customer)
@httpretty.activate
@mock.patch('openedx.features.enterprise_support.api.JwtBuilder')
@mock.patch('openedx.features.enterprise_support.api.create_jwt_for_user')
def test_enterprise_api_client_with_service_user(self, mock_jwt_builder):
"""
Verify that enterprise API service client uses enterprise service user
Verify that enterprise API service client uses enterprcreate_jwt_for_userise service user
by default to authenticate and access enterprise API.
"""
self._assert_api_service_client(EnterpriseApiServiceClient, mock_jwt_builder)
@@ -138,7 +138,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
self._assert_get_enterprise_customer(enterprise_api_client, enterprise_api_data_for_mock_2)
@httpretty.activate
@mock.patch('openedx.features.enterprise_support.api.JwtBuilder')
@mock.patch('openedx.features.enterprise_support.api.create_jwt_for_user')
def test_enterprise_api_client_with_user(self, mock_jwt_builder):
"""
Verify that enterprise API client uses the provided user to
@@ -147,7 +147,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
self._assert_api_client_with_user(EnterpriseApiClient, mock_jwt_builder)
@httpretty.activate
@mock.patch('openedx.features.enterprise_support.api.JwtBuilder')
@mock.patch('openedx.features.enterprise_support.api.create_jwt_for_user')
def test_enterprise_consent_api_client_with_service_user(self, mock_jwt_builder):
"""
Verify that enterprise API consent service client uses enterprise
@@ -156,7 +156,7 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase):
self._assert_api_service_client(ConsentApiServiceClient, mock_jwt_builder)
@httpretty.activate
@mock.patch('openedx.features.enterprise_support.api.JwtBuilder')
@mock.patch('openedx.features.enterprise_support.api.create_jwt_for_user')
def test_enterprise_consent_api_client_with_user(self, mock_jwt_builder):
"""
Verify that enterprise API consent service client uses the provided

View File

@@ -12,9 +12,9 @@ from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from edx_rest_api_client.client import EdxRestApiClient
from openedx.core.djangoapps.catalog.models import CatalogIntegration
from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.waffle_utils import WaffleSwitchNamespace
from openedx.core.lib.token_utils import JwtBuilder
from slumber.exceptions import HttpClientError, HttpServerError
@@ -54,7 +54,7 @@ class DiscoveryApiClient(object):
LOGGER.error("Unable to retrieve catalog integration service user")
return None
jwt = JwtBuilder(user).build_token([])
jwt = create_jwt_for_user(user)
base_url = configuration_helpers.get_value('COURSE_CATALOG_URL_BASE', settings.COURSE_CATALOG_URL_BASE)
self.client = EdxRestApiClient(
'{base_url}{journals_path}'.format(base_url=base_url, journals_path=JOURNALS_API_PATH),
@@ -110,7 +110,7 @@ class JournalsApiClient(object):
LOGGER.error(error)
raise ValueError(error)
jwt = JwtBuilder(self.user).build_token(['email', 'profile'], 16000)
jwt = create_jwt_for_user(self.user)
self.client = EdxRestApiClient(
configuration_helpers.get_value('JOURNALS_API_URL', settings.JOURNALS_API_URL),
jwt=jwt