Skip to content

Commit

Permalink
Merge branch 'master' into ChangeSubscriptionBusinessPlanForcefullyTe…
Browse files Browse the repository at this point in the history
…stCase-
  • Loading branch information
thisaltennakoon authored Jul 23, 2024
2 parents 5a8e8f5 + 22b2218 commit f5e0238
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---


[![Build Status](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fwso2.org%2Fjenkins%2Fview%2Fproducts%2Fjob%2Fproducts%2Fjob%2Fproduct-apim%2F)](https://wso2.org/jenkins/view/products/job/products/job/product-apim/)
[![Build Status](https://wso2.org/jenkins/job/products/job/product-apim/badge/icon)](https://wso2.org/jenkins/job/products/job/product-apim/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![stackoverflow](https://img.shields.io/badge/stackoverflow-wso2am-orange)](https://stackoverflow.com/tags/wso2-am/)
[![slack](https://img.shields.io/badge/slack-wso2--apim-blueviolet)](https://join.slack.com/t/wso2-apim/shared_invite/enQtNzEzMzk5Njc5MzM0LTgwODI3NmQ1MjI0ZDQyMGNmZGI4ZjdkZmI1ZWZmMjNkY2E0NmY3ZmExYjkxYThjNzNkOTU2NWJmYzM4YzZiOWU?src=sidebar)
Expand Down
31 changes: 27 additions & 4 deletions modules/distribution/product/src/main/extensions/error.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
<%@ page isErrorPage="true" %>
<%@ page import="org.owasp.encoder.Encode" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="org.wso2.carbon.identity.event.IdentityEventException" %>
<%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.IdentityManagementEndpointUtil" %>
<%@ page import="org.wso2.carbon.identity.recovery.IdentityRecoveryConstants" %>
<%@ page import="org.wso2.carbon.identity.recovery.util.Utils" %>
<%@ page import="org.owasp.encoder.Encode" %>
<%@ page import="java.io.File" %>
<%@ page import="java.net.URISyntaxException" %>
Expand All @@ -32,8 +34,27 @@
<%
String errorMsg = IdentityManagementEndpointUtil.getStringValue(request.getAttribute("errorMsg"));
String errorCode = IdentityManagementEndpointUtil.getStringValue(request.getAttribute("errorCode"));
String invalidConfirmationErrorCode = IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CODE.getCode();
String callback = request.getParameter("callback");
boolean isValidCallback = true;
if (invalidConfirmationErrorCode.equals(errorCode)) {
String tenantDomain = StringUtils.EMPTY;
if (StringUtils.isNotBlank(request.getParameter("tenantdomain"))){
tenantDomain = request.getParameter("tenantdomain").trim();
} else if (StringUtils.isNotBlank(request.getParameter("tenantDomain"))){
tenantDomain = request.getParameter("tenantDomain").trim();
}
try {
if (StringUtils.isNotBlank(callback) && !Utils.validateCallbackURL
(callback, tenantDomain, IdentityRecoveryConstants.ConnectorConfig.RECOVERY_CALLBACK_REGEX)) {
isValidCallback = false;
}
} catch (IdentityEventException e) {
isValidCallback = false;
}
}
try {
IdentityManagementEndpointUtil.getURLEncodedCallback(callback);
} catch (URISyntaxException e) {
Expand Down Expand Up @@ -92,13 +113,11 @@
%>
</div>

<% if (isValidCallback) { %>
<div id="action-buttons" class="buttons">
<a href="javascript:goBack()" class="ui button primary button">
<a id = "go-back-button" href="javascript:goBack()" class="ui button primary button">
<%=IdentityManagementEndpointUtil.i18n(recoveryResourceBundle, "Go back")%>
</a>
</div>
<% } %>
</div>
</div>
</layout:component>
Expand Down Expand Up @@ -131,13 +150,17 @@
if ("<%=StringUtils.isEmpty(callback)%>" === "true") {
$("#action-buttons").hide();
}
if ("<%=isValidCallback%>" === "false") {
$("#go-back-button").addClass("disabled");
$("#action-buttons").attr("title", "Request has an invalid callback URL.");
}
});
<% if (isValidCallback) { %>
function goBack() {
var errorCodeFromParams = "<%=errorCode%>";
var invalidConfirmationErrorCode = "<%=IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_CODE.getCode()%>";
var invalidConfirmationErrorCode = "<%=invalidConfirmationErrorCode%>";
// Check if the error is related to the confirmation code being invalid.
// If so, navigate the users to the URL defined in `callback` URL param.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $mapping.get('properties')
#end
<payloadFactory description="transform" media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:web="${namespace}">
<soapenv:Envelope xmlns:soapenv="${soapNamespace}" xmlns:web="${namespace}">
<soapenv:Header/>
<soapenv:Body>
$mapping.get('sequence')
Expand All @@ -37,7 +37,7 @@ $mapping.get('properties')
$mapping.get('args')
</args>
</payloadFactory>
<property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
<property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="${mediaType}"/>
</then>
<else>
<payloadFactory media-type="json" description="transform">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.wso2.am.integration.clients.publisher.api.v1.dto.CommentListDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.DocumentDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.DocumentListDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.FileInfoDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.GatewayPolicyDeploymentDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.GatewayPolicyMappingInfoDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.GatewayPolicyMappingsDTO;
Expand Down Expand Up @@ -399,6 +400,10 @@ public APIDTO addAPI(APIDTO apidto, String osVersion) throws ApiException {
return httpInfo.getData();
}

public FileInfoDTO updateAPIThumbnail(String apiId, File file) throws ApiException {
return apIsApi.updateAPIThumbnail(apiId, file, null);
}

private boolean isAsyncApi(APIRequest apiRequest) {

String type = apiRequest.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public void testOperationPolicyAdditionWithMissingAttributes() throws Exception
apidto.getOperations().get(0).setOperationPolicies(apiOperationPoliciesDTO);

HttpResponse updateResponse = restAPIPublisher.updateAPIWithHttpInfo(apidto);
assertEquals(updateResponse.getResponseCode(), 500);
assertEquals(updateResponse.getResponseCode(), 400);
}

@Test(groups = {"wso2.am"}, description = "Invoke the API after adding the add header operation policy",
Expand All @@ -537,7 +537,7 @@ public void testAddOperationPolicyForNotSupportedFlow() throws Exception {
apidto.getOperations().get(0).setOperationPolicies(apiOperationPoliciesDTO);

HttpResponse updateResponse = restAPIPublisher.updateAPIWithHttpInfo(apidto);
assertEquals(updateResponse.getResponseCode(), 500);
assertEquals(updateResponse.getResponseCode(), 400);
}

@Test(groups = {"wso2.am"}, description = "Invoke the API after adding the add header operation policy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.wso2.am.integration.clients.publisher.api.v1.dto.APIListDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.APIOperationsDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.DocumentDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.FileInfoDTO;
import org.wso2.am.integration.clients.store.api.v1.dto.ApplicationDTO;
import org.wso2.am.integration.clients.store.api.v1.dto.ApplicationKeyDTO;
import org.wso2.am.integration.clients.store.api.v1.dto.ApplicationKeyGenerateRequestDTO;
Expand All @@ -63,6 +64,7 @@
import org.wso2.am.integration.test.utils.generic.TestConfigurationProvider;
import org.wso2.am.integration.test.utils.http.HTTPSClientUtils;
import org.wso2.am.integration.tests.api.lifecycle.APIManagerLifecycleBaseTest;
import org.wso2.am.integration.tests.restapi.RESTAPITestConstants;
import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment;
import org.wso2.carbon.automation.engine.annotations.SetEnvironment;
import org.wso2.carbon.automation.engine.context.TestUserMode;
Expand Down Expand Up @@ -101,6 +103,7 @@ public class APIImportExportTestCase extends APIManagerLifecycleBaseTest {
private final String NEW_API_NAME = "NewAPIImportExportTestCaseAPIName";
private final String PRESERVE_PUBLISHER_API_NAME = "preserveNewAPIImportExportAPIName";
private final String NOT_PRESERVE_PUBLISHER_API_NAME = "notPreserveNewAPIImportExportAPIName";
private final String API_WITH_THUMB_NAME = "apiWithThumb";
private final String PRESERVE_PUBLISHER_API_CONTEXT = "preserveAPIImportExportContext";
private final String NOT_PRESERVE_PUBLISHER_API_CONTEXT = "notPreserveAPIImportExportContext";
private final String API_CONTEXT = "APIImportExportTestCaseContext";
Expand All @@ -126,7 +129,7 @@ public class APIImportExportTestCase extends APIManagerLifecycleBaseTest {
private String allowedUser = "allowedUser";
private String publisherUser = "importExportPublisher";
private String publisherURLHttps;
private File zipTempDir, apiZip, newApiZip, preservePublisherApiZip, notPreservePublisherApiZip;
private File zipTempDir, apiZip, apiWithThumbZip, newApiZip, preservePublisherApiZip, notPreservePublisherApiZip;
private String importUrl;
private String exportUrl;
private APICreationRequestBean apiCreationRequestBean;
Expand All @@ -137,6 +140,7 @@ public class APIImportExportTestCase extends APIManagerLifecycleBaseTest {
private Map<String, String> requestHeaders = new HashMap<String, String>();
private String apiId;
private String newApiId;
private String apiWithThumbId;
private String applicationId;
private String newApplicationId;
private String preservePublisherApiId;
Expand Down Expand Up @@ -852,12 +856,75 @@ public void testRestrictedAPIExportFromAdminUser() throws Exception {
exportArtifact(exportRequest, apiZip, publisherUser, String.valueOf(PUBLISHER_USER_PASS));
}

@Test(groups = { "wso2.am" }, description = "Create and Export API with Thumb",
dependsOnMethods = "testRestrictedAPIExportFromAdminUser")
public void createAPIWithThumb() throws Exception {

// Create a dummy API
String imageFile = "thumbnail.png";
String provider = user.getUserName();
APIRequest apiRequest = new APIRequest(API_WITH_THUMB_NAME, "apiWithThumbContext", new URL(exportUrl));
apiRequest.setDescription("This is test API create by API manager integration test");
apiRequest.setVersion(API_VERSION);
apiRequest.setSandbox(exportUrl);
apiRequest.setResourceMethod("GET");
apiRequest.setProvider(provider);

// Check the API creation
HttpResponse response = restAPIPublisher.addAPI(apiRequest);
String APICreatedWithThumbId = response.getData();
int responseCode = response.getResponseCode();
Assert.assertEquals(responseCode, HttpStatus.SC_CREATED);

// Publish API
HttpResponse lifecycleResponse = restAPIPublisher.
changeAPILifeCycleStatusToPublish(APICreatedWithThumbId, false);
Assert.assertEquals(lifecycleResponse.getResponseCode(), HttpStatus.SC_OK);

// Set the Thumbnail
String imagePath = (new File(System.getProperty("user.dir"))).getParent() + RESTAPITestConstants.PATH_SUBSTRING
+ imageFile;
File image = new File(imagePath);
FileInfoDTO thumbUpdateResponse = restAPIPublisher.updateAPIThumbnail(APICreatedWithThumbId, image);
waitForAPIDeployment();
Assert.assertNotNull(thumbUpdateResponse.getRelativePath(), "Thumbnail hasn't been added successfully");
APIDTO apiWithThumbObj = getAPI(API_WITH_THUMB_NAME, API_VERSION, user.getUserName());
Assert.assertTrue(apiWithThumbObj.isHasThumbnail(), "hasThumbnail hasn't been updated successfully");

// Export API
URL exportRequest =
new URL(exportUrl + "?name=" + API_WITH_THUMB_NAME + "&version=" + API_VERSION + "&providerName="
+ provider + "&format=JSON");
String fileName = user.getUserDomain() + "_" + API_WITH_THUMB_NAME;
apiWithThumbZip = new File(zipTempDir.getAbsolutePath() + File.separator + fileName + ".zip");
exportArtifact(exportRequest, apiWithThumbZip, USER_WITH_ACCESS_ROLE, PASSWORD);

// Delete API
HttpResponse serviceResponse = restAPIPublisher.deleteAPI(APICreatedWithThumbId);
assertEquals(serviceResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "API delete failed");
}

@Test(groups = { "wso2.am" }, description = "Import exported API with Thumb", dependsOnMethods = "createAPIWithThumb")
public void testAPIImportWithThumb() throws Exception {

// upload the api zip which has thumbnail
importArtifact(importUrl, apiWithThumbZip, user.getUserName(), user.getPassword().toCharArray());
waitForAPIDeployment();

// get the imported API
APIDTO apiObjWithThumb = getAPI("apiWithThumb", API_VERSION, user.getUserName());
Assert.assertTrue(apiObjWithThumb.isHasThumbnail(), "Imported API has lost the thumbnail");

apiWithThumbId = apiObjWithThumb.getId();
}

@AfterClass(alwaysRun = true)
public void destroy() throws Exception {
allowedStoreUser.deleteApplication(applicationId);
allowedStoreUser.deleteApplication(newApplicationId);
restAPIPublisher.deleteAPI(apiId);
restAPIPublisher.deleteAPI(newApiId);
restAPIPublisher.deleteAPI(apiWithThumbId);
restAPIPublisher.deleteAPI(preservePublisherApiId);
restAPIPublisher.deleteAPI(notPreservePublisherApiId);
restAPIPublisher.deleteAPI(publisherAccessControlAPIId);
Expand All @@ -866,6 +933,8 @@ public void destroy() throws Exception {
Assert.assertTrue(deleteStatus, "temp file delete not successful");
deleteStatus = newApiZip.delete();
Assert.assertTrue(deleteStatus, "temp file delete not successful");
deleteStatus = apiWithThumbZip.delete();
Assert.assertTrue(deleteStatus, "temp file delete not successful");
deleteStatus = preservePublisherApiZip.delete();
Assert.assertTrue(deleteStatus, "temp file delete not successful");
deleteStatus = notPreservePublisherApiZip.delete();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@
<carbon.apimgt.ui.version>9.1.83</carbon.apimgt.ui.version>

<!-- APIM Component Version -->

<carbon.apimgt.version>9.29.169</carbon.apimgt.version>

<carbon.apimgt.imp.pkg.version>[9.0.0, 10.0.0)</carbon.apimgt.imp.pkg.version>
Expand Down

0 comments on commit f5e0238

Please sign in to comment.