@@ -465,12 +465,32 @@ def test_name_denied_name(self):
465465 response = self .send (data = data )
466466 assert response .status_code == 400
467467 assert json .loads (response .content ) == {'name' : ['This name cannot be used.' ]}
468+
469+ # homoglyphs don't bypass the validation
470+ data .update (name = {'en-US' : 'fѻѺ thing' })
471+ response = self .send (data = data )
472+ assert response .status_code == 400
473+ assert json .loads (response .content ) == {'name' : ['This name cannot be used.' ]}
474+
468475 # But you can if you have the correct permission
469476 self .grant_permission (self .user , 'Collections:Edit' )
470477 self .client .login_api (self .user )
471478 response = self .send (data = data )
472479 assert response .status_code in (200 , 201 )
473480
481+ def test_name_too_many_homoglyphs (self ):
482+ self .client .login_api (self .user )
483+ data = dict (self .data )
484+ data .update (name = {'en-US' : 'l' * 17 })
485+ response = self .send (data = data )
486+ assert response .status_code == 400
487+ assert json .loads (response .content ) == {'name' : ['This name cannot be used.' ]}
488+ # even with permission
489+ self .grant_permission (self .user , 'Collections:Edit' )
490+ self .client .login_api (self .user )
491+ response = self .send (data = data )
492+ assert response .status_code == 400
493+
474494 def test_slug_denied_name (self ):
475495 DeniedName .objects .create (name = 'foo' )
476496 self .client .login_api (self .user )
@@ -481,12 +501,36 @@ def test_slug_denied_name(self):
481501 assert json .loads (response .content ) == {
482502 'slug' : ['This custom URL cannot be used.' ]
483503 }
504+
505+ # homoglyphs don't bypass the validation
506+ data .update (slug = 'fѻѺ_thing' )
507+ response = self .send (data = data )
508+ assert response .status_code == 400
509+ assert json .loads (response .content ) == {
510+ 'slug' : ['This custom URL cannot be used.' ]
511+ }
512+
484513 # But you can if you have the correct permission
485514 self .grant_permission (self .user , 'Collections:Edit' )
486515 self .client .login_api (self .user )
487516 response = self .send (data = data )
488517 assert response .status_code in (200 , 201 )
489518
519+ def test_slug_too_many_homoglyphs (self ):
520+ self .client .login_api (self .user )
521+ data = dict (self .data )
522+ data .update (slug = 'l' * 17 )
523+ response = self .send (data = data )
524+ assert response .status_code == 400
525+ assert json .loads (response .content ) == {
526+ 'slug' : ['This custom URL cannot be used.' ]
527+ }
528+ # even with permission
529+ self .grant_permission (self .user , 'Collections:Edit' )
530+ self .client .login_api (self .user )
531+ response = self .send (data = data )
532+ assert response .status_code == 400
533+
490534
491535class TestCollectionViewSetCreate (CollectionViewSetDataMixin , TestCase ):
492536 def send (self , url = None , data = None ):
0 commit comments