2424import org .opensearch .security .user .AuthCredentials ;
2525import org .opensearch .security .util .FakeRestRequest ;
2626
27+ import com .nimbusds .common .contenttype .ContentType ;
28+
2729import static org .hamcrest .MatcherAssert .assertThat ;
2830import static org .hamcrest .Matchers .is ;
29- import static com .amazon .dlic .auth .http .jwt .keybyoidc .OpenIdConstants .APPLICATION_JWT ;
3031import static com .amazon .dlic .auth .http .jwt .keybyoidc .OpenIdConstants .CLIENT_ID ;
3132import static com .amazon .dlic .auth .http .jwt .keybyoidc .OpenIdConstants .ISSUER_ID_URL ;
3233import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .MCCOY_SUBJECT ;
3334import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .OIDC_TEST_AUD ;
3435import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .OIDC_TEST_ISS ;
3536import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .ROLES_CLAIM ;
37+ import static com .amazon .dlic .auth .http .jwt .keybyoidc .TestJwts .STEPHEN_SUBJECT ;
3638import static org .junit .Assert .assertTrue ;
3739import static org .mockito .Mockito .spy ;
3840
@@ -435,7 +437,12 @@ public void userinfoEndpointReturnsJwtWithAllRequirementsTest() throws Exception
435437
436438 AuthCredentials creds = openIdAuthenticator .extractCredentials (
437439 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+ ),
439446 new HashMap <>()
440447 ).asSecurityRequest (),
441448 null
@@ -448,8 +455,8 @@ public void userinfoEndpointReturnsJwtWithAllRequirementsTest() throws Exception
448455
449456 @ Test
450457 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
453460 Settings settings = Settings .builder ()
454461 .put ("openid_connect_url" , mockIdpServer .getDiscoverUri ())
455462 .put ("userinfo_endpoint" , mockIdpServer .getUserinfoSignedUri ())
@@ -466,7 +473,12 @@ public void userinfoEndpointReturnsJwtWithRequiredAudIssFailsTest() throws Excep
466473 try {
467474 creds = openIdAuthenticator .extractCredentials (
468475 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+ ),
470482 new HashMap <>()
471483 ).asSecurityRequest (),
472484 null
@@ -493,7 +505,12 @@ public void userinfoEndpointReturnsJwtWithMatchingRequiredAudIssPassesTest() thr
493505
494506 AuthCredentials creds = openIdAuthenticator .extractCredentials (
495507 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+ ),
497514 new HashMap <>()
498515 ).asSecurityRequest (),
499516 null
@@ -520,7 +537,12 @@ public void userinfoEndpointReturnsJwtMissingIssuerTest() throws Exception {
520537 try {
521538 creds = openIdAuthenticator .extractCredentials (
522539 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+ ),
524546 new HashMap <>()
525547 ).asSecurityRequest (),
526548 null
@@ -548,7 +570,12 @@ public void userinfoEndpointReturnsJwtMissingAudienceTest() throws Exception {
548570 try {
549571 creds = openIdAuthenticator .extractCredentials (
550572 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+ ),
552579 new HashMap <>()
553580 ).asSecurityRequest (),
554581 null
@@ -575,7 +602,12 @@ public void userinfoEndpointReturnsJwtMismatchedSubTest() throws Exception {
575602 try {
576603 creds = openIdAuthenticator .extractCredentials (
577604 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+ ),
579611 new HashMap <>()
580612 ).asSecurityRequest (),
581613 null
@@ -600,7 +632,12 @@ public void userinfoEndpointReturnsJsonWithAllRequirementsTest() throws Exceptio
600632
601633 AuthCredentials creds = openIdAuthenticator .extractCredentials (
602634 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+ ),
604641 new HashMap <>()
605642 ).asSecurityRequest (),
606643 null
@@ -626,7 +663,12 @@ public void userinfoEndpointReturnsJsonMismatchedSubTest() throws Exception {
626663 try {
627664 creds = openIdAuthenticator .extractCredentials (
628665 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+ ),
630672 new HashMap <>()
631673 ).asSecurityRequest (),
632674 null
@@ -642,7 +684,7 @@ public void userinfoEndpointReturnsJsonMismatchedSubTest() throws Exception {
642684 public void userinfoEndpointReturnsResponseNot2xxTest () throws Exception {
643685 Settings settings = Settings .builder ()
644686 .put ("openid_connect_url" , mockIdpServer .getDiscoverUri ())
645- .put ("userinfo_endpoint" , mockIdpServer .getUserinfoUri ())
687+ .put ("userinfo_endpoint" , mockIdpServer .getBadUserInfoUri ())
646688 .put ("required_issuer" , TestJwts .TEST_ISSUER )
647689 .put ("required_audience" , TestJwts .TEST_AUDIENCE + ",another_audience" )
648690 .build ();
@@ -653,7 +695,7 @@ public void userinfoEndpointReturnsResponseNot2xxTest() throws Exception {
653695 try {
654696 creds = openIdAuthenticator .extractCredentials (
655697 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 () ),
657699 new HashMap <>()
658700 ).asSecurityRequest (),
659701 null
@@ -680,7 +722,12 @@ public void userinfoEndpointReturnsJsonWithRequiredAudIssPassesTest() throws Exc
680722
681723 AuthCredentials creds = openIdAuthenticator .extractCredentials (
682724 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+ ),
684731 new HashMap <>()
685732 ).asSecurityRequest (),
686733 null
0 commit comments