-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1688 from GluuFederation/oxauth-jans-issue-1503-f…
…or-4.4.1 feat(oxauth): added restriction for request_uri parameter (blacklist/allowed list) (4.4.1)
- Loading branch information
Showing
5 changed files
with
141 additions
and
17 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
77 changes: 77 additions & 0 deletions
77
Server/src/test/java/org/gluu/oxauth/model/authorize/JwtAuthorizationRequestTest.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,77 @@ | ||
package org.gluu.oxauth.model.authorize; | ||
|
||
import org.gluu.oxauth.model.configuration.AppConfiguration; | ||
import org.gluu.oxauth.model.error.ErrorResponseFactory; | ||
import org.gluu.oxauth.model.registration.Client; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
/** | ||
* @author Yuriy Zabrovarnyy | ||
*/ | ||
public class JwtAuthorizationRequestTest { | ||
|
||
@Test | ||
public void validateRequestUri_whichIsAllowedByClient_shouldBeOk() { | ||
String requestUri = "https://myrp.com/request_uri"; | ||
|
||
Client client = new Client(); | ||
client.setRequestUris(new String[]{"https://myrp.com/request_uri"}); | ||
JwtAuthorizationRequest.validateRequestUri(requestUri, client, new AppConfiguration(), "", new ErrorResponseFactory()); | ||
} | ||
|
||
@Test | ||
public void validateRequestUri_withNoRestrictions_shouldBeOk() { | ||
String requestUri = "https://myrp.com/request_uri"; | ||
|
||
JwtAuthorizationRequest.validateRequestUri(requestUri, new Client(), new AppConfiguration(), "", new ErrorResponseFactory()); | ||
} | ||
|
||
@Test(expectedExceptions = WebApplicationException.class) | ||
public void validateRequestUri_whichIsNotAllowedByClient_shouldRaiseException() { | ||
String requestUri = "https://myrp.com/request_uri"; | ||
|
||
Client client = new Client(); | ||
client.setRequestUris(new String[]{"https://myrp.com"}); | ||
JwtAuthorizationRequest.validateRequestUri(requestUri, client, new AppConfiguration(), "", new ErrorResponseFactory()); | ||
} | ||
|
||
@Test(expectedExceptions = WebApplicationException.class) | ||
public void validateRequestUri_whichIsBlackListed_shouldRaiseException() { | ||
String requestUri = "https://myrp.com/request_uri"; | ||
|
||
final AppConfiguration appConfiguration = new AppConfiguration(); | ||
appConfiguration.setRequestUriBlackList(Arrays.asList("myrp.com", "evil.com")); | ||
JwtAuthorizationRequest.validateRequestUri(requestUri, new Client(), appConfiguration, "", new ErrorResponseFactory()); | ||
} | ||
|
||
@Test(expectedExceptions = WebApplicationException.class) | ||
public void validateRequestUri_forLocalhost_shouldRaiseException() { | ||
String requestUri = "https://localhost/request_uri"; | ||
|
||
final AppConfiguration appConfiguration = new AppConfiguration(); | ||
appConfiguration.setRequestUriBlackList(Collections.singletonList("localhost")); | ||
JwtAuthorizationRequest.validateRequestUri(requestUri, new Client(), appConfiguration, "", new ErrorResponseFactory()); | ||
} | ||
|
||
@Test(expectedExceptions = WebApplicationException.class) | ||
public void validateRequestUri_forLocalhostIp_shouldRaiseException() { | ||
String requestUri = "https://127.0.0.1/request_uri"; | ||
|
||
final AppConfiguration appConfiguration = new AppConfiguration(); | ||
appConfiguration.setRequestUriBlackList(Collections.singletonList("127.0.0.1")); | ||
JwtAuthorizationRequest.validateRequestUri(requestUri, new Client(), appConfiguration, "", new ErrorResponseFactory()); | ||
} | ||
|
||
@Test | ||
public void validateRequestUri_whichIsNotBlackListed_shouldBeOk() { | ||
String requestUri = "https://myrp.com/request_uri"; | ||
|
||
final AppConfiguration appConfiguration = new AppConfiguration(); | ||
appConfiguration.setRequestUriBlackList(Arrays.asList("evil.com", "second.com")); | ||
JwtAuthorizationRequest.validateRequestUri(requestUri, new Client(), appConfiguration, "", new ErrorResponseFactory()); | ||
} | ||
} |