Adding country to list of attrs, updating help text and max length
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Generated by Django 2.2.14 on 2020-07-21 19:08
|
||||
# Generated by Django 2.2.14 on 2020-07-22 22:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
@@ -13,6 +13,6 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='samlproviderconfig',
|
||||
name='country',
|
||||
field=models.CharField(blank=True, help_text=('String representation of the mapping between user`s IDP and edx`s country field.',), max_length=255),
|
||||
field=models.CharField(blank=True, help_text=('URN of SAML attribute containing the user`s country.',), max_length=128),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -619,9 +619,9 @@ class SAMLProviderConfig(ProviderConfig):
|
||||
),
|
||||
)
|
||||
country = models.CharField(
|
||||
max_length=255,
|
||||
max_length=128,
|
||||
help_text=(
|
||||
u'String representation of the mapping between user`s IDP and edx`s country field.',
|
||||
u'URN of SAML attribute containing the user`s country.',
|
||||
),
|
||||
blank=True,
|
||||
)
|
||||
@@ -699,7 +699,7 @@ class SAMLProviderConfig(ProviderConfig):
|
||||
conf = {}
|
||||
attrs = (
|
||||
'attr_user_permanent_id', 'attr_full_name', 'attr_first_name',
|
||||
'attr_last_name', 'attr_username', 'attr_email', 'entity_id')
|
||||
'attr_last_name', 'attr_username', 'attr_email', 'entity_id', 'country')
|
||||
attr_defaults = {
|
||||
'attr_full_name': 'default_full_name',
|
||||
'attr_first_name': 'default_first_name',
|
||||
|
||||
@@ -18,13 +18,14 @@ from third_party_auth.tests.samlutils import set_jwt_cookie
|
||||
from third_party_auth.models import SAMLProviderConfig
|
||||
from third_party_auth.tests import testutil
|
||||
|
||||
# country here refers to the URN provided by a user's IDP
|
||||
SINGLE_PROVIDER_CONFIG = {
|
||||
'entity_id': 'id',
|
||||
'metadata_source': 'http://test.url',
|
||||
'name': 'name-of-config',
|
||||
'enabled': 'true',
|
||||
'slug': 'test-slug',
|
||||
'country': 'https:://example.customer.com/countrycode'
|
||||
'country': 'https://example.customer.com/countrycode'
|
||||
}
|
||||
|
||||
SINGLE_PROVIDER_CONFIG_2 = copy.copy(SINGLE_PROVIDER_CONFIG)
|
||||
@@ -178,3 +179,42 @@ class SAMLProviderConfigTests(APITestCase):
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(SAMLProviderConfig.objects.count(), orig_count)
|
||||
|
||||
def test_create_one_config_with_no_country_urn(self):
|
||||
"""
|
||||
POST auth/saml/v0/provider_config/ -d data
|
||||
"""
|
||||
url = reverse('saml_provider_config-list')
|
||||
provider_config_no_country = {
|
||||
'entity_id': 'id',
|
||||
'metadata_source': 'http://test.url',
|
||||
'name': 'name-of-config-no-country',
|
||||
'enabled': 'true',
|
||||
'slug': 'test-slug-none',
|
||||
'enterprise_customer_uuid': ENTERPRISE_ID,
|
||||
}
|
||||
|
||||
response = self.client.post(url, provider_config_no_country)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
provider_config = SAMLProviderConfig.objects.get(slug='test-slug-none')
|
||||
self.assertEqual(provider_config.country, '')
|
||||
|
||||
def test_create_one_config_with_empty_country_urn(self):
|
||||
"""
|
||||
POST auth/saml/v0/provider_config/ -d data
|
||||
"""
|
||||
url = reverse('saml_provider_config-list')
|
||||
provider_config_blank_country = {
|
||||
'entity_id': 'id',
|
||||
'metadata_source': 'http://test.url',
|
||||
'name': 'name-of-config-blank-country',
|
||||
'enabled': 'true',
|
||||
'slug': 'test-slug-empty',
|
||||
'enterprise_customer_uuid': ENTERPRISE_ID,
|
||||
'country': '',
|
||||
}
|
||||
|
||||
response = self.client.post(url, provider_config_blank_country)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
provider_config = SAMLProviderConfig.objects.get(slug='test-slug-empty')
|
||||
self.assertEqual(provider_config.country, '')
|
||||
|
||||
Reference in New Issue
Block a user