Applied pylint-amnesty to third_party_auth
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Third party authentication. """
|
||||
"""Third party authentication. """ # lint-amnesty, pylint: disable=django-not-configured
|
||||
|
||||
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
|
||||
@@ -56,7 +56,7 @@ class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin):
|
||||
"""
|
||||
Filter the queryset to exclude the archived records.
|
||||
"""
|
||||
queryset = super(SAMLProviderConfigAdmin, self).get_queryset(request).exclude(archived=True)
|
||||
queryset = super(SAMLProviderConfigAdmin, self).get_queryset(request).exclude(archived=True) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
return queryset
|
||||
|
||||
def archive_provider_configuration(self, request, queryset):
|
||||
@@ -81,7 +81,7 @@ class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin):
|
||||
"""
|
||||
Get the actions.
|
||||
"""
|
||||
actions = super(SAMLProviderConfigAdmin, self).get_actions(request)
|
||||
actions = super(SAMLProviderConfigAdmin, self).get_actions(request) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
action_delete = {
|
||||
'archive_provider_configuration': (
|
||||
SAMLProviderConfigAdmin.archive_provider_configuration,
|
||||
@@ -128,7 +128,7 @@ class SAMLProviderConfigAdmin(KeyedConfigurationModelAdmin):
|
||||
Note: This only works if the celery worker and the app worker are using the
|
||||
same 'configuration' cache.
|
||||
"""
|
||||
super(SAMLProviderConfigAdmin, self).save_model(request, obj, form, change)
|
||||
super(SAMLProviderConfigAdmin, self).save_model(request, obj, form, change) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
fetch_saml_metadata.apply_async((), countdown=2)
|
||||
|
||||
admin.site.register(SAMLProviderConfig, SAMLProviderConfigAdmin)
|
||||
|
||||
@@ -12,7 +12,7 @@ class UserMappingSerializer(serializers.Serializer): # pylint: disable=abstract
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.provider = kwargs['context'].get('provider', None)
|
||||
super(UserMappingSerializer, self).__init__(*args, **kwargs)
|
||||
super(UserMappingSerializer, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def get_username(self, social_user):
|
||||
""" Gets the edx username from a social user """
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.conf import settings
|
||||
from django.test import RequestFactory, TestCase
|
||||
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
|
||||
from edx_rest_framework_extensions.auth.jwt.tests.utils import generate_jwt
|
||||
from mock import patch
|
||||
from mock import patch # lint-amnesty, pylint: disable=unused-import
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
@@ -33,7 +33,7 @@ class ThirdPartyAuthPermissionTest(TestCase):
|
||||
permission_classes = (TPA_PERMISSIONS,)
|
||||
required_scopes = ['tpa:read']
|
||||
|
||||
def get(self, request, provider_id=None):
|
||||
def get(self, request, provider_id=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
return Response(data="Success")
|
||||
|
||||
def _create_user(self, is_superuser=False, is_staff=False):
|
||||
|
||||
@@ -49,7 +49,7 @@ class TpaAPITestCase(ThirdPartyAuthTestMixin, APITestCase):
|
||||
|
||||
def setUp(self): # pylint: disable=arguments-differ
|
||||
""" Create users for use in the tests """
|
||||
super(TpaAPITestCase, self).setUp()
|
||||
super(TpaAPITestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
google = self.configure_google_provider(enabled=True)
|
||||
self.configure_facebook_provider(enabled=True)
|
||||
@@ -364,7 +364,7 @@ class TestThirdPartyAuthUserStatusView(ThirdPartyAuthTestMixin, APITestCase):
|
||||
"""
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestThirdPartyAuthUserStatusView, self).setUp(*args, **kwargs)
|
||||
super(TestThirdPartyAuthUserStatusView, self).setUp(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = UserFactory.create(password=PASSWORD)
|
||||
self.google_provider = self.configure_google_provider(enabled=True, visible=True)
|
||||
self.url = reverse('third_party_auth_user_status_api')
|
||||
|
||||
@@ -6,7 +6,7 @@ Third Party Auth REST API views
|
||||
from collections import namedtuple
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.db.models import Q
|
||||
from django.http import Http404
|
||||
from django.urls import reverse
|
||||
@@ -40,7 +40,7 @@ class ProviderBaseThrottle(throttling.UserRateThrottle):
|
||||
Only throttle unprivileged requests.
|
||||
"""
|
||||
if view.is_unprivileged_query(request, view.get_identifier_for_requested_user(request)):
|
||||
return super(ProviderBaseThrottle, self).allow_request(request, view)
|
||||
return super(ProviderBaseThrottle, self).allow_request(request, view) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
return True
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ class UserView(BaseUserView):
|
||||
login.
|
||||
"""
|
||||
|
||||
def get(self, request, username):
|
||||
def get(self, request, username): # lint-amnesty, pylint: disable=unused-argument
|
||||
"""Read provider information for a user.
|
||||
|
||||
Allows reading the list of providers for a specified user.
|
||||
@@ -378,7 +378,7 @@ class UserMappingView(ListAPIView):
|
||||
Extra context provided to the serializer class with current provider. We need the provider to
|
||||
remove idp_slug from the remote_id if there is any
|
||||
"""
|
||||
context = super(UserMappingView, self).get_serializer_context()
|
||||
context = super(UserMappingView, self).get_serializer_context() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
context['provider'] = self.provider
|
||||
|
||||
return context
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
# lint-amnesty, pylint: disable=missing-module-docstring
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class ThirdPartyAuthConfig(AppConfig):
|
||||
class ThirdPartyAuthConfig(AppConfig): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
name = 'common.djangoapps.third_party_auth'
|
||||
verbose_name = "Third-party authentication"
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ Decorators that can be used to interact with third_party_auth.
|
||||
from functools import wraps
|
||||
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect
|
||||
from django.shortcuts import redirect # lint-amnesty, pylint: disable=unused-import
|
||||
from django.utils.decorators import available_attrs
|
||||
from six.moves.urllib.parse import urlencode, urlparse
|
||||
from six.moves.urllib.parse import urlencode, urlparse # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from common.djangoapps.third_party_auth.models import LTIProviderConfig
|
||||
from common.djangoapps.third_party_auth.provider import Registry
|
||||
from common.djangoapps.third_party_auth.provider import Registry # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
|
||||
def xframe_allow_whitelisted(view_func):
|
||||
|
||||
@@ -51,7 +51,7 @@ class LTIAuthBackend(BaseAuth):
|
||||
# Set a auth_entry here so we don't have to receive that as a custom parameter
|
||||
self.strategy.session_setdefault('auth_entry', 'login')
|
||||
|
||||
if not validated_lti_params:
|
||||
if not validated_lti_params: # lint-amnesty, pylint: disable=no-else-raise
|
||||
self.strategy.session_set(LTI_PARAMS_KEY, None)
|
||||
raise AuthFailed(self, "LTI parameters could not be validated.")
|
||||
else:
|
||||
|
||||
@@ -7,7 +7,7 @@ integration sandboxes to allow partners reset users and enrollment data.
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from six.moves import input
|
||||
@@ -45,7 +45,7 @@ class Command(BaseCommand):
|
||||
try:
|
||||
SAMLProviderConfig.objects.current_set().get(slug=slug)
|
||||
except SAMLProviderConfig.DoesNotExist:
|
||||
raise CommandError(u'No SAML provider found for slug {}'.format(slug))
|
||||
raise CommandError(u'No SAML provider found for slug {}'.format(slug)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
users = User.objects.filter(social_auth__provider=slug)
|
||||
user_count = len(users)
|
||||
|
||||
@@ -35,7 +35,7 @@ class TestRemoveSocialAuthUsersCommand(TestCase):
|
||||
cls.command = remove_social_auth_users.Command()
|
||||
|
||||
def setUp(self):
|
||||
super(TestRemoveSocialAuthUsersCommand, self).setUp()
|
||||
super(TestRemoveSocialAuthUsersCommand, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.provider_hogwarts = SAMLProviderConfigFactory.create(slug='hogwarts')
|
||||
self.provider_durmstrang = SAMLProviderConfigFactory.create(slug='durmstrang')
|
||||
|
||||
@@ -47,7 +47,7 @@ class TestRemoveSocialAuthUsersCommand(TestCase):
|
||||
self.create_social_auth_entry(self.user_viktor, self.provider_durmstrang)
|
||||
|
||||
@contextmanager
|
||||
def _replace_stdin(self, text):
|
||||
def _replace_stdin(self, text): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
orig = sys.stdin
|
||||
sys.stdin = StringIO(text)
|
||||
yield
|
||||
|
||||
@@ -27,7 +27,7 @@ def mock_get(status_code=200):
|
||||
Returns:
|
||||
returns a function that can be used as a mock function for requests.get.
|
||||
"""
|
||||
def _(url=None, *args, **kwargs): # pylint: disable=unused-argument
|
||||
def _(url=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg, unused-argument
|
||||
"""
|
||||
mock method for requests.get, this method will read xml file, form a Response object from the
|
||||
contents of this file, set status code and return the Response object.
|
||||
@@ -56,7 +56,7 @@ class TestSAMLCommand(CacheIsolationTestCase):
|
||||
Setup operations for saml configurations. these operations contain
|
||||
creation of SAMLConfiguration and SAMLProviderConfig records in database.
|
||||
"""
|
||||
super(TestSAMLCommand, self).setUp()
|
||||
super(TestSAMLCommand, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
self.stdout = StringIO()
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class ExceptionMiddleware(SocialAuthExceptionMiddleware, MiddlewareMixin):
|
||||
|
||||
def get_redirect_uri(self, request, exception):
|
||||
# Fall back to django settings's SOCIAL_AUTH_LOGIN_ERROR_URL.
|
||||
redirect_uri = super(ExceptionMiddleware, self).get_redirect_uri(request, exception)
|
||||
redirect_uri = super(ExceptionMiddleware, self).get_redirect_uri(request, exception) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
# Safe because it's already been validated by
|
||||
# pipeline.parse_query_params. If that pipeline step ever moves later
|
||||
@@ -48,4 +48,4 @@ class ExceptionMiddleware(SocialAuthExceptionMiddleware, MiddlewareMixin):
|
||||
redirect_url = get_next_url_for_login_page(request)
|
||||
return redirect('/login?next=' + redirect_url)
|
||||
|
||||
return super(ExceptionMiddleware, self).process_exception(request, exception)
|
||||
return super(ExceptionMiddleware, self).process_exception(request, exception) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
@@ -60,7 +60,7 @@ def clean_json(value, of_type):
|
||||
try:
|
||||
value_python = json.loads(value)
|
||||
except ValueError as err:
|
||||
raise ValidationError(u"Invalid JSON: {}".format(err))
|
||||
raise ValidationError(u"Invalid JSON: {}".format(err)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
if not isinstance(value_python, of_type):
|
||||
raise ValidationError(u"Expected a JSON {}".format(of_type))
|
||||
return json.dumps(value_python, indent=4)
|
||||
@@ -74,7 +74,7 @@ def clean_username(username=''):
|
||||
class AuthNotConfigured(SocialAuthBaseException):
|
||||
""" Exception when SAMLProviderData or other required info is missing """
|
||||
def __init__(self, provider_name):
|
||||
super(AuthNotConfigured, self).__init__()
|
||||
super(AuthNotConfigured, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.provider_name = provider_name
|
||||
|
||||
def __str__(self):
|
||||
@@ -224,7 +224,7 @@ class ProviderConfig(ConfigurationModel):
|
||||
|
||||
def clean(self):
|
||||
""" Ensure that at most `icon_class` or `icon_image` is set """
|
||||
super(ProviderConfig, self).clean()
|
||||
super(ProviderConfig, self).clean() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
if bool(self.icon_class) and bool(self.icon_image):
|
||||
raise ValidationError('Either an icon class or an icon image must be given (but not both)')
|
||||
|
||||
@@ -379,7 +379,7 @@ class OAuth2ProviderConfig(ProviderConfig):
|
||||
|
||||
def clean(self):
|
||||
""" Standardize and validate fields """
|
||||
super(OAuth2ProviderConfig, self).clean()
|
||||
super(OAuth2ProviderConfig, self).clean() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.other_settings = clean_json(self.other_settings, dict)
|
||||
|
||||
def get_setting(self, name):
|
||||
@@ -483,7 +483,7 @@ class SAMLConfiguration(ConfigurationModel):
|
||||
|
||||
def clean(self):
|
||||
""" Standardize and validate fields """
|
||||
super(SAMLConfiguration, self).clean()
|
||||
super(SAMLConfiguration, self).clean() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.org_info_str = clean_json(self.org_info_str, dict)
|
||||
self.other_config_str = clean_json(self.other_config_str, dict)
|
||||
|
||||
@@ -686,7 +686,7 @@ class SAMLProviderConfig(ProviderConfig):
|
||||
|
||||
def clean(self):
|
||||
""" Standardize and validate fields """
|
||||
super(SAMLProviderConfig, self).clean()
|
||||
super(SAMLProviderConfig, self).clean() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.other_settings = clean_json(self.other_settings, dict)
|
||||
|
||||
class Meta(object):
|
||||
|
||||
@@ -70,7 +70,7 @@ from uuid import uuid4
|
||||
import six
|
||||
import social_django
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.contrib.auth import logout
|
||||
from django.core.mail.message import EmailMessage
|
||||
from django.http import HttpResponseBadRequest
|
||||
@@ -141,7 +141,7 @@ BASE_URL = settings.AUTHN_MICROFRONTEND_URL if should_redirect_to_authn_microfro
|
||||
|
||||
def is_api(auth_entry):
|
||||
"""Returns whether the auth entry point is via an API call."""
|
||||
return (auth_entry == AUTH_ENTRY_LOGIN_API) or (auth_entry == AUTH_ENTRY_REGISTER_API)
|
||||
return (auth_entry == AUTH_ENTRY_LOGIN_API) or (auth_entry == AUTH_ENTRY_REGISTER_API) # lint-amnesty, pylint: disable=consider-using-in
|
||||
|
||||
# URLs associated with auth entry points
|
||||
# These are used to request additional user information
|
||||
@@ -550,7 +550,7 @@ def redirect_to_custom_form(request, auth_entry, details, kwargs):
|
||||
|
||||
|
||||
@partial.partial
|
||||
def ensure_user_information(strategy, auth_entry, backend=None, user=None, social=None, current_partial=None,
|
||||
def ensure_user_information(strategy, auth_entry, backend=None, user=None, social=None, current_partial=None, # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
allow_inactive_user=False, details=None, *args, **kwargs):
|
||||
"""
|
||||
Ensure that we have the necessary information about a user (either an
|
||||
@@ -654,7 +654,7 @@ def ensure_user_information(strategy, auth_entry, backend=None, user=None, socia
|
||||
|
||||
|
||||
@partial.partial
|
||||
def set_logged_in_cookies(backend=None, user=None, strategy=None, auth_entry=None, current_partial=None,
|
||||
def set_logged_in_cookies(backend=None, user=None, strategy=None, auth_entry=None, current_partial=None, # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
*args, **kwargs):
|
||||
"""This pipeline step sets the "logged in" cookie for authenticated users.
|
||||
|
||||
@@ -706,7 +706,7 @@ def set_logged_in_cookies(backend=None, user=None, strategy=None, auth_entry=Non
|
||||
|
||||
|
||||
@partial.partial
|
||||
def login_analytics(strategy, auth_entry, current_partial=None, *args, **kwargs):
|
||||
def login_analytics(strategy, auth_entry, current_partial=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
""" Sends login info to Segment """
|
||||
|
||||
event_name = None
|
||||
@@ -724,7 +724,7 @@ def login_analytics(strategy, auth_entry, current_partial=None, *args, **kwargs)
|
||||
|
||||
|
||||
@partial.partial
|
||||
def associate_by_email_if_login_api(auth_entry, backend, details, user, current_partial=None, *args, **kwargs):
|
||||
def associate_by_email_if_login_api(auth_entry, backend, details, user, current_partial=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
"""
|
||||
This pipeline step associates the current social auth with the user with the
|
||||
same email address in the database. It defers to the social library's associate_by_email
|
||||
@@ -834,7 +834,7 @@ def associate_by_email_if_saml(auth_entry, backend, details, user, strategy, *ar
|
||||
return associate_response
|
||||
|
||||
|
||||
def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **kwargs):
|
||||
def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
"""
|
||||
Update normally protected user details using data from provider.
|
||||
|
||||
@@ -921,7 +921,7 @@ def user_details_force_sync(auth_entry, strategy, details, user=None, *args, **k
|
||||
u'notification email. Username: {username}'.format(username=user.username))
|
||||
|
||||
|
||||
def set_id_verification_status(auth_entry, strategy, details, user=None, *args, **kwargs):
|
||||
def set_id_verification_status(auth_entry, strategy, details, user=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
"""
|
||||
Use the user's authentication with the provider, if configured, as evidence of their identity being verified.
|
||||
"""
|
||||
@@ -949,7 +949,7 @@ def set_id_verification_status(auth_entry, strategy, details, user=None, *args,
|
||||
verification.send_approval_signal(current_provider.slug)
|
||||
|
||||
|
||||
def get_username(strategy, details, backend, user=None, *args, **kwargs):
|
||||
def get_username(strategy, details, backend, user=None, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
"""
|
||||
Copy of social_core.pipeline.user.get_username to achieve
|
||||
1. additional logging
|
||||
|
||||
@@ -83,23 +83,23 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
|
||||
config["sp"].update(self.get_idp_setting(idp, "SP_EXTRA", {}))
|
||||
return config
|
||||
else:
|
||||
return super(SAMLAuthBackend, self).generate_saml_config()
|
||||
return super(SAMLAuthBackend, self).generate_saml_config() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def get_user_id(self, details, response):
|
||||
"""
|
||||
Calling the parent function and handling the exception properly.
|
||||
"""
|
||||
try:
|
||||
return super(SAMLAuthBackend, self).get_user_id(details, response)
|
||||
return super(SAMLAuthBackend, self).get_user_id(details, response) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
except KeyError as ex:
|
||||
log.warning(
|
||||
u'[THIRD_PARTY_AUTH] Error in SAML authentication flow. '
|
||||
u'Provider: {idp_name}, Message: {message}'.format(
|
||||
message=ex.message,
|
||||
message=ex.message, # lint-amnesty, pylint: disable=no-member
|
||||
idp_name=response.get('idp_name')
|
||||
)
|
||||
)
|
||||
raise IncorrectConfigurationException(self)
|
||||
raise IncorrectConfigurationException(self) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
def generate_metadata_xml(self, idp_name=None): # pylint: disable=arguments-differ
|
||||
"""
|
||||
@@ -127,7 +127,7 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
|
||||
log.error('[THIRD_PARTY_AUTH] SAML authentication is not enabled')
|
||||
raise Http404
|
||||
|
||||
return super(SAMLAuthBackend, self).auth_url()
|
||||
return super(SAMLAuthBackend, self).auth_url() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def disconnect(self, *args, **kwargs):
|
||||
"""
|
||||
@@ -136,7 +136,7 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
|
||||
from openedx.features.enterprise_support.api import unlink_enterprise_user_from_idp
|
||||
user = kwargs.get('user', None)
|
||||
unlink_enterprise_user_from_idp(self.strategy.request, user, self.name)
|
||||
return super(SAMLAuthBackend, self).disconnect(*args, **kwargs)
|
||||
return super(SAMLAuthBackend, self).disconnect(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def _check_entitlements(self, idp, attributes):
|
||||
"""
|
||||
@@ -165,7 +165,7 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
|
||||
"""
|
||||
# We only override this method so that we can add extra debugging when debug_mode is True
|
||||
# Note that auth_inst is instantiated just for the current HTTP request, then is destroyed
|
||||
auth_inst = super(SAMLAuthBackend, self)._create_saml_auth(idp)
|
||||
auth_inst = super(SAMLAuthBackend, self)._create_saml_auth(idp) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
from .models import SAMLProviderConfig
|
||||
if SAMLProviderConfig.current(idp.name).debug_mode:
|
||||
|
||||
@@ -207,7 +207,7 @@ class EdXSAMLIdentityProvider(SAMLIdentityProvider):
|
||||
Overrides `get_user_details` from the base class; retrieves those details,
|
||||
then updates the dict with values from whatever additional fields are desired.
|
||||
"""
|
||||
details = super(EdXSAMLIdentityProvider, self).get_user_details(attributes)
|
||||
details = super(EdXSAMLIdentityProvider, self).get_user_details(attributes) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
extra_field_definitions = self.conf.get('extra_field_definitions', [])
|
||||
details.update({
|
||||
field['name']: attributes[field['urn']][0] if field['urn'] in attributes else None
|
||||
@@ -382,7 +382,7 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider):
|
||||
)
|
||||
return missing
|
||||
|
||||
def log_bizx_api_exception(self, transaction_data, err):
|
||||
def log_bizx_api_exception(self, transaction_data, err): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
try:
|
||||
sys_msg = err.response.content
|
||||
except AttributeError:
|
||||
@@ -476,7 +476,7 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider):
|
||||
return None
|
||||
return token_response.json()
|
||||
|
||||
def get_bizx_odata_api_client(self, user_id):
|
||||
def get_bizx_odata_api_client(self, user_id): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
session = requests.Session()
|
||||
access_token_data = self.generate_bizx_oauth_api_access_token(user_id)
|
||||
if not access_token_data:
|
||||
@@ -492,7 +492,7 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider):
|
||||
of the info we need to do that, or if the request triggers an exception, then fail nicely by
|
||||
returning the basic user details we're able to extract from just the SAML response.
|
||||
"""
|
||||
basic_details = super(SapSuccessFactorsIdentityProvider, self).get_user_details(attributes)
|
||||
basic_details = super(SapSuccessFactorsIdentityProvider, self).get_user_details(attributes) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
if self.invalid_configuration():
|
||||
return basic_details
|
||||
user_id = basic_details['username']
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
Tests for SAMLConfiguration endpoints
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
from django.urls import reverse
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
from common.djangoapps.third_party_auth.models import SAMLConfiguration
|
||||
from common.djangoapps.third_party_auth.tests import testutil
|
||||
from common.djangoapps.third_party_auth.tests import testutil # lint-amnesty, pylint: disable=unused-import
|
||||
from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth
|
||||
SAML_CONFIGURATIONS = [
|
||||
{
|
||||
@@ -77,7 +77,7 @@ class SAMLConfigurationTests(APITestCase):
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(SAMLConfigurationTests, self).setUp()
|
||||
super(SAMLConfigurationTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.client.login(username=self.user.username, password=TEST_PASSWORD)
|
||||
|
||||
def test_get_saml_configurations_successful(self):
|
||||
|
||||
@@ -7,7 +7,7 @@ from rest_framework import serializers
|
||||
from common.djangoapps.third_party_auth.models import SAMLProviderConfig, SAMLConfiguration
|
||||
|
||||
|
||||
class SAMLProviderConfigSerializer(serializers.ModelSerializer):
|
||||
class SAMLProviderConfigSerializer(serializers.ModelSerializer): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
saml_config_id = serializers.IntegerField(required=False)
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -95,7 +95,7 @@ class SAMLProviderConfigViewSet(PermissionRequiredMixin, SAMLProviderMixin, view
|
||||
try:
|
||||
enterprise_customer = EnterpriseCustomer.objects.get(pk=customer_uuid)
|
||||
except EnterpriseCustomer.DoesNotExist:
|
||||
raise ValidationError('Enterprise customer not found at uuid: {}'.format(customer_uuid))
|
||||
raise ValidationError('Enterprise customer not found at uuid: {}'.format(customer_uuid)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
# Create the samlproviderconfig model first
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
|
||||
@@ -57,7 +57,7 @@ class SAMLProviderDataViewSet(PermissionRequiredMixin, SAMLProviderDataMixin, vi
|
||||
saml_provider = SAMLProviderConfig.objects.current_set().get(
|
||||
slug=convert_saml_slug_provider_id(enterprise_customer_idp.provider_id))
|
||||
except SAMLProviderConfig.DoesNotExist:
|
||||
raise Http404('No matching SAML provider found.')
|
||||
raise Http404('No matching SAML provider found.') # lint-amnesty, pylint: disable=raise-missing-from
|
||||
return SAMLProviderData.objects.filter(entity_id=saml_provider.entity_id)
|
||||
|
||||
@property
|
||||
|
||||
@@ -57,4 +57,4 @@ class ConfigurationModelStrategy(DjangoStrategy):
|
||||
|
||||
# At this point, we know 'name' is not set in a [OAuth2|LTI|SAML]ProviderConfig row.
|
||||
# It's probably a global Django setting like 'FIELDS_STORED_IN_SESSION':
|
||||
return super(ConfigurationModelStrategy, self).setting(name, default, backend)
|
||||
return super(ConfigurationModelStrategy, self).setting(name, default, backend) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
@@ -28,7 +28,7 @@ SAML_XML_NS = 'urn:oasis:names:tc:SAML:2.0:metadata' # The SAML Metadata XML na
|
||||
|
||||
class MetadataParseError(Exception):
|
||||
""" An error occurred while parsing the SAML metadata from an IdP """
|
||||
pass
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
@shared_task
|
||||
@@ -89,7 +89,7 @@ def fetch_saml_metadata():
|
||||
try:
|
||||
parser = etree.XMLParser(remove_comments=True)
|
||||
xml = etree.fromstring(response.content, parser)
|
||||
except etree.XMLSyntaxError:
|
||||
except etree.XMLSyntaxError: # lint-amnesty, pylint: disable=try-except-raise
|
||||
raise
|
||||
# TODO: Can use OneLogin_Saml2_Utils to validate signed XML if anyone is using that
|
||||
|
||||
@@ -125,7 +125,7 @@ def fetch_saml_metadata():
|
||||
log.exception(text_type(error))
|
||||
failure_messages.append(
|
||||
u"XMLSyntaxError: {error_message}\nMetadata Source: {url}\nEntity IDs: \n{entity_ids}.".format(
|
||||
error_message=str(error.error_log),
|
||||
error_message=str(error.error_log), # lint-amnesty, pylint: disable=no-member
|
||||
url=url,
|
||||
entity_ids="\n".join(
|
||||
[u"\t{}: {}".format(count, item) for count, item in enumerate(entity_ids, start=1)],
|
||||
@@ -183,7 +183,7 @@ def _parse_metadata_xml(xml, entity_id):
|
||||
# The only binding supported by python-saml and python-social-auth is HTTP-Redirect:
|
||||
sso_url = sso_bindings['urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect']
|
||||
except KeyError:
|
||||
raise MetadataParseError("Unable to find SSO URL with HTTP-Redirect binding.")
|
||||
raise MetadataParseError("Unable to find SSO URL with HTTP-Redirect binding.") # lint-amnesty, pylint: disable=raise-missing-from
|
||||
return public_key, sso_url, expires_at
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from django.contrib.messages.storage import fallback
|
||||
from django.contrib.sessions.backends import cache
|
||||
from django.urls import reverse
|
||||
from django.test import utils as django_utils
|
||||
from django.conf import settings as django_settings
|
||||
from django.conf import settings as django_settings # lint-amnesty, pylint: disable=reimported
|
||||
from social_core import actions, exceptions
|
||||
from social_django import utils as social_utils
|
||||
from social_django import views as social_views
|
||||
@@ -58,7 +58,7 @@ class HelperMixin(object):
|
||||
self.assertEqual(302, response.status_code)
|
||||
self.assertTrue(response.has_header('Location'))
|
||||
|
||||
def assert_register_response_in_pipeline_looks_correct(self, response, pipeline_kwargs, required_fields):
|
||||
def assert_register_response_in_pipeline_looks_correct(self, response, pipeline_kwargs, required_fields): # lint-amnesty, pylint: disable=invalid-name
|
||||
"""Performs spot checks of the rendered register.html page.
|
||||
|
||||
When we display the new account registration form after the user signs
|
||||
@@ -366,7 +366,7 @@ class IntegrationTestMixin(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
USER_USERNAME = "override"
|
||||
|
||||
def setUp(self):
|
||||
super(IntegrationTestMixin, self).setUp()
|
||||
super(IntegrationTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
self.request_factory = test.RequestFactory()
|
||||
self.login_page_url = reverse('signin_user')
|
||||
@@ -536,7 +536,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
"""Abstract base class for provider integration tests."""
|
||||
|
||||
def setUp(self):
|
||||
super(IntegrationTest, self).setUp()
|
||||
super(IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.request_factory = test.RequestFactory()
|
||||
|
||||
# Actual tests, executed once per child.
|
||||
@@ -1023,7 +1023,7 @@ class IntegrationTest(testutil.TestCase, test.TestCase, HelperMixin):
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
@django_utils.override_settings(ECOMMERCE_API_URL=TEST_API_URL)
|
||||
class Oauth2IntegrationTest(IntegrationTest):
|
||||
class Oauth2IntegrationTest(IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests
|
||||
"""Base test case for integration tests of Oauth2 providers."""
|
||||
|
||||
# Dict of string -> object. Information about the token granted to the
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
from common.djangoapps.third_party_auth.tests.specs import base
|
||||
|
||||
|
||||
class AzureADOauth2IntegrationTest(base.Oauth2IntegrationTest):
|
||||
class AzureADOauth2IntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests
|
||||
"""Integration tests for Azure Active Directory / Microsoft Account provider."""
|
||||
|
||||
def setUp(self):
|
||||
super(AzureADOauth2IntegrationTest, self).setUp()
|
||||
super(AzureADOauth2IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.provider = self.configure_azure_ad_provider(
|
||||
enabled=True,
|
||||
visible=True,
|
||||
|
||||
@@ -3,7 +3,7 @@ Use the 'Dummy' auth provider for generic integration tests of third_party_auth.
|
||||
"""
|
||||
|
||||
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
from common.djangoapps.third_party_auth.tests import testutil
|
||||
from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth
|
||||
from .base import IntegrationTestMixin
|
||||
@@ -23,7 +23,7 @@ class GenericIntegrationTest(IntegrationTestMixin, testutil.TestCase):
|
||||
USER_USERNAME = "Galactica1"
|
||||
|
||||
def setUp(self):
|
||||
super(GenericIntegrationTest, self).setUp()
|
||||
super(GenericIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.configure_dummy_provider(enabled=True, visible=True)
|
||||
|
||||
def do_provider_login(self, provider_redirect_url):
|
||||
|
||||
@@ -16,11 +16,11 @@ from common.djangoapps.third_party_auth import pipeline
|
||||
from common.djangoapps.third_party_auth.tests.specs import base
|
||||
|
||||
|
||||
class GoogleOauth2IntegrationTest(base.Oauth2IntegrationTest):
|
||||
class GoogleOauth2IntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests
|
||||
"""Integration tests for provider.GoogleOauth2."""
|
||||
|
||||
def setUp(self):
|
||||
super(GoogleOauth2IntegrationTest, self).setUp()
|
||||
super(GoogleOauth2IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.provider = self.configure_google_provider(
|
||||
enabled=True,
|
||||
visible=True,
|
||||
@@ -50,7 +50,7 @@ class GoogleOauth2IntegrationTest(base.Oauth2IntegrationTest):
|
||||
return self.get_response_data().get('email').split('@')[0]
|
||||
|
||||
def assert_redirect_to_provider_looks_correct(self, response):
|
||||
super(GoogleOauth2IntegrationTest, self).assert_redirect_to_provider_looks_correct(response)
|
||||
super(GoogleOauth2IntegrationTest, self).assert_redirect_to_provider_looks_correct(response) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.assertIn('google.com', response['Location'])
|
||||
|
||||
def test_custom_form(self):
|
||||
|
||||
@@ -13,11 +13,11 @@ def get_localized_name(name):
|
||||
return name['localized'].get(locale, '')
|
||||
|
||||
|
||||
class LinkedInOauth2IntegrationTest(base.Oauth2IntegrationTest):
|
||||
class LinkedInOauth2IntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests
|
||||
"""Integration tests for provider.LinkedInOauth2."""
|
||||
|
||||
def setUp(self):
|
||||
super(LinkedInOauth2IntegrationTest, self).setUp()
|
||||
super(LinkedInOauth2IntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.provider = self.configure_linkedin_provider(
|
||||
enabled=True,
|
||||
visible=True,
|
||||
|
||||
@@ -5,7 +5,7 @@ Integration tests for third_party_auth LTI auth providers
|
||||
|
||||
import unittest
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.urls import reverse
|
||||
from oauthlib.oauth1.rfc5849 import Client, SIGNATURE_TYPE_BODY
|
||||
from common.djangoapps.third_party_auth.tests import testutil
|
||||
@@ -30,7 +30,7 @@ class IntegrationTestLTI(testutil.TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(IntegrationTestLTI, self).setUp()
|
||||
super(IntegrationTestLTI, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.hostname = 'testserver'
|
||||
self.client.defaults['SERVER_NAME'] = self.hostname
|
||||
self.url_prefix = 'http://{}'.format(self.hostname)
|
||||
|
||||
@@ -7,7 +7,7 @@ import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
from unittest import skip
|
||||
|
||||
import ddt
|
||||
@@ -53,27 +53,27 @@ class SamlIntegrationTestUtilities(object):
|
||||
USER_USERNAME = "myself"
|
||||
|
||||
def setUp(self):
|
||||
super(SamlIntegrationTestUtilities, self).setUp()
|
||||
self.enable_saml(
|
||||
private_key=self._get_private_key(),
|
||||
public_key=self._get_public_key(),
|
||||
super(SamlIntegrationTestUtilities, self).setUp() # lint-amnesty, pylint: disable=no-member, super-with-arguments
|
||||
self.enable_saml( # lint-amnesty, pylint: disable=no-member
|
||||
private_key=self._get_private_key(), # lint-amnesty, pylint: disable=no-member
|
||||
public_key=self._get_public_key(), # lint-amnesty, pylint: disable=no-member
|
||||
entity_id="https://saml.example.none",
|
||||
)
|
||||
# Mock out HTTP requests that may be made to TestShib:
|
||||
httpretty.enable()
|
||||
httpretty.reset()
|
||||
self.addCleanup(httpretty.reset)
|
||||
self.addCleanup(httpretty.disable)
|
||||
self.addCleanup(httpretty.reset) # lint-amnesty, pylint: disable=no-member
|
||||
self.addCleanup(httpretty.disable) # lint-amnesty, pylint: disable=no-member
|
||||
|
||||
def metadata_callback(_request, _uri, headers):
|
||||
""" Return a cached copy of TestShib's metadata by reading it from disk """
|
||||
return (200, headers, self.read_data_file('testshib_metadata.xml'))
|
||||
return (200, headers, self.read_data_file('testshib_metadata.xml')) # lint-amnesty, pylint: disable=no-member
|
||||
|
||||
httpretty.register_uri(httpretty.GET, TESTSHIB_METADATA_URL, content_type='text/xml', body=metadata_callback)
|
||||
|
||||
def cache_duration_metadata_callback(_request, _uri, headers):
|
||||
"""Return a cached copy of TestShib's metadata with a cacheDuration attribute"""
|
||||
return (200, headers, self.read_data_file('testshib_metadata_with_cache_duration.xml'))
|
||||
return (200, headers, self.read_data_file('testshib_metadata_with_cache_duration.xml')) # lint-amnesty, pylint: disable=no-member
|
||||
|
||||
httpretty.register_uri(
|
||||
httpretty.GET,
|
||||
@@ -86,14 +86,14 @@ class SamlIntegrationTestUtilities(object):
|
||||
# Doing this and freezing the time allows us to play back recorded request/response pairs
|
||||
uid_patch = patch('onelogin.saml2.utils.OneLogin_Saml2_Utils.generate_unique_id', return_value='TESTID')
|
||||
uid_patch.start()
|
||||
self.addCleanup(uid_patch.stop)
|
||||
self.addCleanup(uid_patch.stop) # lint-amnesty, pylint: disable=no-member
|
||||
self._freeze_time(timestamp=1434326820) # This is the time when the saved request/response was recorded.
|
||||
|
||||
def _freeze_time(self, timestamp):
|
||||
""" Mock the current time for SAML, so we can replay canned requests/responses """
|
||||
now_patch = patch('onelogin.saml2.utils.OneLogin_Saml2_Utils.now', return_value=timestamp)
|
||||
now_patch.start()
|
||||
self.addCleanup(now_patch.stop)
|
||||
self.addCleanup(now_patch.stop) # lint-amnesty, pylint: disable=no-member
|
||||
|
||||
def _configure_testshib_provider(self, **kwargs):
|
||||
""" Enable and configure the TestShib SAML IdP as a third_party_auth provider """
|
||||
@@ -114,28 +114,28 @@ class SamlIntegrationTestUtilities(object):
|
||||
saml_provider = self.configure_saml_provider(**kwargs) # pylint: disable=no-member
|
||||
|
||||
if fetch_metadata:
|
||||
self.assertTrue(httpretty.is_enabled())
|
||||
self.assertTrue(httpretty.is_enabled()) # lint-amnesty, pylint: disable=no-member
|
||||
num_total, num_skipped, num_attempted, num_updated, num_failed, failure_messages = fetch_saml_metadata()
|
||||
if assert_metadata_updates:
|
||||
self.assertEqual(num_total, 1)
|
||||
self.assertEqual(num_skipped, 0)
|
||||
self.assertEqual(num_attempted, 1)
|
||||
self.assertEqual(num_updated, 1)
|
||||
self.assertEqual(num_failed, 0)
|
||||
self.assertEqual(len(failure_messages), 0)
|
||||
self.assertEqual(num_total, 1) # lint-amnesty, pylint: disable=no-member
|
||||
self.assertEqual(num_skipped, 0) # lint-amnesty, pylint: disable=no-member
|
||||
self.assertEqual(num_attempted, 1) # lint-amnesty, pylint: disable=no-member
|
||||
self.assertEqual(num_updated, 1) # lint-amnesty, pylint: disable=no-member
|
||||
self.assertEqual(num_failed, 0) # lint-amnesty, pylint: disable=no-member
|
||||
self.assertEqual(len(failure_messages), 0) # lint-amnesty, pylint: disable=no-member
|
||||
return saml_provider
|
||||
|
||||
def do_provider_login(self, provider_redirect_url):
|
||||
""" Mocked: the user logs in to TestShib and then gets redirected back """
|
||||
# The SAML provider (TestShib) will authenticate the user, then get the browser to POST a response:
|
||||
self.assertTrue(provider_redirect_url.startswith(TESTSHIB_SSO_URL))
|
||||
self.assertTrue(provider_redirect_url.startswith(TESTSHIB_SSO_URL)) # lint-amnesty, pylint: disable=no-member
|
||||
|
||||
saml_response_xml = utils.read_and_pre_process_xml(
|
||||
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data', 'testshib_saml_response.xml')
|
||||
)
|
||||
|
||||
return self.client.post(
|
||||
self.complete_url,
|
||||
return self.client.post( # lint-amnesty, pylint: disable=no-member
|
||||
self.complete_url, # lint-amnesty, pylint: disable=no-member
|
||||
content_type='application/x-www-form-urlencoded',
|
||||
data=utils.prepare_saml_response_from_xml(saml_response_xml),
|
||||
)
|
||||
@@ -188,7 +188,7 @@ class TestShibIntegrationTest(SamlIntegrationTestUtilities, IntegrationTestMixin
|
||||
enterprise_customer = EnterpriseCustomerFactory()
|
||||
assert EnterpriseCustomerUser.objects.count() == 0, "Precondition check: no link records should exist"
|
||||
EnterpriseCustomerUser.objects.link_user(enterprise_customer, user.email)
|
||||
self.assertTrue(
|
||||
self.assertTrue( # lint-amnesty, pylint: disable=wrong-assert-type
|
||||
EnterpriseCustomerUser.objects.filter(enterprise_customer=enterprise_customer, user_id=user.id).count() == 1
|
||||
)
|
||||
EnterpriseCustomerIdentityProvider.objects.get_or_create(enterprise_customer=enterprise_customer,
|
||||
@@ -394,7 +394,7 @@ class SuccessFactorsIntegrationTest(SamlIntegrationTestUtilities, IntegrationTes
|
||||
"""
|
||||
Mock out HTTP calls to various endpoints using httpretty.
|
||||
"""
|
||||
super(SuccessFactorsIntegrationTest, self).setUp()
|
||||
super(SuccessFactorsIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
# Mock the call to the SAP SuccessFactors assertion endpoint
|
||||
SAPSF_ASSERTION_URL = 'http://successfactors.com/oauth/idp'
|
||||
@@ -467,7 +467,7 @@ class SuccessFactorsIntegrationTest(SamlIntegrationTestUtilities, IntegrationTes
|
||||
Mock an error response when calling the OData API for user details.
|
||||
"""
|
||||
|
||||
def callback(request, uri, headers):
|
||||
def callback(request, uri, headers): # lint-amnesty, pylint: disable=unused-argument
|
||||
"""
|
||||
Return a 500 error when someone tries to call the URL.
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""
|
||||
""" # lint-amnesty, pylint: disable=cyclic-import
|
||||
Separate integration test for Twitter which is an OAuth1 provider.
|
||||
"""
|
||||
|
||||
@@ -7,11 +7,11 @@ from mock import patch
|
||||
from common.djangoapps.third_party_auth.tests.specs import base
|
||||
|
||||
|
||||
class TwitterIntegrationTest(base.Oauth2IntegrationTest):
|
||||
class TwitterIntegrationTest(base.Oauth2IntegrationTest): # lint-amnesty, pylint: disable=test-inherits-tests
|
||||
"""Integration tests for Twitter backend."""
|
||||
|
||||
def setUp(self):
|
||||
super(TwitterIntegrationTest, self).setUp()
|
||||
super(TwitterIntegrationTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.provider = self.configure_twitter_provider(
|
||||
enabled=True,
|
||||
visible=True,
|
||||
|
||||
@@ -3,7 +3,7 @@ Tests third_party_auth admin views
|
||||
"""
|
||||
|
||||
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
|
||||
@@ -3,10 +3,10 @@ Tests for third_party_auth decorators.
|
||||
"""
|
||||
|
||||
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
import ddt
|
||||
from django.conf import settings
|
||||
from django.conf import settings # lint-amnesty, pylint: disable=unused-import
|
||||
from django.http import HttpResponse
|
||||
from django.test import RequestFactory
|
||||
|
||||
@@ -27,7 +27,7 @@ class TestXFrameWhitelistDecorator(TestCase):
|
||||
""" Test the xframe_allow_whitelisted decorator. """
|
||||
|
||||
def setUp(self):
|
||||
super(TestXFrameWhitelistDecorator, self).setUp()
|
||||
super(TestXFrameWhitelistDecorator, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.configure_lti_provider(name='Test', lti_hostname='localhost', lti_consumer_key='test_key', enabled=True)
|
||||
self.factory = RequestFactory()
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ Unit tests for the IdentityServer3 OAuth2 Backend
|
||||
"""
|
||||
import json
|
||||
import ddt
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import, wrong-import-order
|
||||
from common.djangoapps.third_party_auth.identityserver3 import IdentityServer3
|
||||
from common.djangoapps.third_party_auth.tests import testutil
|
||||
from common.djangoapps.third_party_auth.tests.utils import skip_unless_thirdpartyauth
|
||||
@@ -17,7 +17,7 @@ class IdentityServer3Test(testutil.TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(IdentityServer3Test, self).setUp()
|
||||
super(IdentityServer3Test, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.id3_instance = IdentityServer3()
|
||||
self.response = {
|
||||
"sub": "020cadec-919a-4b06-845e-57915bf76826",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
import json
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
@@ -63,7 +63,7 @@ class PipelineOverridesTest(SamlIntegrationTestUtilities, IntegrationTestMixin,
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(PipelineOverridesTest, self).setUp()
|
||||
super(PipelineOverridesTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.enable_saml()
|
||||
self.provider = self.configure_saml_provider(
|
||||
enabled=True,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
import datetime
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
@@ -27,7 +27,7 @@ class TestCase(testutil.TestCase, test.TestCase):
|
||||
"""Base test case."""
|
||||
|
||||
def setUp(self):
|
||||
super(TestCase, self).setUp()
|
||||
super(TestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.enabled_provider = self.configure_google_provider(enabled=True)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class GetAuthenticatedUserTestCase(TestCase):
|
||||
"""Tests for get_authenticated_user."""
|
||||
|
||||
def setUp(self):
|
||||
super(GetAuthenticatedUserTestCase, self).setUp()
|
||||
super(GetAuthenticatedUserTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = social_models.DjangoStorage.user.create_user(username='username', password='password')
|
||||
|
||||
def get_by_username(self, username):
|
||||
@@ -75,7 +75,7 @@ class GetProviderUserStatesTestCase(TestCase):
|
||||
"""Tests generation of ProviderUserStates."""
|
||||
|
||||
def setUp(self):
|
||||
super(GetProviderUserStatesTestCase, self).setUp()
|
||||
super(GetProviderUserStatesTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.configure_google_provider(enabled=False)
|
||||
self.user = social_models.DjangoStorage.user.create_user(username='username', password='password')
|
||||
|
||||
@@ -129,7 +129,7 @@ class GetProviderUserStatesTestCase(TestCase):
|
||||
|
||||
states = pipeline.get_provider_user_states(self.user)
|
||||
|
||||
self.assertEqual([], [x for x in social_models.DjangoStorage.user.objects.all()])
|
||||
self.assertEqual([], [x for x in social_models.DjangoStorage.user.objects.all()]) # lint-amnesty, pylint: disable=unnecessary-comprehension
|
||||
self.assertEqual(2, len(states))
|
||||
|
||||
google_state = [state for state in states if state.provider.provider_id == google_provider.provider_id][0]
|
||||
@@ -217,7 +217,7 @@ class TestPipelineUtilityFunctions(TestCase):
|
||||
Test some of the isolated utility functions in the pipeline
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestPipelineUtilityFunctions, self).setUp()
|
||||
super(TestPipelineUtilityFunctions, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = social_models.DjangoStorage.user.create_user(username='username', password='password')
|
||||
self.social_auth = social_models.UserSocialAuth.objects.create(
|
||||
user=self.user,
|
||||
@@ -307,7 +307,7 @@ class EnsureUserInformationTestCase(TestCase):
|
||||
"""Tests ensuring that we have the necessary user information to proceed with the pipeline."""
|
||||
|
||||
def setUp(self):
|
||||
super(EnsureUserInformationTestCase, self).setUp()
|
||||
super(EnsureUserInformationTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = social_models.DjangoStorage.user.create_user(
|
||||
username='username',
|
||||
password='password',
|
||||
@@ -325,12 +325,12 @@ class EnsureUserInformationTestCase(TestCase):
|
||||
based on the provider's setting for send_to_registration_first.
|
||||
"""
|
||||
|
||||
provider = mock.MagicMock(
|
||||
provider = mock.MagicMock( # lint-amnesty, pylint: disable=redefined-outer-name
|
||||
send_to_registration_first=send_to_registration_first,
|
||||
skip_email_verification=False
|
||||
)
|
||||
|
||||
with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline:
|
||||
with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline: # lint-amnesty, pylint: disable=line-too-long
|
||||
get_from_pipeline.return_value = provider
|
||||
with mock.patch('social_core.pipeline.partial.partial_prepare') as partial_prepare:
|
||||
partial_prepare.return_value = mock.MagicMock(token='')
|
||||
@@ -363,7 +363,7 @@ class EnsureUserInformationTestCase(TestCase):
|
||||
send_to_registration_first=True,
|
||||
skip_email_verification=False
|
||||
)
|
||||
with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline:
|
||||
with mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') as get_from_pipeline: # lint-amnesty, pylint: disable=line-too-long
|
||||
get_from_pipeline.return_value = saml_provider
|
||||
with mock.patch(
|
||||
'common.djangoapps.third_party_auth.pipeline.provider.Registry.get_enabled_by_backend_name'
|
||||
@@ -387,7 +387,7 @@ class UserDetailsForceSyncTestCase(TestCase):
|
||||
"""Tests to ensure learner profile data is properly synced if the provider requires it."""
|
||||
|
||||
def setUp(self):
|
||||
super(UserDetailsForceSyncTestCase, self).setUp()
|
||||
super(UserDetailsForceSyncTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = UserFactory.create()
|
||||
self.old_email = self.user.email
|
||||
self.old_username = self.user.username
|
||||
@@ -404,7 +404,7 @@ class UserDetailsForceSyncTestCase(TestCase):
|
||||
self.strategy = mock.MagicMock()
|
||||
self.strategy.storage.user.changed.side_effect = lambda user: user.save()
|
||||
|
||||
get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline')
|
||||
get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') # lint-amnesty, pylint: disable=line-too-long
|
||||
self.get_from_pipeline = get_from_pipeline.start()
|
||||
self.get_from_pipeline.return_value = mock.MagicMock(sync_learner_profile_data=True)
|
||||
self.addCleanup(get_from_pipeline.stop)
|
||||
@@ -491,7 +491,7 @@ class SetIDVerificationStatusTestCase(TestCase):
|
||||
"""Tests to ensure SSO ID Verification for the user is set if the provider requires it."""
|
||||
|
||||
def setUp(self):
|
||||
super(SetIDVerificationStatusTestCase, self).setUp()
|
||||
super(SetIDVerificationStatusTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = UserFactory.create()
|
||||
self.provider_class_name = 'common.djangoapps.third_party_auth.models.SAMLProviderConfig'
|
||||
self.provider_slug = 'default'
|
||||
@@ -501,7 +501,7 @@ class SetIDVerificationStatusTestCase(TestCase):
|
||||
self.strategy = mock.MagicMock()
|
||||
self.strategy.storage.user.changed.side_effect = lambda user: user.save()
|
||||
|
||||
get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline')
|
||||
get_from_pipeline = mock.patch('common.djangoapps.third_party_auth.pipeline.provider.Registry.get_from_pipeline') # lint-amnesty, pylint: disable=line-too-long
|
||||
self.get_from_pipeline = get_from_pipeline.start()
|
||||
self.get_from_pipeline.return_value = mock.MagicMock(
|
||||
enable_sso_id_verification=True,
|
||||
@@ -565,7 +565,7 @@ class SetIDVerificationStatusTestCase(TestCase):
|
||||
identity_provider_slug=self.provider_slug,
|
||||
)
|
||||
|
||||
with mock.patch('common.djangoapps.third_party_auth.pipeline.earliest_allowed_verification_date') as earliest_date:
|
||||
with mock.patch('common.djangoapps.third_party_auth.pipeline.earliest_allowed_verification_date') as earliest_date: # lint-amnesty, pylint: disable=line-too-long
|
||||
earliest_date.return_value = datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=1)
|
||||
# Begin the pipeline.
|
||||
pipeline.set_id_verification_status(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
import re
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
from django.db import connections, DEFAULT_DB_ALIAS
|
||||
@@ -178,7 +178,7 @@ class RegistryTest(testutil.TestCase):
|
||||
which doesn't match any of the possible backend_names.
|
||||
"""
|
||||
google_provider = self.configure_google_provider(enabled=True, slug='custom_slug')
|
||||
self.assertIn(google_provider, provider.Registry._enabled_providers())
|
||||
self.assertIn(google_provider, provider.Registry._enabled_providers()) # lint-amnesty, pylint: disable=protected-access
|
||||
self.assertIn(google_provider, provider.Registry.get_enabled_by_backend_name('google-oauth2'))
|
||||
|
||||
def test_oath2_different_slug_from_backend_name(self):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Unit tests for settings.py."""
|
||||
|
||||
|
||||
import unittest
|
||||
import unittest # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from mock import patch
|
||||
from common.djangoapps.third_party_auth import provider, settings
|
||||
@@ -32,7 +32,7 @@ class SettingsUnitTest(testutil.TestCase):
|
||||
# pylint: disable=no-member
|
||||
|
||||
def setUp(self):
|
||||
super(SettingsUnitTest, self).setUp()
|
||||
super(SettingsUnitTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.settings = testutil.FakeDjangoSettings(_SETTINGS_MAP)
|
||||
|
||||
def test_apply_settings_adds_exception_middleware(self):
|
||||
|
||||
@@ -164,7 +164,7 @@ class IdPRedirectViewTest(SAMLTestCase):
|
||||
Test IdPRedirectView.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(IdPRedirectViewTest, self).setUp()
|
||||
super(IdPRedirectViewTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
self.enable_saml()
|
||||
self.configure_saml_provider(
|
||||
|
||||
@@ -12,7 +12,7 @@ import django.test
|
||||
import mock
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.contrib.sites.models import Site
|
||||
from mako.template import Template
|
||||
from oauth2_provider.models import Application
|
||||
@@ -64,11 +64,11 @@ class ThirdPartyAuthTestMixin(object):
|
||||
patch.start()
|
||||
self.addCleanup(patch.stop)
|
||||
|
||||
super(ThirdPartyAuthTestMixin, self).setUp(*args, **kwargs)
|
||||
super(ThirdPartyAuthTestMixin, self).setUp(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def tearDown(self):
|
||||
config_cache.clear()
|
||||
super(ThirdPartyAuthTestMixin, self).tearDown()
|
||||
super(ThirdPartyAuthTestMixin, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def enable_saml(self, **kwargs):
|
||||
""" Enable SAML support (via SAMLConfiguration, not for any particular provider) """
|
||||
@@ -186,7 +186,7 @@ class TestCase(ThirdPartyAuthTestMixin, CacheIsolationMixin, django.test.TestCas
|
||||
"""Base class for auth test cases."""
|
||||
|
||||
def setUp(self): # pylint: disable=arguments-differ
|
||||
super(TestCase, self).setUp()
|
||||
super(TestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
# Explicitly set a server name that is compatible with all our providers:
|
||||
# (The SAML lib we use doesn't like the default 'testserver' as a domain)
|
||||
self.hostname = 'example.none'
|
||||
@@ -215,7 +215,7 @@ class SAMLTestCase(TestCase):
|
||||
if 'public_key' not in kwargs:
|
||||
kwargs['public_key'] = self._get_public_key()
|
||||
kwargs.setdefault('entity_id', "https://saml.example.none")
|
||||
super(SAMLTestCase, self).enable_saml(**kwargs)
|
||||
super(SAMLTestCase, self).enable_saml(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
@@ -33,8 +33,8 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin):
|
||||
|
||||
CREATE_USER = True
|
||||
|
||||
def setUp(self):
|
||||
super(ThirdPartyOAuthTestMixin, self).setUp()
|
||||
def setUp(self): # lint-amnesty, pylint: disable=arguments-differ
|
||||
super(ThirdPartyOAuthTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
if self.CREATE_USER:
|
||||
self.user = UserFactory()
|
||||
UserSocialAuth.objects.create(user=self.user, provider=self.BACKEND, uid=self.social_uid)
|
||||
@@ -45,7 +45,7 @@ class ThirdPartyOAuthTestMixin(ThirdPartyAuthTestMixin):
|
||||
self.configure_facebook_provider(enabled=True, visible=True)
|
||||
|
||||
def tearDown(self):
|
||||
super(ThirdPartyOAuthTestMixin, self).tearDown()
|
||||
super(ThirdPartyOAuthTestMixin, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
Partial.objects.all().delete()
|
||||
|
||||
def _create_client(self):
|
||||
|
||||
@@ -3,7 +3,7 @@ Utility functions for third_party_auth
|
||||
"""
|
||||
|
||||
from uuid import UUID
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from enterprise.models import EnterpriseCustomerUser, EnterpriseCustomerIdentityProvider
|
||||
from . import provider
|
||||
|
||||
@@ -49,7 +49,7 @@ def get_user_from_email(details):
|
||||
return None
|
||||
|
||||
|
||||
def convert_saml_slug_provider_id(provider):
|
||||
def convert_saml_slug_provider_id(provider): # lint-amnesty, pylint: disable=redefined-outer-name
|
||||
"""
|
||||
Provider id is stored with the backend type prefixed to it (ie "saml-")
|
||||
Slug is stored without this prefix.
|
||||
|
||||
@@ -125,7 +125,7 @@ class IdPRedirectView(View):
|
||||
GET auth/idp_redirect/saml-default
|
||||
|
||||
"""
|
||||
def get(self, request, *args, **kwargs):
|
||||
def get(self, request, *args, **kwargs): # lint-amnesty, pylint: disable=unused-argument
|
||||
"""
|
||||
Return either a redirect to the login page of an identity provider that
|
||||
corresponds to the provider_slug keyword argument or a 404 if the
|
||||
|
||||
Reference in New Issue
Block a user