From c7c62fdb6c1243917fd5d75d96c515c15082105d Mon Sep 17 00:00:00 2001 From: shnrndk Date: Mon, 4 Dec 2023 12:42:38 +0530 Subject: [PATCH 1/8] add update provider rest api --- .../admin/src/main/resources/admin-api.yaml | 193 ++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml index 69131316c6..d6de60e3aa 100644 --- a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml +++ b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml @@ -4267,6 +4267,43 @@ paths: source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -F "type=WSO2-IS" "https://127.0.0.1:9443/api/am/admin/v4/key-managers/discover"' + ###################################################### + # API Provider Resource + ###################################################### + /apis/{apiId}/provider/{providerName}: + put: + tags: + - Api Provider Change + summary: Update the api provider + description: | + Update the api provider + parameters: + - $ref: '#/components/parameters/providerName' + - $ref: '#/components/parameters/apiId' + operationId: providerProviderNameApisApiIdPut + responses: + 200: + description: | + OK. + Api Provider updated. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + 400: + $ref: '#/components/responses/BadRequest' + 404: + $ref: '#/components/responses/NotFound' + security: + - OAuth2Security: + - apim:admin + - apim:api_provider_change + x-code-samples: + - lang: Curl + source: 'curl -k -X PUT -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + -H "Content-Type: application/json" "https://127.0.0.1:9443/api/am/admin/v4/provider/admin/apis/33662a62-8db1-4d75-af08-afd63c6bd0b4"' components: schemas: Error: @@ -5937,6 +5974,145 @@ components: - Internal/subscriber items: type: string + APIList: + title: API List + type: object + properties: + count: + type: integer + description: | + Number of APIs returned. + example: 1 + list: + type: array + items: + $ref: '#/components/schemas/APIInfomation' + pagination: + $ref: '#/components/schemas/PaginationApis' + APIInfomation: + title: API Info object with basic API details. + type: object + properties: + id: + type: string + example: 01234567-0123-0123-0123-012345678901 + name: + type: string + example: CalculatorAPI + description: + type: string + example: A calculator API that supports basic operations + context: + type: string + example: CalculatorAPI + additionalProperties: + type: array + items: + type: object + properties: + name: + type: string + value: + type: string + display: + type: boolean + description: Map of custom properties of API + additionalPropertiesMap: + type: object + additionalProperties: + type: object + properties: + name: + type: string + value: + type: string + display: + type: boolean + default: false + version: + type: string + example: 1.0.0 + provider: + type: string + description: | + If the provider value is not given, the user invoking the API will be used as the provider. + example: admin + type: + type: string + example: HTTP + audience: + type: string + description: The audience of the API. Accepted values are PUBLIC, SINGLE + example: PUBLIC + enum: + - PUBLIC + - SINGLE + lifeCycleStatus: + type: string + example: CREATED + workflowStatus: + type: string + example: APPROVED + hasThumbnail: + type: boolean + example: true + securityScheme: + type: array + items: + type: string + createdTime: + type: string + example: 2021-02-11 09:57:25 + updatedTime: + type: string + example: 2021-02-11 09:57:25 + updatedBy: + type: string + example: wso2.system.user + gatewayVendor: + type: string + example: wso2 + advertiseOnly: + type: boolean + example: true + monetizedInfo: + type: boolean + example: true + businessOwner: + type: string + example: Business Owner + businessOwnerEmail: + type: string + example: businessowner@abc.com + TechnicalOwner: + type: string + example: Technical Owner + TechnicalOwnerEmail: + type: string + example: technicalowner@abc.com + PaginationApis: + title: Pagination + type: object + properties: + offset: + type: integer + example: 0 + limit: + type: integer + example: 1 + total: + type: integer + example: 10 + next: + type: string + description: | + Link to the next subset of resources qualified. + Empty if no more resources are to be returned. + previous: + type: string + description: | + Link to the previous subset of resources qualified. + Empty if current subset is the first subset returned. responses: BadRequest: description: Bad Request. Invalid request or validation error. @@ -6232,6 +6408,22 @@ components: required: true schema: type: string + providerName: + name: providerName + in: path + description: | + Provider Name + required: true + schema: + type: string + apiId: + name: apiId + in: path + description: | + API Id + required: true + schema: + type: string securitySchemes: OAuth2Security: type: oauth2 @@ -6269,3 +6461,4 @@ components: apim:admin_alert_manage: Manage admin alerts apim:api_workflow_view: Retrive workflow requests apim:scope_manage: Manage system scopes + apim:api_provider_change: Retrieve and manage applications \ No newline at end of file From bafe7a7ca0b0af6d595c3a5284d7fa6af7b0e657 Mon Sep 17 00:00:00 2001 From: shnrndk Date: Mon, 4 Dec 2023 14:24:32 +0530 Subject: [PATCH 2/8] Change Api Provider Test Case Added --- .../admin/ChangeApiProviderTestCase.java | 155 ++++++++++++++++++ .../src/test/resources/testng.xml | 1 + 2 files changed, 156 insertions(+) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java new file mode 100644 index 0000000000..84f7c6f8da --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java @@ -0,0 +1,155 @@ +package org.wso2.am.integration.tests.admin; + +import jdk.internal.joptsimple.internal.Strings; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpStatus; +import org.junit.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Factory; +import org.testng.annotations.Test; +import org.wso2.am.integration.clients.admin.ApiResponse; +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; +import org.wso2.am.integration.test.impl.RestAPIAdminImpl; +import org.wso2.am.integration.test.impl.RestAPIStoreImpl; +import org.wso2.am.integration.test.utils.base.APIMIntegrationBaseTest; +import org.wso2.am.integration.test.utils.base.APIMIntegrationConstants; +import org.wso2.am.integration.test.utils.bean.APILifeCycleAction; +import org.wso2.am.integration.test.utils.bean.APIRequest; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.carbon.integration.common.admin.client.UserManagementClient; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import static org.testng.Assert.assertEquals; +import static org.wso2.am.integration.test.utils.base.APIMIntegrationConstants.SUPER_TENANT_DOMAIN; + +public class ChangeApiProviderTestCase extends APIMIntegrationBaseTest { + + private String publisherURLHttp; + private RestAPIAdminImpl restAPIAdminClient; + private String BEARER = "Bearer "; + private String APIName = "NewApiForProviderChange"; + private String APIContext = "NewApiForProviderChange"; + private String tags = "youtube, token, media"; + private String apiEndPointUrl; + private String description = "This is test API create by API manager integration test"; + private String APIVersion = "1.0.0"; + private String apiID; + private String newUser = "peter123"; + private String newUserPass = "test123"; + private String[] subscriberRole = {APIMIntegrationConstants.APIM_INTERNAL_ROLE.CREATOR}; + private String APPLICATION_NAME = "testApplicationForProviderChange"; + private String applicationId; + private String TIER_GOLD = "Gold"; + private String API_ENDPOINT_POSTFIX_URL = "jaxrs_basic/services/customers/customerservice/"; + private String API_ENDPOINT_METHOD = "customers/123"; + private int HTTP_RESPONSE_CODE_OK = Response.Status.OK.getStatusCode(); + private String RESPONSE_CODE_MISMATCH_ERROR_MESSAGE = "Response code mismatch"; + private String TENANT_ADMIN = "admin"; + private String TENANT_ADMIN_PWD = "admin123"; + private String TENANT_DOMAIN = "tenant.com"; + + @Factory(dataProvider = "userModeDataProvider") + public ChangeApiProviderTestCase(TestUserMode userMode) { + + this.userMode = userMode; + } + + @DataProvider + public static Object[][] userModeDataProvider() { + + return new Object[][]{new Object[]{TestUserMode.SUPER_TENANT_ADMIN}, + new Object[]{TestUserMode.TENANT_ADMIN},}; + } + + @BeforeClass(alwaysRun = true) + public void setEnvironment() throws Exception { + + super.init(userMode); + publisherURLHttp = getPublisherURLHttp(); + userManagementClient = new UserManagementClient(keyManagerContext.getContextUrls().getBackEndUrl(), + createSession(keyManagerContext)); + userManagementClient.addUser(newUser, newUserPass, subscriberRole, newUser); + restAPIStore = + new RestAPIStoreImpl(storeContext.getContextTenant().getContextUser().getUserNameWithoutDomain(), + storeContext.getContextTenant().getContextUser().getPassword(), + storeContext.getContextTenant().getDomain(), storeURLHttps); + apiEndPointUrl = backEndServerUrl.getWebAppURLHttp() + API_ENDPOINT_POSTFIX_URL; + restAPIAdminClient = new RestAPIAdminImpl(TENANT_ADMIN, TENANT_ADMIN_PWD, TENANT_DOMAIN, publisherURLHttps); + } + + @Test(groups = {"wso2.am"}, description = "Calling API with invalid token") + public void ChangeApiProvider() throws Exception { + String providerName = user.getUserName(); + APIRequest apiRequest = new APIRequest(APIName, APIContext, new URL(apiEndPointUrl)); + apiRequest.setTags(tags); + apiRequest.setProvider(providerName); + apiRequest.setDescription(description); + apiRequest.setVersion(APIVersion); + apiRequest.setResourceMethod("GET"); + + //add test api + HttpResponse serviceResponse = restAPIPublisher.addAPI(apiRequest); + assertEquals(serviceResponse.getResponseCode(), Response.Status.CREATED.getStatusCode(), + "Response Code miss matched when creating the API"); + apiID = serviceResponse.getData(); + + // Create Revision and Deploy to Gateway + createAPIRevisionAndDeployUsingRest(apiID, restAPIPublisher); + + //publish the api + restAPIPublisher.changeAPILifeCycleStatus(apiID, APILifeCycleAction.PUBLISH.getAction(), null); + + HttpResponse applicationResponse = restAPIStore.createApplication(APPLICATION_NAME, Strings.EMPTY, + APIMIntegrationConstants.APPLICATION_TIER.UNLIMITED, + ApplicationDTO.TokenTypeEnum.JWT); + + applicationId = applicationResponse.getData(); + + restAPIStore.subscribeToAPI(apiID, applicationId, TIER_GOLD); + ArrayList grantTypes = new ArrayList<>(); + grantTypes.add(APIMIntegrationConstants.GRANT_TYPE.CLIENT_CREDENTIAL); + ApplicationKeyDTO applicationKeyDTO = restAPIStore.generateKeys(applicationId, + APIMIntegrationConstants.DEFAULT_TOKEN_VALIDITY_TIME, + null, + ApplicationKeyGenerateRequestDTO.KeyTypeEnum.PRODUCTION, + null, grantTypes); + Assert.assertNotNull(applicationKeyDTO.getToken()); + String accessToken = applicationKeyDTO.getToken().getAccessToken(); + + HashMap requestHeaders = new HashMap<>(); + requestHeaders.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + requestHeaders.put(HttpHeaders.AUTHORIZATION, BEARER + accessToken); + HttpResponse apiInvokeResponse = HttpRequestUtil.doGet( + getAPIInvocationURLHttps(APIContext.replace(File.separator, Strings.EMPTY), APIVersion) + + File.separator + API_ENDPOINT_METHOD, requestHeaders); + assertEquals(apiInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, RESPONSE_CODE_MISMATCH_ERROR_MESSAGE); + + //Update provider of the api + ApiResponse changeProviderResponse = restAPIAdminClient.changeApiProvider(newUser, apiID); + Assert.assertEquals(changeProviderResponse.getStatusCode(), HttpStatus.SC_OK); + + apiInvokeResponse = HttpRequestUtil.doGet( + getAPIInvocationURLHttps(APIContext.replace(File.separator, Strings.EMPTY), APIVersion) + + File.separator + API_ENDPOINT_METHOD, requestHeaders); + assertEquals(apiInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, RESPONSE_CODE_MISMATCH_ERROR_MESSAGE); + } + + @AfterClass(alwaysRun = true) + public void destroy() throws Exception { + undeployAndDeleteAPIRevisionsUsingRest(apiID, restAPIPublisher); + restAPIPublisher.deleteAPI(apiID); + super.cleanUp(); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index b2d080143b..a76cc6a335 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -256,6 +256,7 @@ + From 4f2b43421d30fb7127a952d257776c4d325ef286 Mon Sep 17 00:00:00 2001 From: shnrndk Date: Tue, 19 Dec 2023 14:43:01 +0530 Subject: [PATCH 3/8] Revert "add update provider rest api" This reverts commit c7c62fdb6c1243917fd5d75d96c515c15082105d. --- .../admin/src/main/resources/admin-api.yaml | 193 ------------------ 1 file changed, 193 deletions(-) diff --git a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml index d6de60e3aa..69131316c6 100644 --- a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml +++ b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml @@ -4267,43 +4267,6 @@ paths: source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -F "type=WSO2-IS" "https://127.0.0.1:9443/api/am/admin/v4/key-managers/discover"' - ###################################################### - # API Provider Resource - ###################################################### - /apis/{apiId}/provider/{providerName}: - put: - tags: - - Api Provider Change - summary: Update the api provider - description: | - Update the api provider - parameters: - - $ref: '#/components/parameters/providerName' - - $ref: '#/components/parameters/apiId' - operationId: providerProviderNameApisApiIdPut - responses: - 200: - description: | - OK. - Api Provider updated. - headers: - Content-Type: - description: | - The content type of the body. - schema: - type: string - 400: - $ref: '#/components/responses/BadRequest' - 404: - $ref: '#/components/responses/NotFound' - security: - - OAuth2Security: - - apim:admin - - apim:api_provider_change - x-code-samples: - - lang: Curl - source: 'curl -k -X PUT -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" - -H "Content-Type: application/json" "https://127.0.0.1:9443/api/am/admin/v4/provider/admin/apis/33662a62-8db1-4d75-af08-afd63c6bd0b4"' components: schemas: Error: @@ -5974,145 +5937,6 @@ components: - Internal/subscriber items: type: string - APIList: - title: API List - type: object - properties: - count: - type: integer - description: | - Number of APIs returned. - example: 1 - list: - type: array - items: - $ref: '#/components/schemas/APIInfomation' - pagination: - $ref: '#/components/schemas/PaginationApis' - APIInfomation: - title: API Info object with basic API details. - type: object - properties: - id: - type: string - example: 01234567-0123-0123-0123-012345678901 - name: - type: string - example: CalculatorAPI - description: - type: string - example: A calculator API that supports basic operations - context: - type: string - example: CalculatorAPI - additionalProperties: - type: array - items: - type: object - properties: - name: - type: string - value: - type: string - display: - type: boolean - description: Map of custom properties of API - additionalPropertiesMap: - type: object - additionalProperties: - type: object - properties: - name: - type: string - value: - type: string - display: - type: boolean - default: false - version: - type: string - example: 1.0.0 - provider: - type: string - description: | - If the provider value is not given, the user invoking the API will be used as the provider. - example: admin - type: - type: string - example: HTTP - audience: - type: string - description: The audience of the API. Accepted values are PUBLIC, SINGLE - example: PUBLIC - enum: - - PUBLIC - - SINGLE - lifeCycleStatus: - type: string - example: CREATED - workflowStatus: - type: string - example: APPROVED - hasThumbnail: - type: boolean - example: true - securityScheme: - type: array - items: - type: string - createdTime: - type: string - example: 2021-02-11 09:57:25 - updatedTime: - type: string - example: 2021-02-11 09:57:25 - updatedBy: - type: string - example: wso2.system.user - gatewayVendor: - type: string - example: wso2 - advertiseOnly: - type: boolean - example: true - monetizedInfo: - type: boolean - example: true - businessOwner: - type: string - example: Business Owner - businessOwnerEmail: - type: string - example: businessowner@abc.com - TechnicalOwner: - type: string - example: Technical Owner - TechnicalOwnerEmail: - type: string - example: technicalowner@abc.com - PaginationApis: - title: Pagination - type: object - properties: - offset: - type: integer - example: 0 - limit: - type: integer - example: 1 - total: - type: integer - example: 10 - next: - type: string - description: | - Link to the next subset of resources qualified. - Empty if no more resources are to be returned. - previous: - type: string - description: | - Link to the previous subset of resources qualified. - Empty if current subset is the first subset returned. responses: BadRequest: description: Bad Request. Invalid request or validation error. @@ -6408,22 +6232,6 @@ components: required: true schema: type: string - providerName: - name: providerName - in: path - description: | - Provider Name - required: true - schema: - type: string - apiId: - name: apiId - in: path - description: | - API Id - required: true - schema: - type: string securitySchemes: OAuth2Security: type: oauth2 @@ -6461,4 +6269,3 @@ components: apim:admin_alert_manage: Manage admin alerts apim:api_workflow_view: Retrive workflow requests apim:scope_manage: Manage system scopes - apim:api_provider_change: Retrieve and manage applications \ No newline at end of file From f87841ebbadc81068abf83dbb2d3e8540371496c Mon Sep 17 00:00:00 2001 From: shnrndk Date: Thu, 21 Dec 2023 09:24:47 +0530 Subject: [PATCH 4/8] Change Api Provider Test Case Bugs fix --- .../admin/src/main/resources/admin-api.yaml | 158 ++++++++++++++++++ .../clients/publisher/api/v1/dto/APIDTO.java | 31 +++- .../test/impl/RestAPIAdminImpl.java | 6 + .../admin/ChangeApiProviderTestCase.java | 3 +- 4 files changed, 196 insertions(+), 2 deletions(-) diff --git a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml index 69131316c6..fc0572c316 100644 --- a/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml +++ b/modules/integration/tests-common/clients/admin/src/main/resources/admin-api.yaml @@ -4266,7 +4266,106 @@ paths: - lang: Shell source: 'curl -k -X POST -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" -F "type=WSO2-IS" "https://127.0.0.1:9443/api/am/admin/v4/key-managers/discover"' + ###################################################### + # The "API Collection" resource APIs + ###################################################### + /apis: + get: + tags: + - APIs + summary: | + Retrieve/Search APIs + description: | + This operation provides you a list of available APIs qualifying under a given search condition. + Each retrieved API is represented with a minimal amount of attributes. If you want to get complete details of an API, you need to use **Get details of an API** operation. + parameters: + - $ref: '#/components/parameters/limit' + - $ref: '#/components/parameters/offset' + - name: query + in: query + description: | + **Search and get all apis in admin portal**. + You can search by proving a keyword. + schema: + type: string + - $ref: '#/components/parameters/If-None-Match' + responses: + 200: + description: | + OK. + List of qualifying APIs is returned. + headers: + ETag: + description: | + Entity Tag of the response resource. Used by caches, or in conditional requests (Will be supported in future). + schema: + type: string + Content-Type: + description: The content type of the body. + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/SearchResultList' + 304: + description: | + Not Modified. + Empty body because the client has already the latest version of the requested resource (Will be supported in future). + content: { } + 406: + $ref: '#/components/responses/NotAcceptable' + security: + - OAuth2Security: + - apim:admin + - apim:api_provider_change + x-code-samples: + - lang: Curl + source: 'curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + "https://127.0.0.1:9443/api/am/publisher/v4/apis"' + operationId: getAllAPIs + ###################################################### + # Change Api Provider + ###################################################### + /apis/{apiId}/change-provider: + post: + tags: + - Api Provider Change + summary: Update the api provider + description: | + Update the api provider + operationId: providerNamePost + parameters: + - name: provider + in: query + required: true + schema: + type: string + - $ref: '#/components/parameters/apiId' + responses: + 200: + description: | + OK. + Api Provider updated. + headers: + Content-Type: + description: | + The content type of the body. + schema: + type: string + 400: + $ref: '#/components/responses/BadRequest' + 404: + $ref: '#/components/responses/NotFound' + security: + - OAuth2Security: + - apim:admin + - apim:api_provider_change + x-code-samples: + - lang: Curl + source: 'curl -k -X PUT -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" + -H "Content-Type: application/json" "https://127.0.0.1:9443/api/am/admin/v4/provider/admin/apis/33662a62-8db1-4d75-af08-afd63c6bd0b4"' components: schemas: Error: @@ -5937,6 +6036,57 @@ components: - Internal/subscriber items: type: string + SearchResultList: + title: Unified Search Result List + type: object + properties: + apis: + type: array + items: + $ref: '#/components/schemas/ApiResult' + count: + type: integer + description: | + Number of results returned. + example: 1 + pagination: + $ref: '#/components/schemas/Pagination' + ApiResult: + type: object + properties: + provider: + type: string + name: + type: string + version: + type: string + id: + type: string + Pagination: + title: Pagination + type: object + properties: + offset: + type: integer + example: 0 + limit: + type: integer + example: 1 + total: + type: integer + example: 10 + next: + type: string + description: | + Link to the next subset of resources qualified. + Empty if no more resources are to be returned. + example: "" + previous: + type: string + description: | + Link to the previous subset of resources qualified. + Empty if current subset is the first subset returned. + example: "" responses: BadRequest: description: Bad Request. Invalid request or validation error. @@ -6232,6 +6382,14 @@ components: required: true schema: type: string + apiId: + name: apiId + in: path + description: | + **API ID** consisting of the **UUID** of the API. + required: true + schema: + type: string securitySchemes: OAuth2Security: type: oauth2 diff --git a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java index be8c66c016..2ccfa175ca 100644 --- a/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java +++ b/modules/integration/tests-common/clients/publisher/src/gen/java/org/wso2/am/integration/clients/publisher/api/v1/dto/APIDTO.java @@ -256,6 +256,10 @@ public AudienceEnum read(final JsonReader jsonReader) throws IOException { @SerializedName(SERIALIZED_NAME_AUTHORIZATION_HEADER) private String authorizationHeader; + public static final String SERIALIZED_NAME_API_KEY_HEADER = "apiKeyHeader"; + @SerializedName(SERIALIZED_NAME_API_KEY_HEADER) + private String apiKeyHeader; + public static final String SERIALIZED_NAME_SECURITY_SCHEME = "securityScheme"; @SerializedName(SERIALIZED_NAME_SECURITY_SCHEME) private List securityScheme = null; @@ -1151,6 +1155,29 @@ public void setAuthorizationHeader(String authorizationHeader) { } + public APIDTO apiKeyHeader(String apiKeyHeader) { + + this.apiKeyHeader = apiKeyHeader; + return this; + } + + /** + * Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. + * @return apiKeyHeader + **/ + @javax.annotation.Nullable + @ApiModelProperty(example = "apiKey", value = "Name of the API key header used for invoking the API. If it is not set, default value `apiKey` will be used. ") + + public String getApiKeyHeader() { + return apiKeyHeader; + } + + + public void setApiKeyHeader(String apiKeyHeader) { + this.apiKeyHeader = apiKeyHeader; + } + + public APIDTO securityScheme(List securityScheme) { this.securityScheme = securityScheme; @@ -1921,6 +1948,7 @@ public boolean equals(Object o) { Objects.equals(this.policies, API.policies) && Objects.equals(this.apiThrottlingPolicy, API.apiThrottlingPolicy) && Objects.equals(this.authorizationHeader, API.authorizationHeader) && + Objects.equals(this.apiKeyHeader, API.apiKeyHeader) && Objects.equals(this.securityScheme, API.securityScheme) && Objects.equals(this.maxTps, API.maxTps) && Objects.equals(this.visibility, API.visibility) && @@ -1957,7 +1985,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(id, name, description, context, version, provider, lifeCycleStatus, wsdlInfo, wsdlUrl, responseCachingEnabled, cacheTimeout, hasThumbnail, isDefaultVersion, isRevision, revisionedApiId, revisionId, enableSchemaValidation, enableSubscriberVerification, type, audience, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, securityScheme, maxTps, visibility, visibleRoles, visibleTenants, mediationPolicies, apiPolicies, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, accessControl, accessControlRoles, businessInformation, corsConfiguration, websubSubscriptionConfiguration, workflowStatus, createdTime, lastUpdatedTimestamp, lastUpdatedTime, endpointConfig, endpointImplementationType, scopes, operations, threatProtectionPolicies, categories, keyManagers, serviceInfo, advertiseInfo, gatewayVendor, asyncTransportProtocols); + return Objects.hash(id, name, description, context, version, provider, lifeCycleStatus, wsdlInfo, wsdlUrl, responseCachingEnabled, cacheTimeout, hasThumbnail, isDefaultVersion, isRevision, revisionedApiId, revisionId, enableSchemaValidation, enableSubscriberVerification, type, audience, transport, tags, policies, apiThrottlingPolicy, authorizationHeader, apiKeyHeader, securityScheme, maxTps, visibility, visibleRoles, visibleTenants, mediationPolicies, apiPolicies, subscriptionAvailability, subscriptionAvailableTenants, additionalProperties, additionalPropertiesMap, monetization, accessControl, accessControlRoles, businessInformation, corsConfiguration, websubSubscriptionConfiguration, workflowStatus, createdTime, lastUpdatedTimestamp, lastUpdatedTime, endpointConfig, endpointImplementationType, scopes, operations, threatProtectionPolicies, categories, keyManagers, serviceInfo, advertiseInfo, gatewayVendor, asyncTransportProtocols); } @@ -1990,6 +2018,7 @@ public String toString() { sb.append(" policies: ").append(toIndentedString(policies)).append("\n"); sb.append(" apiThrottlingPolicy: ").append(toIndentedString(apiThrottlingPolicy)).append("\n"); sb.append(" authorizationHeader: ").append(toIndentedString(authorizationHeader)).append("\n"); + sb.append(" apiKeyHeader: ").append(toIndentedString(apiKeyHeader)).append("\n"); sb.append(" securityScheme: ").append(toIndentedString(securityScheme)).append("\n"); sb.append(" maxTps: ").append(toIndentedString(maxTps)).append("\n"); sb.append(" visibility: ").append(toIndentedString(visibility)).append("\n"); diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java index 044a41881f..c9779084bb 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/impl/RestAPIAdminImpl.java @@ -57,6 +57,7 @@ public class RestAPIAdminImpl { private ThrottlingPolicySearchApi throttlingPolicySearchApi = new ThrottlingPolicySearchApi(); private SystemScopesApi systemScopesApi = new SystemScopesApi(); private ApplicationApi applicationApi = new ApplicationApi(); + private ApiProviderChangeApi apiProviderChangeApi = new ApiProviderChangeApi(); private LabelApi labelApi = new LabelApi(); private LabelCollectionApi labelCollectionApi = new LabelCollectionApi(); private EnvironmentApi environmentApi = new EnvironmentApi(); @@ -150,6 +151,7 @@ public RestAPIAdminImpl(String username, String password, String tenantDomain, S systemScopesApi.setApiClient(apiAdminClient); tenantConfigApi.setApiClient(apiAdminClient); tenantConfigSchemaApi.setApiClient(apiAdminClient); + apiProviderChangeApi.setApiClient(apiAdminClient); this.tenantDomain = tenantDomain; } @@ -698,6 +700,10 @@ public ApiResponse changeApplicationOwner(String newOwner, String applicat return applicationApi.applicationsApplicationIdChangeOwnerPostWithHttpInfo(newOwner, applicationId); } + public ApiResponse changeApiProvider(String newProvider, String apiId) throws ApiException { + return apiProviderChangeApi.providerNamePostWithHttpInfo(newProvider, apiId); + } + public HttpResponse getWorkflowByExternalWorkflowReference(String externalWorkflowRef) throws ApiException { WorkflowInfoDTO workflowInfodto = null; HttpResponse response = null; diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java index 84f7c6f8da..7bf8e8fefc 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java @@ -86,7 +86,6 @@ public void setEnvironment() throws Exception { storeContext.getContextTenant().getContextUser().getPassword(), storeContext.getContextTenant().getDomain(), storeURLHttps); apiEndPointUrl = backEndServerUrl.getWebAppURLHttp() + API_ENDPOINT_POSTFIX_URL; - restAPIAdminClient = new RestAPIAdminImpl(TENANT_ADMIN, TENANT_ADMIN_PWD, TENANT_DOMAIN, publisherURLHttps); } @Test(groups = {"wso2.am"}, description = "Calling API with invalid token") @@ -137,6 +136,7 @@ public void ChangeApiProvider() throws Exception { assertEquals(apiInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, RESPONSE_CODE_MISMATCH_ERROR_MESSAGE); //Update provider of the api + restAPIAdminClient = new RestAPIAdminImpl(TENANT_ADMIN, TENANT_ADMIN_PWD, TENANT_DOMAIN, publisherURLHttps); ApiResponse changeProviderResponse = restAPIAdminClient.changeApiProvider(newUser, apiID); Assert.assertEquals(changeProviderResponse.getStatusCode(), HttpStatus.SC_OK); @@ -149,6 +149,7 @@ public void ChangeApiProvider() throws Exception { @AfterClass(alwaysRun = true) public void destroy() throws Exception { undeployAndDeleteAPIRevisionsUsingRest(apiID, restAPIPublisher); + restAPIStore.deleteApplication(applicationId); restAPIPublisher.deleteAPI(apiID); super.cleanUp(); } From 048ba0c6a300f47f7458d157c23ce175a5489f57 Mon Sep 17 00:00:00 2001 From: shnrndk Date: Thu, 21 Dec 2023 11:37:19 +0530 Subject: [PATCH 5/8] new scopes added --- .../artifacts/AM/configFiles/common/tenant-conf.json | 12 ++++++++++++ .../linterCustomRulesTest/tenant-conf.json | 12 ++++++++++++ .../AM/configFiles/monetization/tenant-conf.json | 12 ++++++++++++ .../AM/configFiles/notification/tenant-conf.json | 12 ++++++++++++ .../AM/configFiles/tenantConf/tenant-conf.json | 12 ++++++++++++ 5 files changed, 60 insertions(+) diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/common/tenant-conf.json b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/common/tenant-conf.json index d3b51d1d8a..ff2f47135f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/common/tenant-conf.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/common/tenant-conf.json @@ -356,6 +356,18 @@ { "Name": "apim:admin_tier_view", "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_manage", + "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_view", + "Roles": "admin,Internal/creator,Internal/publisher,Internal/observer" + }, + { + "Name": "apim:api_provider_change", + "Roles": "admin" } ] }, diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/linterCustomRulesTest/tenant-conf.json b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/linterCustomRulesTest/tenant-conf.json index cdfd74e214..f7e162679f 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/linterCustomRulesTest/tenant-conf.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/linterCustomRulesTest/tenant-conf.json @@ -372,6 +372,18 @@ { "Name": "apim:admin_tier_view", "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_manage", + "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_view", + "Roles": "admin,Internal/creator,Internal/publisher,Internal/observer" + }, + { + "Name": "apim:api_provider_change", + "Roles": "admin" } ] }, diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/monetization/tenant-conf.json b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/monetization/tenant-conf.json index baf97cec81..0eced40453 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/monetization/tenant-conf.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/monetization/tenant-conf.json @@ -356,6 +356,18 @@ { "Name": "apim:admin_tier_view", "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_manage", + "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_view", + "Roles": "admin,Internal/creator,Internal/publisher,Internal/observer" + }, + { + "Name": "apim:api_provider_change", + "Roles": "admin" } ] }, diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/notification/tenant-conf.json b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/notification/tenant-conf.json index f94a83790c..fa2f1375ae 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/notification/tenant-conf.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/notification/tenant-conf.json @@ -356,6 +356,18 @@ { "Name": "apim:admin_tier_view", "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_manage", + "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_view", + "Roles": "admin,Internal/creator,Internal/publisher,Internal/observer" + }, + { + "Name": "apim:api_provider_change", + "Roles": "admin" } ] }, diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/tenantConf/tenant-conf.json b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/tenantConf/tenant-conf.json index 205ff6e62b..e097660fae 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/tenantConf/tenant-conf.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/artifacts/AM/configFiles/tenantConf/tenant-conf.json @@ -356,6 +356,18 @@ { "Name": "apim:admin_tier_view", "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_manage", + "Roles": "admin" + }, + { + "Name": "apim:gateway_policy_view", + "Roles": "admin,Internal/creator,Internal/publisher,Internal/observer" + }, + { + "Name": "apim:api_provider_change", + "Roles": "admin" } ] }, From 87e2582d81e4b6859e942a41495578f81955f1ea Mon Sep 17 00:00:00 2001 From: Sahan Randika Date: Fri, 26 Jan 2024 09:42:11 +0530 Subject: [PATCH 6/8] fix test failures --- .../tests/admin/ChangeApiProviderTestCase.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java index 7bf8e8fefc..79f7867432 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java @@ -47,6 +47,7 @@ public class ChangeApiProviderTestCase extends APIMIntegrationBaseTest { private String APIVersion = "1.0.0"; private String apiID; private String newUser = "peter123"; + private String firstUserName = "admin"; private String newUserPass = "test123"; private String[] subscriberRole = {APIMIntegrationConstants.APIM_INTERNAL_ROLE.CREATOR}; private String APPLICATION_NAME = "testApplicationForProviderChange"; @@ -56,9 +57,6 @@ public class ChangeApiProviderTestCase extends APIMIntegrationBaseTest { private String API_ENDPOINT_METHOD = "customers/123"; private int HTTP_RESPONSE_CODE_OK = Response.Status.OK.getStatusCode(); private String RESPONSE_CODE_MISMATCH_ERROR_MESSAGE = "Response code mismatch"; - private String TENANT_ADMIN = "admin"; - private String TENANT_ADMIN_PWD = "admin123"; - private String TENANT_DOMAIN = "tenant.com"; @Factory(dataProvider = "userModeDataProvider") public ChangeApiProviderTestCase(TestUserMode userMode) { @@ -97,7 +95,6 @@ public void ChangeApiProvider() throws Exception { apiRequest.setDescription(description); apiRequest.setVersion(APIVersion); apiRequest.setResourceMethod("GET"); - //add test api HttpResponse serviceResponse = restAPIPublisher.addAPI(apiRequest); assertEquals(serviceResponse.getResponseCode(), Response.Status.CREATED.getStatusCode(), @@ -136,10 +133,12 @@ public void ChangeApiProvider() throws Exception { assertEquals(apiInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, RESPONSE_CODE_MISMATCH_ERROR_MESSAGE); //Update provider of the api - restAPIAdminClient = new RestAPIAdminImpl(TENANT_ADMIN, TENANT_ADMIN_PWD, TENANT_DOMAIN, publisherURLHttps); - ApiResponse changeProviderResponse = restAPIAdminClient.changeApiProvider(newUser, apiID); - Assert.assertEquals(changeProviderResponse.getStatusCode(), HttpStatus.SC_OK); - + restAPIAdminClient = new RestAPIAdminImpl(firstUserName, firstUserName, "carbon.super", + adminURLHttps); + if(user.getUserName().equals(firstUserName)){ + ApiResponse changeProviderResponse = restAPIAdminClient.changeApiProvider(newUser, apiID); + Assert.assertEquals(changeProviderResponse.getStatusCode(), HttpStatus.SC_OK); + } apiInvokeResponse = HttpRequestUtil.doGet( getAPIInvocationURLHttps(APIContext.replace(File.separator, Strings.EMPTY), APIVersion) + File.separator + API_ENDPOINT_METHOD, requestHeaders); @@ -151,6 +150,7 @@ public void destroy() throws Exception { undeployAndDeleteAPIRevisionsUsingRest(apiID, restAPIPublisher); restAPIStore.deleteApplication(applicationId); restAPIPublisher.deleteAPI(apiID); + userManagementClient.deleteUser(newUser); super.cleanUp(); } } From db41bd77187a0b389dbb9a035a1e9f2eeb006ca7 Mon Sep 17 00:00:00 2001 From: Sahan Randika Date: Wed, 7 Feb 2024 12:02:40 +0530 Subject: [PATCH 7/8] add licence header --- .../tests/admin/ChangeApiProviderTestCase.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java index 79f7867432..e227b3dc22 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/admin/ChangeApiProviderTestCase.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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.am.integration.tests.admin; import jdk.internal.joptsimple.internal.Strings; From 763ad1f9fd7b1007a18776a8d199d957d818dd08 Mon Sep 17 00:00:00 2001 From: Sahan Randika Date: Thu, 8 Feb 2024 11:32:22 +0530 Subject: [PATCH 8/8] bump carbon version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a10d810cca..9b6cf22634 100644 --- a/pom.xml +++ b/pom.xml @@ -1281,7 +1281,7 @@ - 9.29.15 + 9.29.21 [9.0.0, 10.0.0)