Skip to content

Commit

Permalink
chore: Cherry-pick modifications from V2 to V3 between 2023-01-25 and…
Browse files Browse the repository at this point in the history
… 2024-01-31 (#3307)

* chore: add request with http client for jwt from zosmf (#3281)

---------

Signed-off-by: Pablo Hernán Carle <[email protected]>
Co-authored-by: Pablo Hernán Carle <[email protected]>

* Create user_story.md (#3293)

Signed-off-by: Jakub Balhar <[email protected]>

* test does not depend on getting oidc token first (#3301)

Signed-off-by: Pablo Hernán Carle <[email protected]>
Co-authored-by: Pablo Hernán Carle <[email protected]>

* fix: Fix base path in API Catalog (#3297)

---------

Signed-off-by: Pablo Hernán Carle <[email protected]>
Signed-off-by: Jakub Balhar <[email protected]>
Co-authored-by: Pablo Carle <[email protected]>
Co-authored-by: Pablo Hernán Carle <[email protected]>
Co-authored-by: Jakub Balhar <[email protected]>
Co-authored-by: Pavel Jareš <[email protected]>
  • Loading branch information
5 people authored Feb 8, 2024
1 parent 7b5019e commit adbc645
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 40 deletions.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/user_story.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: User Story
about: Story that is part of current ongoing effort. Created by the squad.
title: ''
labels: User Story
---

**Story**
A clear and concise description of what the bug is.

**Acceptance Criteria**

-

**Demonstration**

-

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.zowe.apiml.product.gateway.GatewayClient;
import org.zowe.apiml.product.gateway.GatewayConfigProperties;
import org.zowe.apiml.product.routing.RoutedService;
Expand Down Expand Up @@ -233,7 +235,7 @@ void givenUrlContainingPathAndQuery_whenTransform_thenKeepQueryPartInTheNewUrl()

@Test
void givenServiceAndApiRoute_whenGetApiBasePath_thenReturnApiPath() throws URLTransformationException {
String url = "https://localhost:8080/" + SERVICE_ID;
String url = "https://localhost:8080/" + SERVICE_ID + "/" + API_PREFIX + "/v1";

String serviceUrl = String.format("/%s/%s", SERVICE_ID, API_PREFIX);
RoutedServices routedServices = new RoutedServices();
Expand All @@ -251,7 +253,7 @@ void givenServiceAndApiRoute_whenGetApiBasePath_thenReturnApiPath() throws URLTr

@Test
void givenServiceAndApiRouteWithVersion_whenGetApiBasePath_thenReturnApiPath() throws URLTransformationException {
String url = "https://localhost:8080/" + SERVICE_ID;
String url = "https://localhost:8080/" + SERVICE_ID + "/" + API_PREFIX + "/v1";

String serviceUrl = String.format("/%s/%s/%s", SERVICE_ID, API_PREFIX, "v1");
RoutedServices routedServices = new RoutedServices();
Expand Down Expand Up @@ -295,4 +297,28 @@ void givenNoRoutes_whenGetApiBasePath_thenThrowError() {
assertEquals("Not able to select API base path for the service " + SERVICE_ID + ". Original url used.", exception.getMessage());
}

@ParameterizedTest
@CsvSource({
"service,api/v1,api/v1,api/v1,/service/api/{api-version}",
"srv,api/v1/home/page.html,api/v1,api/v1,/srv/api/{api-version}",
"srv,wrong/url,api/v1,api/v1,",
"srv,apiV1/home/page.html,api/v1,apiV1,/srv/api/{api-version}"
})
void testRetrieveApiBasePath(String serviceId, String url, String gatewayUrl, String serviceUrl, String expectedBasePath) {
RoutedService route = new RoutedService("api", gatewayUrl, serviceUrl);

RoutedServices routedServices = new RoutedServices();
routedServices.addRoutedService(route);

TransformService transformService = new TransformService(null);
String basePath;
try {
basePath = transformService.retrieveApiBasePath(serviceId, url, routedServices);
} catch (URLTransformationException e) {
basePath = null;
}

assertEquals(expectedBasePath, basePath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.zowe.apiml.product.routing;

import org.apache.commons.lang3.StringUtils;
import org.zowe.apiml.util.UrlUtils;

import java.util.HashMap;
Expand Down Expand Up @@ -102,7 +103,7 @@ private boolean isServiceTypeMatch(Map.Entry<String, RoutedService> serviceEntry
}

private boolean isMatchingApiRoute(String serviceUrl, String routeServiceUrl) {
return routeServiceUrl.startsWith(serviceUrl.toLowerCase());
return StringUtils.startsWithIgnoreCase(serviceUrl, routeServiceUrl);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ void testBestMatchingApiUrl() {
routedServices.addRoutedService(routedService1);
routedServices.addRoutedService(routedService2);

routedService = routedServices.getBestMatchingApiUrl("/test");
routedService = routedServices.getBestMatchingApiUrl("/test2/api/v2");

assertEquals("api_v2", routedService.getSubServiceId());
assertEquals("api/v2", routedService.getGatewayUrl());
assertEquals("/test2/api/v2", routedService.getServiceUrl());


}

@Test
Expand Down
12 changes: 6 additions & 6 deletions config/local/api-defs-http/staticclient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
description: Sample to demonstrate how to add an API service with Swagger to API Catalog using a static YAML definition # Description of the service in the API catalog
instanceBaseUrls: # list of base URLs for each instance
- http://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: / # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -36,7 +36,7 @@ services:
description: Sample to demonstrate how to add an API service without Swagger documentation to API Catalog using a static YAML definition # Description of the service in the API catalog
instanceBaseUrls: # list of base URLs for each instance
- http://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -61,7 +61,7 @@ services:
description: Define service to test by pass authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- http://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -80,7 +80,7 @@ services:
description: Define service to test passTicket authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- http://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -100,7 +100,7 @@ services:
description: Define service to test safIdt authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- http://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -120,7 +120,7 @@ services:
description: Define service to test zosmf authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand Down
14 changes: 7 additions & 7 deletions config/local/api-defs/staticclient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
description: Sample to demonstrate how to add an API service with Swagger to API Catalog using a static YAML definition # Description of the service in the API catalog
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: / # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -36,7 +36,7 @@ services:
description: Sample to demonstrate how to add an API service without Swagger documentation to API Catalog using a static YAML definition # Description of the service in the API catalog
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -61,7 +61,7 @@ services:
description: Sample to demonstrate how to add an API service without Swagger documentation to API Catalog using a static YAML definition # Description of the service in the API catalog
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -84,7 +84,7 @@ services:
description: Define service to test by pass authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -103,7 +103,7 @@ services:
description: Define service to test passTicket authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -123,7 +123,7 @@ services:
description: Define service to test safIdt authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand All @@ -143,7 +143,7 @@ services:
description: Define service to test zosmf authentication schema for integration tests.
instanceBaseUrls: # list of base URLs for each instance
- https://localhost:10012/discoverableclient # scheme://hostname:port/contextPath
homePageRelativeUrl: # Normally used for informational purposes for other services to use it as a landing page
homePageRelativeUrl: /api/v1 # Normally used for informational purposes for other services to use it as a landing page
statusPageRelativeUrl: /application/info # Appended to the instanceBaseUrl
healthCheckRelativeUrl: /application/health # Appended to the instanceBaseUrl
routes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,23 @@
import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.JSON;
import static io.restassured.http.ContentType.XML;
import static org.apache.http.HttpStatus.*;
import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_OK;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.zowe.apiml.integration.zaas.ZaasTestUtil.*;
import static org.zowe.apiml.util.SecurityUtils.*;
import static org.zowe.apiml.integration.zaas.ZaasTestUtil.COOKIE;
import static org.zowe.apiml.integration.zaas.ZaasTestUtil.ZAAS_TICKET_URI;
import static org.zowe.apiml.util.SecurityUtils.USERNAME;
import static org.zowe.apiml.util.SecurityUtils.generateZoweJwtWithLtpa;
import static org.zowe.apiml.util.SecurityUtils.getConfiguredSslConfig;
import static org.zowe.apiml.util.SecurityUtils.getZosmfJwtToken;
import static org.zowe.apiml.util.SecurityUtils.getZosmfLtpaToken;
import static org.zowe.apiml.util.SecurityUtils.personalAccessToken;
import static org.zowe.apiml.util.SecurityUtils.validOktaAccessToken;

/**
* Verify integration of the API ML PassTicket support with the zOS provider of the PassTicket.
Expand Down Expand Up @@ -81,7 +90,7 @@ void givenValidZosmfToken() {

@Test
void givenValidZoweTokenWithLtpa() throws UnrecoverableKeyException, CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException {
String ltpaToken = getZosmfToken(LTPA_COOKIE);
String ltpaToken = getZosmfLtpaToken();
String zoweToken = generateZoweJwtWithLtpa(ltpaToken);

//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public class ZaasNegativeTest {

private final static String APPLICATION_NAME = ConfigReader.environmentConfiguration().getDiscoverableClientConfiguration().getApplId();

private static final String OKTA_TOKEN_NO_MAPPING = SecurityUtils.validOktaAccessToken(false);

private static final Set<URI> tokenEndpoints = new HashSet<URI>() {{
add(ZAAS_ZOWE_URI);
add(ZAAS_ZOSMF_URI);
Expand All @@ -68,6 +66,7 @@ public class ZaasNegativeTest {
add(generateJwtWithRandomSignature("https://localhost:10010"));
}};

@SuppressWarnings("unused")
private static Stream<Arguments> provideZaasEndpointsWithAllTokens() {
List<Arguments> argumentsList = new ArrayList<>();
for (URI uri : endpoints) {
Expand All @@ -83,6 +82,7 @@ private static Stream<Arguments> provideZaasEndpointsWithAllTokens() {
return argumentsList.stream();
}

@SuppressWarnings("unused")
private static Stream<Arguments> provideZaasEndpoints() {
List<Arguments> argumentsList = new ArrayList<>();
for (URI uri : endpoints) {
Expand All @@ -95,6 +95,7 @@ private static Stream<Arguments> provideZaasEndpoints() {
return argumentsList.stream();
}

@SuppressWarnings("unused")
private static Stream<Arguments> provideZaasTokenEndpoints() {
List<Arguments> argumentsList = new ArrayList<>();
for (URI uri : tokenEndpoints) {
Expand Down Expand Up @@ -143,9 +144,10 @@ void givenInvalidToken(URI uri, RequestSpecification requestSpecification, Strin
@ParameterizedTest
@MethodSource("org.zowe.apiml.integration.zaas.ZaasNegativeTest#provideZaasEndpoints")
void givenOKTATokenWithNoMapping(URI uri, RequestSpecification requestSpecification) {
String oktaTokenNoMapping = SecurityUtils.validOktaAccessToken(false);
//@formatter:off
requestSpecification
.header("Authorization", "Bearer " + OKTA_TOKEN_NO_MAPPING)
.header("Authorization", "Bearer " + oktaTokenNoMapping)
.when()
.post(uri)
.then()
Expand Down
Loading

0 comments on commit adbc645

Please sign in to comment.