-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'nenaraab-decode-jwt-from-multiple-xsuaa'
- Loading branch information
Showing
14 changed files
with
173 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorForCloneTokenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.sap.cloud.security.xsuaa.token.authentication; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import com.nimbusds.jwt.JWTClaimsSet; | ||
import com.sap.cloud.security.xsuaa.XsuaaServiceConfiguration; | ||
import com.sap.cloud.security.xsuaa.test.JwtGenerator; | ||
import com.sap.cloud.security.xsuaa.token.Token; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.security.oauth2.core.OAuth2Error; | ||
import org.springframework.security.oauth2.core.OAuth2ErrorCodes; | ||
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; | ||
|
||
public class XsuaaAudienceValidatorForCloneTokenTest { | ||
|
||
private JWTClaimsSet.Builder claimsBuilder; | ||
private String XSUAA_BROKER_XSAPPNAME = "brokerplanmasterapp!b123"; | ||
private String XSUAA_BROKER_CLIENT_ID = "sb-" + XSUAA_BROKER_XSAPPNAME; | ||
private XsuaaAudienceValidator cut; | ||
|
||
@Before | ||
public void setup() { | ||
XsuaaServiceConfiguration serviceConfiguration = new XsuaaAudienceValidatorTest.DummyXsuaaServiceConfiguration( | ||
"sb-test1!t1", "test1!t1"); | ||
cut = new XsuaaAudienceValidator(serviceConfiguration); | ||
cut.configureAnotherXsuaaInstance(XSUAA_BROKER_XSAPPNAME, XSUAA_BROKER_CLIENT_ID); | ||
|
||
claimsBuilder = new JWTClaimsSet.Builder().issueTime(new Date()).expirationTime(JwtGenerator.NO_EXPIRE_DATE); | ||
} | ||
|
||
@Test | ||
public void tokenWithClientId_like_brokerClientId_shouldBeIgnored() { | ||
claimsBuilder.claim(Token.CLIENT_ID, XSUAA_BROKER_CLIENT_ID); | ||
|
||
OAuth2TokenValidatorResult result = cut.validate(JwtGenerator.createFromClaims(claimsBuilder.build())); | ||
Assert.assertFalse(result.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void cloneTokenClientId_like_brokerClientId_shouldBeAccepted() { | ||
claimsBuilder.claim(Token.CLIENT_ID, "sb-clone1!b22|" + XSUAA_BROKER_XSAPPNAME); | ||
|
||
OAuth2TokenValidatorResult result = cut.validate(JwtGenerator.createFromClaims(claimsBuilder.build())); | ||
Assert.assertFalse(result.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void cloneTokenClientId_unlike_brokerClientId_raisesError() { | ||
claimsBuilder.claim(Token.CLIENT_ID, "sb-clone1!b22|ANOTHERAPP!b12"); | ||
|
||
OAuth2TokenValidatorResult result = cut.validate(JwtGenerator.createFromClaims(claimsBuilder.build())); | ||
Assert.assertTrue(result.hasErrors()); | ||
|
||
List<OAuth2Error> errors = new ArrayList<>(result.getErrors()); | ||
Assert.assertThat(errors.get(0).getDescription(), | ||
is("Jwt token audience matches none of these: [test1!t1, brokerplanmasterapp!b123]")); | ||
Assert.assertThat(errors.get(0).getErrorCode(), is(OAuth2ErrorCodes.INVALID_CLIENT)); | ||
} | ||
|
||
} |
Oops, something went wrong.