@@ -63,6 +63,99 @@ def test_application_registration_user(self):
6363 self .assertEqual (app .algorithm , form_data ["algorithm" ])
6464
6565
66+ @pytest .mark .usefixtures ("oauth2_settings" )
67+ @pytest .mark .oauth2_settings ({"ALLOW_REDIRECT_URI_WILDCARDS" : True })
68+ class TestApplicationRegistrationViewRedirectURIWithWildcardRedirectURIs (BaseTest ):
69+ def _test_valid (self , redirect_uri ):
70+ self .client .login (username = "foo_user" , password = "123456" )
71+
72+ form_data = {
73+ "name" : "Foo app" ,
74+ "client_id" : "client_id" ,
75+ "client_secret" : "client_secret" ,
76+ "client_type" : Application .CLIENT_CONFIDENTIAL ,
77+ "redirect_uris" : redirect_uri ,
78+ "post_logout_redirect_uris" : "http://example.com" ,
79+ "authorization_grant_type" : Application .GRANT_AUTHORIZATION_CODE ,
80+ "algorithm" : "" ,
81+ }
82+
83+ response = self .client .post (reverse ("oauth2_provider:register" ), form_data )
84+ self .assertEqual (response .status_code , 302 )
85+
86+ app = get_application_model ().objects .get (name = "Foo app" )
87+ self .assertEqual (app .user .username , "foo_user" )
88+ app = Application .objects .get ()
89+ self .assertEqual (app .name , form_data ["name" ])
90+ self .assertEqual (app .client_id , form_data ["client_id" ])
91+ self .assertEqual (app .redirect_uris , form_data ["redirect_uris" ])
92+ self .assertEqual (app .post_logout_redirect_uris , form_data ["post_logout_redirect_uris" ])
93+ self .assertEqual (app .client_type , form_data ["client_type" ])
94+ self .assertEqual (app .authorization_grant_type , form_data ["authorization_grant_type" ])
95+ self .assertEqual (app .algorithm , form_data ["algorithm" ])
96+
97+ def _test_invalid (self , uri , error_message ):
98+ self .client .login (username = "foo_user" , password = "123456" )
99+
100+ form_data = {
101+ "name" : "Foo app" ,
102+ "client_id" : "client_id" ,
103+ "client_secret" : "client_secret" ,
104+ "client_type" : Application .CLIENT_CONFIDENTIAL ,
105+ "redirect_uris" : uri ,
106+ "post_logout_redirect_uris" : "http://example.com" ,
107+ "authorization_grant_type" : Application .GRANT_AUTHORIZATION_CODE ,
108+ "algorithm" : "" ,
109+ }
110+
111+ response = self .client .post (reverse ("oauth2_provider:register" ), form_data )
112+ self .assertEqual (response .status_code , 200 )
113+ self .assertContains (response , error_message )
114+
115+ def test_application_registration_valid_3ld_wildcard (self ):
116+ self ._test_valid ("http://*.example.com" )
117+
118+ def test_application_registration_valid_3ld_partial_wildcard (self ):
119+ self ._test_valid ("http://*-partial.example.com" )
120+
121+ def test_application_registration_invalid_tld_wildcard (self ):
122+ self ._test_invalid ("http://*" , "wildcards cannot be in the top level or second level domain" )
123+
124+ def test_application_registration_invalid_tld_partial_wildcard (self ):
125+ self ._test_invalid ("http://*-partial" , "wildcards cannot be in the top level or second level domain" )
126+
127+ def test_application_registration_invalid_tld_not_startswith_wildcard_tld (self ):
128+ self ._test_invalid ("http://example.*" , "wildcards must be at the beginning of the hostname" )
129+
130+ def test_application_registration_invalid_2ld_wildcard (self ):
131+ self ._test_invalid ("http://*.com" , "wildcards cannot be in the top level or second level domain" )
132+
133+ def test_application_registration_invalid_2ld_partial_wildcard (self ):
134+ self ._test_invalid (
135+ "http://*-partial.com" , "wildcards cannot be in the top level or second level domain"
136+ )
137+
138+ def test_application_registration_invalid_2ld_not_startswith_wildcard_tld (self ):
139+ self ._test_invalid ("http://example.*.com" , "wildcards must be at the beginning of the hostname" )
140+
141+ def test_application_registration_invalid_3ld_partial_not_startswith_wildcard_2ld (self ):
142+ self ._test_invalid (
143+ "http://invalid-*.example.com" , "wildcards must be at the beginning of the hostname"
144+ )
145+
146+ def test_application_registration_invalid_4ld_not_startswith_wildcard_3ld (self ):
147+ self ._test_invalid (
148+ "http://invalid.*.invalid.example.com" ,
149+ "wildcards must be at the beginning of the hostname" ,
150+ )
151+
152+ def test_application_registration_invalid_4ld_partial_not_startswith_wildcard_2ld (self ):
153+ self ._test_invalid (
154+ "http://invalid-*.invalid.example.com" ,
155+ "wildcards must be at the beginning of the hostname" ,
156+ )
157+
158+
66159class TestApplicationViews (BaseTest ):
67160 @classmethod
68161 def _create_application (cls , name , user ):
0 commit comments