24
24
import org .opensearch .security .user .AuthCredentials ;
25
25
import org .opensearch .security .util .FakeRestRequest ;
26
26
27
+ import com .nimbusds .common .contenttype .ContentType ;
28
+
27
29
import static org .hamcrest .MatcherAssert .assertThat ;
28
30
import static org .hamcrest .Matchers .is ;
29
- import static com .amazon .dlic .auth .http .jwt .keybyoidc .OpenIdConstants .APPLICATION_JWT ;
30
31
import static com .amazon .dlic .auth .http .jwt .keybyoidc .OpenIdConstants .CLIENT_ID ;
31
32
import static com .amazon .dlic .auth .http .jwt .keybyoidc .OpenIdConstants .ISSUER_ID_URL ;
32
33
import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .MCCOY_SUBJECT ;
33
34
import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .OIDC_TEST_AUD ;
34
35
import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .OIDC_TEST_ISS ;
35
36
import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .ROLES_CLAIM ;
37
+ import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .STEPHEN_SUBJECT ;
36
38
import static org .junit .Assert .assertTrue ;
37
39
import static org .mockito .Mockito .spy ;
38
40
@@ -435,7 +437,12 @@ public void userinfoEndpointReturnsJwtWithAllRequirementsTest() throws Exception
435
437
436
438
AuthCredentials creds = openIdAuthenticator .extractCredentials (
437
439
new FakeRestRequest (
438
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
440
+ ImmutableMap .of (
441
+ "Authorization" ,
442
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 ,
443
+ "Content-Type" ,
444
+ ContentType .APPLICATION_JWT .toString ()
445
+ ),
439
446
new HashMap <>()
440
447
).asSecurityRequest (),
441
448
null
@@ -448,8 +455,8 @@ public void userinfoEndpointReturnsJwtWithAllRequirementsTest() throws Exception
448
455
449
456
@ Test
450
457
public void userinfoEndpointReturnsJwtWithRequiredAudIssFailsTest () throws Exception { // Setting a required issuer or audience
451
- // alongside userinfo endpoint settings causes
452
- // failures in signed response cases
458
+ // alongside userinfo endpoint settings causes
459
+ // failures in signed response cases
453
460
Settings settings = Settings .builder ()
454
461
.put ("openid_connect_url" , mockIdpServer .getDiscoverUri ())
455
462
.put ("userinfo_endpoint" , mockIdpServer .getUserinfoSignedUri ())
@@ -466,7 +473,12 @@ public void userinfoEndpointReturnsJwtWithRequiredAudIssFailsTest() throws Excep
466
473
try {
467
474
creds = openIdAuthenticator .extractCredentials (
468
475
new FakeRestRequest (
469
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
476
+ ImmutableMap .of (
477
+ "Authorization" ,
478
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 ,
479
+ "Content-Type" ,
480
+ ContentType .APPLICATION_JWT .toString ()
481
+ ),
470
482
new HashMap <>()
471
483
).asSecurityRequest (),
472
484
null
@@ -493,7 +505,12 @@ public void userinfoEndpointReturnsJwtWithMatchingRequiredAudIssPassesTest() thr
493
505
494
506
AuthCredentials creds = openIdAuthenticator .extractCredentials (
495
507
new FakeRestRequest (
496
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1_OIDC , "Content-Type" , APPLICATION_JWT ),
508
+ ImmutableMap .of (
509
+ "Authorization" ,
510
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1_OIDC ,
511
+ "Content-Type" ,
512
+ ContentType .APPLICATION_JWT .toString ()
513
+ ),
497
514
new HashMap <>()
498
515
).asSecurityRequest (),
499
516
null
@@ -520,7 +537,12 @@ public void userinfoEndpointReturnsJwtMissingIssuerTest() throws Exception {
520
537
try {
521
538
creds = openIdAuthenticator .extractCredentials (
522
539
new FakeRestRequest (
523
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
540
+ ImmutableMap .of (
541
+ "Authorization" ,
542
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 ,
543
+ "Content-Type" ,
544
+ ContentType .APPLICATION_JWT .toString ()
545
+ ),
524
546
new HashMap <>()
525
547
).asSecurityRequest (),
526
548
null
@@ -548,7 +570,12 @@ public void userinfoEndpointReturnsJwtMissingAudienceTest() throws Exception {
548
570
try {
549
571
creds = openIdAuthenticator .extractCredentials (
550
572
new FakeRestRequest (
551
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
573
+ ImmutableMap .of (
574
+ "Authorization" ,
575
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 ,
576
+ "Content-Type" ,
577
+ ContentType .APPLICATION_JWT .toString ()
578
+ ),
552
579
new HashMap <>()
553
580
).asSecurityRequest (),
554
581
null
@@ -575,7 +602,12 @@ public void userinfoEndpointReturnsJwtMismatchedSubTest() throws Exception {
575
602
try {
576
603
creds = openIdAuthenticator .extractCredentials (
577
604
new FakeRestRequest (
578
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .STEPHEN_RSA_1 , "Content-Type" , APPLICATION_JWT ),
605
+ ImmutableMap .of (
606
+ "Authorization" ,
607
+ "Bearer " + TestJwts .STEPHEN_RSA_1 ,
608
+ "Content-Type" ,
609
+ ContentType .APPLICATION_JWT .toString ()
610
+ ),
579
611
new HashMap <>()
580
612
).asSecurityRequest (),
581
613
null
@@ -600,7 +632,12 @@ public void userinfoEndpointReturnsJsonWithAllRequirementsTest() throws Exceptio
600
632
601
633
AuthCredentials creds = openIdAuthenticator .extractCredentials (
602
634
new FakeRestRequest (
603
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
635
+ ImmutableMap .of (
636
+ "Authorization" ,
637
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 ,
638
+ "Content-Type" ,
639
+ ContentType .APPLICATION_JWT .toString ()
640
+ ),
604
641
new HashMap <>()
605
642
).asSecurityRequest (),
606
643
null
@@ -626,7 +663,12 @@ public void userinfoEndpointReturnsJsonMismatchedSubTest() throws Exception {
626
663
try {
627
664
creds = openIdAuthenticator .extractCredentials (
628
665
new FakeRestRequest (
629
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .STEPHEN_RSA_1 , "Content-Type" , APPLICATION_JWT ),
666
+ ImmutableMap .of (
667
+ "Authorization" ,
668
+ "Bearer " + TestJwts .STEPHEN_RSA_1 ,
669
+ "Content-Type" ,
670
+ ContentType .APPLICATION_JWT .toString ()
671
+ ),
630
672
new HashMap <>()
631
673
).asSecurityRequest (),
632
674
null
@@ -642,7 +684,7 @@ public void userinfoEndpointReturnsJsonMismatchedSubTest() throws Exception {
642
684
public void userinfoEndpointReturnsResponseNot2xxTest () throws Exception {
643
685
Settings settings = Settings .builder ()
644
686
.put ("openid_connect_url" , mockIdpServer .getDiscoverUri ())
645
- .put ("userinfo_endpoint" , mockIdpServer .getUserinfoUri ())
687
+ .put ("userinfo_endpoint" , mockIdpServer .getBadUserInfoUri ())
646
688
.put ("required_issuer" , TestJwts .TEST_ISSUER )
647
689
.put ("required_audience" , TestJwts .TEST_AUDIENCE + ",another_audience" )
648
690
.build ();
@@ -653,7 +695,7 @@ public void userinfoEndpointReturnsResponseNot2xxTest() throws Exception {
653
695
try {
654
696
creds = openIdAuthenticator .extractCredentials (
655
697
new FakeRestRequest (
656
- ImmutableMap .of ("Authorization" , TestJwts . MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
698
+ ImmutableMap .of ("Authorization" , STEPHEN_SUBJECT , "Content-Type" , ContentType . APPLICATION_JWT . toString () ),
657
699
new HashMap <>()
658
700
).asSecurityRequest (),
659
701
null
@@ -680,7 +722,12 @@ public void userinfoEndpointReturnsJsonWithRequiredAudIssPassesTest() throws Exc
680
722
681
723
AuthCredentials creds = openIdAuthenticator .extractCredentials (
682
724
new FakeRestRequest (
683
- ImmutableMap .of ("Authorization" , "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 , "Content-Type" , APPLICATION_JWT ),
725
+ ImmutableMap .of (
726
+ "Authorization" ,
727
+ "Bearer " + TestJwts .MC_COY_SIGNED_OCT_1 ,
728
+ "Content-Type" ,
729
+ ContentType .APPLICATION_JWT .toString ()
730
+ ),
684
731
new HashMap <>()
685
732
).asSecurityRequest (),
686
733
null
0 commit comments