Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions enterprise_access/apps/api/serializers/customer_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class CustomerBillingCreateCheckoutSessionValidationFailedResponseSerializer(ser
required=False,
help_text='Validation results for stripe_price_id if validation failed. Absent otherwise.',
)
company_name = FieldValidationSerializer(
required=False,
help_text='Validation results for company_name if validation failed. Absent otherwise.',
)
errors = UnprocessableEntityErrorSerializer(
required=False,
many=True,
Expand Down
25 changes: 21 additions & 4 deletions enterprise_access/apps/bffs/checkout/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,32 @@ def _get_field_constraints(self) -> Dict:
min_val, max_val = product_config['quantity_range']
quantity_constraints = {'min': min_val, 'max': max_val}
break

return {
'quantity': quantity_constraints,
'enterprise_slug': {
'min_length': 3,
'max_length': 30,
'min_length': 1,
'max_length': 255,
'pattern': '^[a-z0-9-]+$'
},
'embargoed_countries': get_embargoed_countries()
'embargoed_countries': get_embargoed_countries(),
'full_name': {
'min_length': 1,
'max_length': 150,
},
'admin_email': {
'min_length': 6,
'max_length': 253,
'pattern': '^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$', # enforce the format of [email protected] without spaces
},
'country': {
'min_length': 2,
'max_length': 2,
'pattern': '^[A-Z]{2}$'
},
'company_name': {
'min_length': 1,
'max_length': 255,
}
}


Expand Down
38 changes: 38 additions & 0 deletions enterprise_access/apps/bffs/tests/test_checkout_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Tests for Checkout BFF handlers.
"""
import random
import re
from datetime import datetime
from decimal import Decimal
from unittest import mock
Expand Down Expand Up @@ -224,6 +225,43 @@ def test_get_field_constraints_includes_embargoed_countries(self):
self.assertIsInstance(constraints['embargoed_countries'], list)
self.assertEqual(constraints['embargoed_countries'], ['RU', 'IR', 'KP', 'SY', 'CU'])

@ddt.data(
{
'constraint_name': 'enterprise_slug',
'should_match': ['valid-slug', '123', '0kay-slug'],
'should_not_match': ['Capitalization-fail', 'b&d-symbol', '/-and-burn']
},
{
'constraint_name': 'admin_email',
'should_match': ['[email protected]', '[email protected]'],
'should_not_match': ['notanemail', 'too@[email protected]', 'forbidden [email protected]']
},
{
'constraint_name': 'country',
'should_match': ['US', 'CN'],
'should_not_match': ['us', 'CANADA']
},
)
@ddt.unpack
def test_get_field_constraints_regexes(self, constraint_name, should_match, should_not_match):
"""
Test that _get_field_constraints includes embargoed countries list.
"""
context = self._create_context()
handler = CheckoutContextHandler(context)

constraints = handler._get_field_constraints()

self.assertIn(constraint_name, constraints)
constraint_definition = constraints[constraint_name]
self.assertIn('pattern', constraint_definition)
pattern = constraint_definition['pattern']

for str in should_match:
self.assertTrue(re.match(pattern, str))
for str in should_not_match:
self.assertFalse(re.match(pattern, str))

@mock.patch('enterprise_access.apps.bffs.checkout.handlers.get_ssp_product_pricing')
def test_handler_adds_error_on_pricing_failure(self, mock_get_pricing):
"""
Expand Down
2 changes: 2 additions & 0 deletions requirements/common_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ elasticsearch<7.14.0
# The constraint can be removed once a release (pip-tools > 7.5.1) is available with support for pip 25.3
# Issue to track this dependency and unpin later on: https://github.com/openedx/edx-lint/issues/503
pip<25.3

pip-tools>=7.4.0