Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add integration tests for OAuth2.0 DPoP #23215

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.identity.integration.test.oauth2;

import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationModel;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AccessTokenConfiguration;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.InboundProtocols;
import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration;

import static org.testng.Assert.assertNotNull;


public class OAuth2DPopTestCase extends OAuth2ServiceAbstractIntegrationTest {
private static final String BINDING_TYPE = "DPoP";
private static final boolean VALIDATE_TOKEN_BINDING = true;

private CloseableHttpClient client;
private OpenIDConnectConfiguration oidcConfig;

private String appID;
private String clientId;

@BeforeClass(alwaysRun = true)
public void testInit() throws Exception {
super.init(TestUserMode.SUPER_TENANT_USER);
super.setSystemproperties();
this.client = HttpClientBuilder.create()
.disableRedirectHandling()
.setDefaultRequestConfig(RequestConfig.custom()
.setCookieSpec(CookieSpecs.DEFAULT)
.build())
.setDefaultCookieSpecRegistry(RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, new RFC6265CookieSpecProvider())
.build())
.build();

this.appID = super.addApplication(this.getApplicationWithDpopEnabled());
assertNotNull(this.appID, "Error while creating the application with DPoP enabled.");

this.oidcConfig = super.restClient.getOIDCInboundDetails(this.appID);
assertNotNull(this.oidcConfig, "Error while retrieving the OIDC configuration of the application.");

this.clientId = this.oidcConfig.getClientId();
}

@AfterClass(alwaysRun = true)
public void testClear() throws Exception {
super.deleteApp(this.appID);
this.client.close();
super.restClient.closeHttpClient();
}

private ApplicationModel getApplicationWithDpopEnabled() {
final ApplicationModel application = new ApplicationModel();
AccessTokenConfiguration accessTokenConfiguration = new AccessTokenConfiguration().type("JWT");
accessTokenConfiguration.setBindingType(BINDING_TYPE);
accessTokenConfiguration.setValidateTokenBinding(VALIDATE_TOKEN_BINDING);

OpenIDConnectConfiguration oidcConfig = new OpenIDConnectConfiguration();
oidcConfig.setAccessToken(accessTokenConfiguration);

InboundProtocols inboundProtocolsConfig = new InboundProtocols();
inboundProtocolsConfig.setOidc(oidcConfig);

application.setInboundProtocolConfiguration(inboundProtocolsConfig);
application.setName("DPoPTestSP");

return application;
}

@Test(groups = "wso2.is",
description = "")
public void test() throws Exception {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class AccessTokenConfiguration {

private String type;
private String bindingType;
private Long userAccessTokenExpiryInSeconds;
private Long applicationAccessTokenExpiryInSeconds;
private Boolean revokeTokensWhenIDPSessionTerminated;
Expand All @@ -53,6 +54,24 @@ public void setType(String type) {
this.type = type;
}

/**
**/
public AccessTokenConfiguration bindingType(String bindingType) {

this.bindingType = bindingType;
return this;
}

@ApiModelProperty(example = "DPoP", value = "")
@JsonProperty("bindingType")
@Valid
public String getBindingType() {
return bindingType;
}
public void setBindingType(String bindingType) {
this.bindingType = bindingType;
}

/**
**/
public AccessTokenConfiguration userAccessTokenExpiryInSeconds(Long userAccessTokenExpiryInSeconds) {
Expand Down Expand Up @@ -162,14 +181,15 @@ public boolean equals(Object o) {
}
AccessTokenConfiguration accessTokenConfiguration = (AccessTokenConfiguration) o;
return Objects.equals(this.type, accessTokenConfiguration.type) &&
Objects.equals(this.bindingType, accessTokenConfiguration.bindingType) &&
Objects.equals(this.userAccessTokenExpiryInSeconds, accessTokenConfiguration.userAccessTokenExpiryInSeconds) &&
Objects.equals(this.applicationAccessTokenExpiryInSeconds, accessTokenConfiguration.applicationAccessTokenExpiryInSeconds) &&
Objects.equals(this.accessTokenAttributes, accessTokenConfiguration.accessTokenAttributes);
}

@Override
public int hashCode() {
return Objects.hash(type, userAccessTokenExpiryInSeconds, applicationAccessTokenExpiryInSeconds,
return Objects.hash(type, bindingType, userAccessTokenExpiryInSeconds, applicationAccessTokenExpiryInSeconds,
accessTokenAttributes);
}

Expand All @@ -180,6 +200,7 @@ public String toString() {
sb.append("class AccessTokenConfiguration {\n");

sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" bindingType: ").append(toIndentedString(bindingType)).append("\n");
sb.append(" userAccessTokenExpiryInSeconds: ").append(toIndentedString(userAccessTokenExpiryInSeconds)).append("\n");
sb.append(" applicationAccessTokenExpiryInSeconds: ").append(toIndentedString(applicationAccessTokenExpiryInSeconds)).append("\n");
sb.append(" accessTokenAttributes: ").append(toIndentedString(accessTokenAttributes)).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<class name="org.wso2.identity.integration.test.oauth2.OAuth2RichAuthorizationRequestsTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.OAuth2RichAuthorizationRequestsGrantTypesTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.Oauth2ImpersonationTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.OAuth2DPopTestCase"/>
<class name="org.wso2.identity.integration.test.oidc.OIDCAccessTokenAttributesTestCase"/>
<class name="org.wso2.identity.integration.test.oauth2.OAuth2AuthorizationCodeGrantJWTTokenTestCase"/>
<class name="org.wso2.identity.integration.test.recovery.PasswordRecoveryTestCase"/>
Expand Down