@@ -30,12 +30,14 @@ def register_css(arg)
30
30
describe OAuth2BasicAuthenticator do
31
31
context 'after_authenticate' do
32
32
let ( :user ) { Fabricate ( :user ) }
33
- let ( :authenticator ) { OAuth2BasicAuthenticator . new ( 'oauth2_basic' ) }
33
+ let ( :authenticator ) { OAuth2BasicAuthenticator . new }
34
34
35
35
let ( :auth ) do
36
- { 'credentials' => { 'token' : 'token' } ,
36
+ OmniAuth ::AuthHash . new ( { 'provider' => 'oauth2_basic' ,
37
+ 'credentials' => { 'token' : 'token' } ,
38
+ 'uid' => '123456789' ,
37
39
'info' => { id : 'id' } ,
38
- 'extra' => { } }
40
+ 'extra' => { } } )
39
41
end
40
42
41
43
before ( :each ) do
@@ -73,17 +75,19 @@ def register_css(arg)
73
75
74
76
it 'validates user email if provider has verified' do
75
77
SiteSetting . oauth2_email_verified = false
76
-
77
- # Check it's working
78
78
authenticator . stubs ( :fetch_user_details ) . returns ( email : user . email , email_verified : true )
79
79
result = authenticator . after_authenticate ( auth )
80
80
expect ( result . email_valid ) . to eq ( true )
81
-
81
+ end
82
+
83
+ it 'doesnt validate user email if provider hasnt verified' do
84
+ SiteSetting . oauth2_email_verified = false
82
85
authenticator . stubs ( :fetch_user_details ) . returns ( email : user . email , email_verified : nil )
83
86
result = authenticator . after_authenticate ( auth )
84
87
expect ( result . email_valid ) . to eq ( false )
85
-
86
- # Check it doesn't interfere with the site setting
88
+ end
89
+
90
+ it 'doesnt affect the site setting' do
87
91
SiteSetting . oauth2_email_verified = true
88
92
authenticator . stubs ( :fetch_user_details ) . returns ( email : user . email , email_verified : false )
89
93
result = authenticator . after_authenticate ( auth )
@@ -135,7 +139,11 @@ def register_css(arg)
135
139
end
136
140
137
141
context 'avatar downloading' do
138
- before { SiteSetting . queue_jobs = true }
142
+ before do
143
+ SiteSetting . queue_jobs = true
144
+ SiteSetting . oauth2_fetch_user_details = true
145
+ SiteSetting . oauth2_email_verified = true
146
+ end
139
147
140
148
let ( :job_klass ) { Jobs ::DownloadAvatarFromUrl }
141
149
@@ -186,7 +194,7 @@ def register_css(arg)
186
194
end
187
195
188
196
it 'can walk json' do
189
- authenticator = OAuth2BasicAuthenticator . new ( 'oauth2_basic' )
197
+ authenticator = OAuth2BasicAuthenticator . new
190
198
json_string = '{"user":{"id":1234,"email":{"address":"[email protected] "}}}'
191
199
SiteSetting . oauth2_json_email_path = 'user.email.address'
192
200
result = authenticator . json_walk ( { } , JSON . parse ( json_string ) , :email )
@@ -195,7 +203,7 @@ def register_css(arg)
195
203
end
196
204
197
205
it 'can walk json that contains an array' do
198
- authenticator = OAuth2BasicAuthenticator . new ( 'oauth2_basic' )
206
+ authenticator = OAuth2BasicAuthenticator . new
199
207
json_string = '{"email":"[email protected] ","identities":[{"user_id":"123456789","provider":"auth0","isSocial":false}]}'
200
208
SiteSetting . oauth2_json_user_id_path = 'identities.[].user_id'
201
209
result = authenticator . json_walk ( { } , JSON . parse ( json_string ) , :user_id )
@@ -204,7 +212,7 @@ def register_css(arg)
204
212
end
205
213
206
214
it 'can walk json and handle an empty array' do
207
- authenticator = OAuth2BasicAuthenticator . new ( 'oauth2_basic' )
215
+ authenticator = OAuth2BasicAuthenticator . new
208
216
json_string = '{"email":"[email protected] ","identities":[]}'
209
217
SiteSetting . oauth2_json_user_id_path = 'identities.[].user_id'
210
218
result = authenticator . json_walk ( { } , JSON . parse ( json_string ) , :user_id )
@@ -213,7 +221,7 @@ def register_css(arg)
213
221
end
214
222
215
223
it 'can walk json and download avatar' do
216
- authenticator = OAuth2BasicAuthenticator . new ( 'oauth2_basic' )
224
+ authenticator = OAuth2BasicAuthenticator . new
217
225
json_string = '{"user":{"avatar":"http://example.com/1.png"}}'
218
226
SiteSetting . oauth2_json_avatar_path = 'user.avatar'
219
227
result = authenticator . json_walk ( { } , JSON . parse ( json_string ) , :avatar )
@@ -224,10 +232,11 @@ def register_css(arg)
224
232
context 'token_callback' do
225
233
let ( :user ) { Fabricate ( :user ) }
226
234
let ( :strategy ) { OmniAuth ::Strategies ::Oauth2Basic . new ( { } ) }
227
- let ( :authenticator ) { OAuth2BasicAuthenticator . new ( 'oauth2_basic' ) }
235
+ let ( :authenticator ) { OAuth2BasicAuthenticator . new }
228
236
229
237
let ( :auth ) do
230
- {
238
+ OmniAuth ::AuthHash . new ( {
239
+ 'provider' => 'oauth2_basic' ,
231
240
'credentials' => {
232
241
'token' => 'token'
233
242
} ,
@@ -237,7 +246,7 @@ def register_css(arg)
237
246
238
247
} ,
239
248
'extra' => { }
240
- }
249
+ } )
241
250
end
242
251
243
252
let ( :access_token ) do
@@ -273,7 +282,7 @@ def register_css(arg)
273
282
authenticator . stubs ( :fetch_user_details ) . returns ( email :
'[email protected] ' )
274
283
result = authenticator . after_authenticate ( auth )
275
284
276
- expect ( result . extra_data [ :oauth2_basic_user_id ] ) . to eq 'e028b1b918853eca7fba208a9d7e9d29a6e93c57'
285
+ expect ( result . extra_data [ :uid ] ) . to eq 'e028b1b918853eca7fba208a9d7e9d29a6e93c57'
277
286
expect ( result . name ) . to eq 'Sammy the Shark'
278
287
expect ( result . email ) . to eq '[email protected] '
279
288
end
@@ -282,7 +291,7 @@ def register_css(arg)
282
291
SiteSetting . oauth2_fetch_user_details = false
283
292
result = authenticator . after_authenticate ( auth )
284
293
285
- expect ( result . extra_data [ :oauth2_basic_user_id ] ) . to eq 'e028b1b918853eca7fba208a9d7e9d29a6e93c57'
294
+ expect ( result . extra_data [ :uid ] ) . to eq 'e028b1b918853eca7fba208a9d7e9d29a6e93c57'
286
295
expect ( result . name ) . to eq 'Sammy the Shark'
287
296
expect ( result . email ) . to eq '[email protected] '
288
297
end
0 commit comments