@@ -85,12 +85,10 @@ def good_submit(mocker):
85
85
86
86
87
87
@pytest .fixture
88
- def good_submit_with_login (mocker ):
88
+ def good_submit_with_auth (mocker ):
89
89
client = mocker .MagicMock ()
90
90
r = ClientSessionMocker ([
91
- dumps ({'message' : "Login Successful" ,
92
- 'access_token' : "jwt:foo" ,
93
- 'refresh_token' : "jwt:bar" }),
91
+ dumps ({'access_token' : "jwt:access" }),
94
92
dumps ({'request_id' : "111-222-333-444" })], [200 , 200 ])
95
93
client .post = mocker .MagicMock (return_value = r )
96
94
return client
@@ -154,10 +152,9 @@ def servicex_status_unknown(mocker):
154
152
155
153
156
154
@pytest .mark .asyncio
157
- async def test_status_no_login (servicex_status_request ):
158
-
155
+ async def test_status_no_auth (servicex_status_request ):
159
156
servicex_status_request (None , 0 , 10 )
160
- sa = ServiceXAdaptor ('http://localhost:500 /sx' )
157
+ sa = ServiceXAdaptor (endpoint = 'http://localhost:5000 /sx' )
161
158
async with aiohttp .ClientSession () as client :
162
159
r = await sa .get_transform_status (client , '123-123-123-444' )
163
160
assert len (r ) == 3
@@ -178,35 +175,32 @@ async def test_status_fatal_status(servicex_status_fatal):
178
175
179
176
180
177
@pytest .mark .asyncio
181
- async def test_status_with_login (mocker ):
178
+ async def test_status_with_auth (mocker ):
182
179
client = mocker .MagicMock ()
183
180
client .post = mocker .Mock (return_value = ClientSessionMocker ([
184
- dumps ({'message' : "Login Successful" ,
185
- 'access_token' : "jwt:foo" ,
186
- 'refresh_token' : "jwt:bar" })], [200 ]))
181
+ dumps ({'access_token' : "jwt:access" })], [200 ]))
187
182
188
183
client .get = mocker .Mock (return_value = ClientSessionMocker ([
189
184
dumps ({'files-remaining' : 1 ,
190
185
'files-skipped' : 0 ,
191
186
'files-processed' : 0 })], [200 ]))
192
187
193
188
sa = ServiceXAdaptor (endpoint = 'http://localhost:5000/sx' ,
194
- email = "test@example.com" ,
195
- password = "foobar" )
189
+ refresh_token = 'jwt:refresh' )
196
190
197
191
await sa .get_transform_status (client , '123-123-123-444' )
198
- client .post .assert_called_with ("http://localhost:5000/sx/login" ,
199
- json = { 'password' : 'foobar' , 'email' : 'test@example.com' })
200
-
192
+ client .post .assert_called_with (
193
+ "http://localhost:5000/sx/token/refresh" , json = None ,
194
+ headers = { 'Authorization' : 'Bearer jwt:refresh' })
201
195
client .get .assert_called_with (
202
196
"http://localhost:5000/sx/servicex/transformation/123-123-123-444/status" ,
203
- headers = {'Authorization' : 'Bearer jwt:foo ' })
197
+ headers = {'Authorization' : 'Bearer jwt:access ' })
204
198
205
199
206
200
@pytest .mark .asyncio
207
201
async def test_status_unknown_request (servicex_status_unknown ):
208
202
209
- sa = ServiceXAdaptor ('http://localhost:500 /sx' )
203
+ sa = ServiceXAdaptor ('http://localhost:5000 /sx' )
210
204
with pytest .raises (ServiceXUnknownRequestID ) as e :
211
205
async with aiohttp .ClientSession () as client :
212
206
await sa .get_transform_status (client , '123-123-123-444' )
@@ -281,7 +275,7 @@ async def test_watch_fail_start(short_status_poll_time, mocker):
281
275
282
276
283
277
@pytest .mark .asyncio
284
- async def test_submit_good_no_login (good_submit ):
278
+ async def test_submit_good_no_auth (good_submit ):
285
279
sa = ServiceXAdaptor (endpoint = 'http://localhost:5000/sx' )
286
280
287
281
rid = await sa .submit_query (good_submit , {'hi' : 'there' })
@@ -306,17 +300,14 @@ async def test_submit_good_no_login(good_submit):
306
300
307
301
308
302
@pytest .mark .asyncio
309
- async def test_submit_good_with_login (mocker ):
303
+ async def test_submit_good_with_auth (mocker ):
310
304
client = mocker .MagicMock ()
311
305
client .post = mocker .Mock (return_value = ClientSessionMocker ([
312
- dumps ({'message' : "Login Successful" ,
313
- 'access_token' : "jwt:foo" ,
314
- 'refresh_token' : "jwt:bar" }),
306
+ dumps ({'access_token' : "jwt:access" }),
315
307
dumps ({'request_id' : "111-222-333-444" })], [200 , 200 ]))
316
308
317
309
sa = ServiceXAdaptor (endpoint = 'http://localhost:5000/sx' ,
318
- email = "test@example.com" ,
319
- password = "foobar" )
310
+ refresh_token = 'jwt:refresh' )
320
311
321
312
await sa .submit_query (client , {'hi' : 'there' })
322
313
r = client .post .mock_calls
@@ -325,29 +316,25 @@ async def test_submit_good_with_login(mocker):
325
316
326
317
# Verify the login POST
327
318
_ , args , kwargs = r [0 ]
328
- assert args [0 ] == 'http://localhost:5000/sx/login'
329
- assert kwargs ['json' ]['email' ] == 'test@example.com'
330
- assert kwargs ['json' ]['password' ] == 'foobar'
319
+ assert args [0 ] == 'http://localhost:5000/sx/token/refresh'
320
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:refresh'
331
321
332
322
# Verify the Submit POST
333
323
_ , args , kwargs = r [1 ]
334
324
assert args [0 ] == 'http://localhost:5000/sx/servicex/transformation'
335
- assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:foo '
325
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:access '
336
326
337
327
338
328
@pytest .mark .asyncio
339
- async def test_submit_good_with_login_existing_token (mocker ):
329
+ async def test_submit_good_with_auth_existing_token (mocker ):
340
330
client = mocker .MagicMock ()
341
331
client .post = mocker .Mock (return_value = ClientSessionMocker ([
342
- dumps ({'message' : "Login Successful" ,
343
- 'access_token' : "jwt:foo" ,
344
- 'refresh_token' : "jwt:bar" }),
332
+ dumps ({'access_token' : "jwt:access" }),
345
333
dumps ({'request_id' : "111-222-333-444" }),
346
334
dumps ({'request_id' : "222-333-444-555" })], [200 , 200 , 200 ]))
347
335
348
336
sa = ServiceXAdaptor (endpoint = 'http://localhost:5000/sx' ,
349
- email = "test@example.com" ,
350
- password = "foobar" )
337
+ refresh_token = 'jwt:refresh' )
351
338
352
339
mocker .patch ('google.auth.jwt.decode' , return_value = {'exp' : float ('inf' )}) # Never expires
353
340
rid1 = await sa .submit_query (client , {'hi' : 'there' })
@@ -360,39 +347,33 @@ async def test_submit_good_with_login_existing_token(mocker):
360
347
361
348
assert len (r ) == 3
362
349
363
- # Verify the login POST
350
+ # Verify the access token POST
364
351
_ , args , kwargs = r [0 ]
365
- assert args [0 ] == 'http://localhost:5000/sx/login'
366
- assert kwargs ['json' ]['email' ] == 'test@example.com'
367
- assert kwargs ['json' ]['password' ] == 'foobar'
352
+ assert args [0 ] == 'http://localhost:5000/sx/token/refresh'
353
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:refresh'
368
354
369
355
# Verify the Submit POST
370
356
_ , args , kwargs = r [1 ]
371
357
assert args [0 ] == 'http://localhost:5000/sx/servicex/transformation'
372
- assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:foo '
358
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:access '
373
359
374
360
# Verify the second Submit POST
375
361
_ , args , kwargs = r [2 ]
376
362
assert args [0 ] == 'http://localhost:5000/sx/servicex/transformation'
377
- assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:foo '
363
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:access '
378
364
379
365
380
366
@pytest .mark .asyncio
381
- async def test_submit_good_with_login_expired_token (mocker ):
367
+ async def test_submit_good_with_auth_expired_token (mocker ):
382
368
client = mocker .MagicMock ()
383
369
client .post = mocker .Mock (return_value = ClientSessionMocker ([
384
- dumps ({'message' : "Login Successful" ,
385
- 'access_token' : "jwt:foo" ,
386
- 'refresh_token' : "jwt:bar" }),
370
+ dumps ({'access_token' : "jwt:access" }),
387
371
dumps ({'request_id' : "111-222-333-444" }),
388
- dumps ({'message' : "Login Successful" ,
389
- 'access_token' : "jwt:foo2" ,
390
- 'refresh_token' : "jwt:bar2" }),
372
+ dumps ({'access_token' : "jwt:access2" }),
391
373
dumps ({'request_id' : "222-333-444-555" })], [200 , 200 , 200 , 200 ]))
392
374
393
375
sa = ServiceXAdaptor (endpoint = 'http://localhost:5000/sx' ,
394
- email = "test@example.com" ,
395
- password = "foobar" )
376
+ refresh_token = 'jwt:refresh' )
396
377
397
378
mocker .patch ('google.auth.jwt.decode' , return_value = {'exp' : 0 }) # Always expired
398
379
@@ -408,25 +389,23 @@ async def test_submit_good_with_login_expired_token(mocker):
408
389
409
390
# Verify the login POST
410
391
_ , args , kwargs = r [0 ]
411
- assert args [0 ] == 'http://localhost:5000/sx/login'
412
- assert kwargs ['json' ]['email' ] == 'test@example.com'
413
- assert kwargs ['json' ]['password' ] == 'foobar'
392
+ assert args [0 ] == 'http://localhost:5000/sx/token/refresh'
393
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:refresh'
414
394
415
395
# Verify the Submit POST
416
396
_ , args , kwargs = r [1 ]
417
397
assert args [0 ] == 'http://localhost:5000/sx/servicex/transformation'
418
- assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:foo '
398
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:access '
419
399
420
400
# Verify the second login POST
421
401
_ , args , kwargs = r [2 ]
422
- assert args [0 ] == 'http://localhost:5000/sx/login'
423
- assert kwargs ['json' ]['email' ] == 'test@example.com'
424
- assert kwargs ['json' ]['password' ] == 'foobar'
402
+ assert args [0 ] == 'http://localhost:5000/sx/token/refresh'
403
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:refresh'
425
404
426
405
# Verify the second Submit POST
427
406
_ , args , kwargs = r [3 ]
428
407
assert args [0 ] == 'http://localhost:5000/sx/servicex/transformation'
429
- assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:foo2 '
408
+ assert kwargs ['headers' ]['Authorization' ] == 'Bearer jwt:access2 '
430
409
431
410
432
411
@pytest .mark .asyncio
@@ -450,19 +429,18 @@ async def test_submit_bad_html(bad_submit_html):
450
429
451
430
452
431
@pytest .mark .asyncio
453
- async def test_submit_good_with_bad_login (mocker ):
432
+ async def test_submit_good_with_bad_token (mocker ):
454
433
client = mocker .MagicMock ()
455
434
client .post = mocker .Mock (return_value = ClientSessionMocker (
456
435
dumps ({'message' : 'Wrong credentials' }), 401 ))
457
436
458
437
sa = ServiceXAdaptor (endpoint = 'http://localhost:5000/sx' ,
459
- email = "test@example.com" ,
460
- password = "XXXXX" )
438
+ refresh_token = "XXXXX" )
461
439
462
440
with pytest .raises (ServiceXException ) as e :
463
441
await sa .submit_query (client , {'hi' : 'there' })
464
442
465
- assert "ServiceX login request rejected" in str (e .value )
443
+ assert "ServiceX access token request rejected" in str (e .value )
466
444
467
445
468
446
@pytest .mark .asyncio
@@ -505,15 +483,12 @@ def test_servicex_adaptor_settings():
505
483
{
506
484
'type' : 'my-type' ,
507
485
'endpoint' : 'http://my-left-foot.com:5000' ,
508
- 'email' : 'thegoodplace@example.com' ,
509
- 'password' : 'forkingshirtballs' ,
486
+ 'token' : 'forkingshirtballs.thegoodplace.bortles'
510
487
}
511
488
]
512
-
513
489
sx = servicex_adaptor_factory (c , 'my-type' )
514
490
assert sx ._endpoint == 'http://my-left-foot.com:5000'
515
- assert sx ._email == 'thegoodplace@example.com'
516
- assert sx ._password == 'forkingshirtballs'
491
+ assert sx ._refresh_token == 'forkingshirtballs.thegoodplace.bortles'
517
492
518
493
519
494
def test_servicex_adaptor_settings_wrong_type ():
@@ -524,8 +499,7 @@ def test_servicex_adaptor_settings_wrong_type():
524
499
{
525
500
'type' : 'my-type' ,
526
501
'endpoint' : 'http://my-left-foot.com:5000' ,
527
- 'email' : 'thegoodplace@example.com' ,
528
- 'password' : 'forkingshirtballs' ,
502
+ 'token' : 'forkingshirtballs.thegoodplace.bortles'
529
503
}
530
504
]
531
505
@@ -544,21 +518,18 @@ def test_servicex_adaptor_settings_env():
544
518
{
545
519
'type' : '${SXTYPE}' ,
546
520
'endpoint' : '${ENDPOINT}:5000' ,
547
- 'email' : '${SXUSER}' ,
548
- 'password' : '${SXPASS}' ,
521
+ 'token' : '${SXTOKEN}' ,
549
522
}
550
523
]
551
524
552
525
from os import environ
553
526
environ ['ENDPOINT' ] = 'http://tachi.com'
554
- environ ['SXUSER' ] = 'Holden'
555
- environ ['SXPASS' ] = 'protomolecule'
527
+ environ ['SXTOKEN' ] = 'protomolecule'
556
528
environ ['SXTYPE' ] = 'mcrn'
557
529
558
530
sx = servicex_adaptor_factory (c , 'mcrn' )
559
531
assert sx ._endpoint == 'http://tachi.com:5000'
560
- assert sx ._email == 'Holden'
561
- assert sx ._password == 'protomolecule'
532
+ assert sx ._refresh_token == 'protomolecule'
562
533
563
534
564
535
@pytest .mark .asyncio
0 commit comments