@@ -37,6 +37,12 @@ def test_get_form_class(self):
37
37
def test_application_registration_user (self ):
38
38
self .client .login (username = "foo_user" , password = "123456" )
39
39
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
+
40
46
form_data = {
41
47
"name" : "Foo app" ,
42
48
"client_type" : Application .CLIENT_CONFIDENTIAL ,
@@ -46,6 +52,10 @@ def test_application_registration_user(self):
46
52
"algorithm" : "" ,
47
53
}
48
54
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
+
49
59
response = self .client .post (reverse ("oauth2_provider:register" ), form_data )
50
60
self .assertEqual (response .status_code , 302 )
51
61
@@ -96,12 +106,21 @@ def test_application_detail_owner(self):
96
106
97
107
response = self .client .get (reverse ("oauth2_provider:detail" , args = (self .app_foo_1 .pk ,)))
98
108
self .assertEqual (response .status_code , 200 )
109
+ self .assertNotIn ("client_secret" , response .context )
99
110
self .assertContains (response , self .app_foo_1 .name )
100
111
self .assertContains (response , self .app_foo_1 .redirect_uris )
101
112
self .assertContains (response , self .app_foo_1 .post_logout_redirect_uris )
102
113
self .assertContains (response , self .app_foo_1 .client_type )
103
114
self .assertContains (response , self .app_foo_1 .authorization_grant_type )
104
115
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
+
105
124
def test_application_detail_not_owner (self ):
106
125
self .client .login (username = "foo_user" , password = "123456" )
107
126
@@ -111,19 +130,36 @@ def test_application_detail_not_owner(self):
111
130
def test_application_update (self ):
112
131
self .client .login (username = "foo_user" , password = "123456" )
113
132
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
+
114
143
form_data = {
144
+ "name" : new_app_name ,
115
145
"redirect_uris" : "http://new_example.com" ,
116
146
"post_logout_redirect_uris" : "http://new_other_example.com" ,
117
147
"client_type" : Application .CLIENT_PUBLIC ,
118
148
"authorization_grant_type" : Application .GRANT_OPENID_HYBRID ,
119
149
}
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
+
120
155
response = self .client .post (
121
156
reverse ("oauth2_provider:update" , args = (self .app_foo_1 .pk ,)),
122
157
data = form_data ,
123
158
)
124
159
self .assertRedirects (response , reverse ("oauth2_provider:detail" , args = (self .app_foo_1 .pk ,)))
125
160
126
161
self .app_foo_1 .refresh_from_db ()
162
+ self .assertEqual (self .app_foo_1 .name , new_app_name )
127
163
self .assertEqual (self .app_foo_1 .redirect_uris , form_data ["redirect_uris" ])
128
164
self .assertEqual (self .app_foo_1 .post_logout_redirect_uris , form_data ["post_logout_redirect_uris" ])
129
165
self .assertEqual (self .app_foo_1 .client_type , form_data ["client_type" ])
0 commit comments