3
3
from urllib .parse import parse_qs
4
4
from urllib .parse import urlsplit
5
5
6
+ import pytest
6
7
import time_machine
7
8
from authlib .jose import jwt
9
+ from authlib .oauth2 .rfc6749 .errors import InvalidRequestError
8
10
from authlib .oauth2 .rfc7636 import create_s256_code_challenge
9
11
from flask import g
10
12
from werkzeug .security import gen_salt
@@ -27,6 +29,7 @@ def test_nominal_case(
27
29
client_id = client .client_id ,
28
30
scope = "openid profile email groups address phone" ,
29
31
nonce = "somenonce" ,
32
+ redirect_uri = "https://client.test/redirect1" ,
30
33
),
31
34
status = 200 ,
32
35
)
@@ -119,6 +122,7 @@ def test_invalid_client(testclient, logged_user, keypair):
119
122
client_id = "invalid" ,
120
123
scope = "openid profile email groups address phone" ,
121
124
nonce = "somenonce" ,
125
+ redirect_uri = "https://client.test/redirect1" ,
122
126
),
123
127
status = 400 ,
124
128
)
@@ -186,6 +190,7 @@ def test_preconsented_client(
186
190
client_id = client .client_id ,
187
191
scope = "openid profile" ,
188
192
nonce = "somenonce" ,
193
+ redirect_uri = "https://client.test/redirect1" ,
189
194
),
190
195
status = 302 ,
191
196
)
@@ -240,6 +245,7 @@ def test_logout_login(testclient, logged_user, client, backend):
240
245
client_id = client .client_id ,
241
246
scope = "openid profile" ,
242
247
nonce = "somenonce" ,
248
+ redirect_uri = "https://client.test/redirect1" ,
243
249
),
244
250
status = 200 ,
245
251
)
@@ -311,6 +317,7 @@ def test_deny(testclient, logged_user, client, backend):
311
317
client_id = client .client_id ,
312
318
scope = "openid profile" ,
313
319
nonce = "somenonce" ,
320
+ redirect_uri = "https://client.test/redirect1" ,
314
321
),
315
322
status = 200 ,
316
323
)
@@ -342,6 +349,7 @@ def test_code_challenge(testclient, logged_user, client, backend):
342
349
client_id = client .client_id ,
343
350
scope = "openid profile" ,
344
351
nonce = "somenonce" ,
352
+ redirect_uri = "https://client.test/redirect1" ,
345
353
),
346
354
status = 200 ,
347
355
)
@@ -399,6 +407,7 @@ def test_consent_already_given(testclient, logged_user, client, backend):
399
407
client_id = client .client_id ,
400
408
scope = "openid profile" ,
401
409
nonce = "somenonce" ,
410
+ redirect_uri = "https://client.test/redirect1" ,
402
411
),
403
412
status = 200 ,
404
413
)
@@ -434,6 +443,7 @@ def test_consent_already_given(testclient, logged_user, client, backend):
434
443
client_id = client .client_id ,
435
444
scope = "openid profile" ,
436
445
nonce = "somenonce" ,
446
+ redirect_uri = "https://client.test/redirect1" ,
437
447
),
438
448
status = 302 ,
439
449
)
@@ -455,6 +465,7 @@ def test_consent_with_openid_scope_only(testclient, logged_user, client, backend
455
465
client_id = client .client_id ,
456
466
scope = "openid" ,
457
467
nonce = "somenonce" ,
468
+ redirect_uri = "https://client.test/redirect1" ,
458
469
),
459
470
status = 200 ,
460
471
)
@@ -474,6 +485,7 @@ def test_consent_with_no_scope(testclient, logged_user, client, backend):
474
485
response_type = "code" ,
475
486
client_id = client .client_id ,
476
487
nonce = "somenonce" ,
488
+ redirect_uri = "https://client.test/redirect1" ,
477
489
),
478
490
status = 200 ,
479
491
)
@@ -483,6 +495,22 @@ def test_consent_with_no_scope(testclient, logged_user, client, backend):
483
495
res .mustcontain (no = "Accept" )
484
496
485
497
498
+ def test_consent_with_no_redirect_uri (testclient , logged_user , client , backend ):
499
+ with pytest .raises (
500
+ InvalidRequestError ,
501
+ match = r'Missing "redirect_uri" in request.' ,
502
+ ):
503
+ testclient .get (
504
+ "/oauth/authorize" ,
505
+ params = dict (
506
+ response_type = "code" ,
507
+ client_id = client .client_id ,
508
+ nonce = "somenonce" ,
509
+ ),
510
+ status = 200 ,
511
+ )
512
+
513
+
486
514
def test_when_consent_already_given_but_for_a_smaller_scope (
487
515
testclient , logged_user , client , backend
488
516
):
@@ -495,6 +523,7 @@ def test_when_consent_already_given_but_for_a_smaller_scope(
495
523
client_id = client .client_id ,
496
524
scope = "openid profile" ,
497
525
nonce = "somenonce" ,
526
+ redirect_uri = "https://client.test/redirect1" ,
498
527
),
499
528
status = 200 ,
500
529
)
@@ -531,6 +560,7 @@ def test_when_consent_already_given_but_for_a_smaller_scope(
531
560
client_id = client .client_id ,
532
561
scope = "openid profile groups" ,
533
562
nonce = "somenonce" ,
563
+ redirect_uri = "https://client.test/redirect1" ,
534
564
),
535
565
status = 200 ,
536
566
)
@@ -564,6 +594,7 @@ def test_user_cannot_use_oidc(
564
594
client_id = client .client_id ,
565
595
scope = "openid profile" ,
566
596
nonce = "somenonce" ,
597
+ redirect_uri = "https://client.test/redirect1" ,
567
598
),
568
599
)
569
600
res = res .follow ()
@@ -584,6 +615,7 @@ def test_nonce_required_in_oidc_requests(testclient, logged_user, client):
584
615
response_type = "code" ,
585
616
client_id = client .client_id ,
586
617
scope = "openid profile" ,
618
+ redirect_uri = "https://client.test/redirect1" ,
587
619
),
588
620
status = 200 ,
589
621
)
@@ -601,6 +633,7 @@ def test_nonce_not_required_in_oauth_requests(testclient, logged_user, client, b
601
633
response_type = "code" ,
602
634
client_id = client .client_id ,
603
635
scope = "profile" ,
636
+ redirect_uri = "https://client.test/redirect1" ,
604
637
),
605
638
status = 200 ,
606
639
)
@@ -624,6 +657,7 @@ def test_request_scope_too_large(testclient, logged_user, keypair, client, backe
624
657
client_id = client .client_id ,
625
658
scope = "openid profile email" ,
626
659
nonce = "somenonce" ,
660
+ redirect_uri = "https://client.test/redirect1" ,
627
661
),
628
662
status = 200 ,
629
663
)
@@ -690,6 +724,7 @@ def test_code_expired(testclient, user, client):
690
724
client_id = client .client_id ,
691
725
scope = "openid profile email groups address phone" ,
692
726
nonce = "somenonce" ,
727
+ redirect_uri = "https://client.test/redirect1" ,
693
728
),
694
729
)
695
730
res = res .follow ()
@@ -738,6 +773,7 @@ def test_code_with_invalid_user(testclient, admin, client, backend):
738
773
client_id = client .client_id ,
739
774
scope = "openid profile email groups address phone" ,
740
775
nonce = "somenonce" ,
776
+ redirect_uri = "https://client.test/redirect1" ,
741
777
),
742
778
).follow ()
743
779
@@ -782,6 +818,7 @@ def test_locked_account(
782
818
client_id = client .client_id ,
783
819
scope = "openid profile email groups address phone" ,
784
820
nonce = "somenonce" ,
821
+ redirect_uri = "https://client.test/redirect1" ,
785
822
),
786
823
status = 200 ,
787
824
)
@@ -822,6 +859,7 @@ def test_missing_client_id(
822
859
response_type = "code" ,
823
860
scope = "openid profile email groups address phone" ,
824
861
nonce = "somenonce" ,
862
+ redirect_uri = "https://client.test/redirect1" ,
825
863
),
826
864
status = 400 ,
827
865
)
@@ -844,6 +882,7 @@ def test_logout_login_with_intruder_lockout(testclient, logged_user, client, bac
844
882
client_id = client .client_id ,
845
883
scope = "openid profile" ,
846
884
nonce = "somenonce" ,
885
+ redirect_uri = "https://client.test/redirect1" ,
847
886
),
848
887
status = 200 ,
849
888
)
@@ -892,6 +931,7 @@ def test_rfc9207(
892
931
client_id = client .client_id ,
893
932
scope = "openid profile email groups address phone" ,
894
933
nonce = "somenonce" ,
934
+ redirect_uri = "https://client.test/redirect1" ,
895
935
),
896
936
status = 200 ,
897
937
)
0 commit comments