@@ -37,6 +37,12 @@ def test_get_form_class(self):
3737 def test_application_registration_user (self ):
3838 self .client .login (username = "foo_user" , password = "123456" )
3939
40+ get_response = self .client .get (reverse ("oauth2_provider:register" ))
41+ self .assertEqual (get_response .status_code , 200 )
42+
43+ self .assertNotIn ("client_id" , get_response .context ["form" ].fields )
44+ self .assertNotIn ("client_secret" , get_response .context ["form" ].fields )
45+
4046 form_data = {
4147 "name" : "Foo app" ,
4248 "client_type" : Application .CLIENT_CONFIDENTIAL ,
@@ -46,6 +52,10 @@ def test_application_registration_user(self):
4652 "algorithm" : "" ,
4753 }
4854
55+ # Check that all fields in form_data are form fields
56+ for field in form_data .keys ():
57+ self .assertIn (field , get_response .context ["form" ].fields .keys ())
58+
4959 response = self .client .post (reverse ("oauth2_provider:register" ), form_data )
5060 self .assertEqual (response .status_code , 302 )
5161
@@ -96,12 +106,21 @@ def test_application_detail_owner(self):
96106
97107 response = self .client .get (reverse ("oauth2_provider:detail" , args = (self .app_foo_1 .pk ,)))
98108 self .assertEqual (response .status_code , 200 )
109+ self .assertNotIn ("client_secret" , response .context )
99110 self .assertContains (response , self .app_foo_1 .name )
100111 self .assertContains (response , self .app_foo_1 .redirect_uris )
101112 self .assertContains (response , self .app_foo_1 .post_logout_redirect_uris )
102113 self .assertContains (response , self .app_foo_1 .client_type )
103114 self .assertContains (response , self .app_foo_1 .authorization_grant_type )
104115
116+ # We don't allow users to update this, setting it False to test context
117+ self .app_foo_1 .hash_client_secret = False
118+ self .app_foo_1 .save ()
119+
120+ response = self .client .get (reverse ("oauth2_provider:detail" , args = (self .app_foo_1 .pk ,)))
121+ self .assertEqual (response .status_code , 200 )
122+ self .assertIn ("client_secret" , response .context )
123+
105124 def test_application_detail_not_owner (self ):
106125 self .client .login (username = "foo_user" , password = "123456" )
107126
@@ -111,19 +130,36 @@ def test_application_detail_not_owner(self):
111130 def test_application_update (self ):
112131 self .client .login (username = "foo_user" , password = "123456" )
113132
133+ get_response = self .client .get (reverse ("oauth2_provider:update" , args = (self .app_foo_1 .pk ,)))
134+ self .assertEqual (get_response .status_code , 200 )
135+
136+ self .assertNotIn ("client_id" , get_response .context ["form" ].fields )
137+ self .assertNotIn ("client_secret" , get_response .context )
138+ self .assertNotIn ("client_secret" , get_response .context ["form" ].fields )
139+ self .assertNotIn ("hash_client_secret" , get_response .context ["form" ].fields )
140+
141+ new_app_name = self .app_foo_1 .name + " - Updated"
142+
114143 form_data = {
144+ "name" : new_app_name ,
115145 "redirect_uris" : "http://new_example.com" ,
116146 "post_logout_redirect_uris" : "http://new_other_example.com" ,
117147 "client_type" : Application .CLIENT_PUBLIC ,
118148 "authorization_grant_type" : Application .GRANT_OPENID_HYBRID ,
119149 }
150+
151+ # Check that all fields in form_data are form fields
152+ for field in form_data .keys ():
153+ self .assertIn (field , get_response .context ["form" ].fields .keys ())
154+
120155 response = self .client .post (
121156 reverse ("oauth2_provider:update" , args = (self .app_foo_1 .pk ,)),
122157 data = form_data ,
123158 )
124159 self .assertRedirects (response , reverse ("oauth2_provider:detail" , args = (self .app_foo_1 .pk ,)))
125160
126161 self .app_foo_1 .refresh_from_db ()
162+ self .assertEqual (self .app_foo_1 .name , new_app_name )
127163 self .assertEqual (self .app_foo_1 .redirect_uris , form_data ["redirect_uris" ])
128164 self .assertEqual (self .app_foo_1 .post_logout_redirect_uris , form_data ["post_logout_redirect_uris" ])
129165 self .assertEqual (self .app_foo_1 .client_type , form_data ["client_type" ])
0 commit comments