Skip to content

Commit

Permalink
addressed code review
Browse files Browse the repository at this point in the history
Signed-off-by: Amanda D'Errico <[email protected]>
  • Loading branch information
AmandaDErrico committed Mar 30, 2022
1 parent 60e1c67 commit 0fa4f7b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import lombok.Data;
import lombok.experimental.Tolerate;

import java.util.Objects;

@Data
@Builder
public class ConfigProperties {
Expand All @@ -29,6 +31,8 @@ public class ConfigProperties {
private boolean httpOnly;
private boolean nonStrictVerifySslCertificatesOfServices;

private static final String GATEWAY_SERVICE_ID = "gateway";

@Tolerate
public ConfigProperties() {
// no args constructor
Expand All @@ -47,4 +51,28 @@ public ConfigProperties withoutKeyStore() {
.build();
}

public void setApimlBaseUrl(String baseUrl) {
if (baseUrl == null) { // default path
apimlBaseUrl = "/gateway/api/v1/auth";
}
else if (baseUrl.contains("/") && baseUrl.contains(GATEWAY_SERVICE_ID)) {
String[] baseUrlParts = baseUrl.split("/");
if (Objects.equals(baseUrlParts[2], GATEWAY_SERVICE_ID)) {
apimlBaseUrl = "/gateway/" + baseUrlParts[0] + "/" + baseUrlParts[1] + "/auth";
}
else if (Objects.equals(baseUrlParts[3], GATEWAY_SERVICE_ID)) {
apimlBaseUrl = "/gateway/" + baseUrlParts[1] + "/" + baseUrlParts[2] + "/auth";
}
else if (!baseUrl.startsWith("/")) { // starts with gateway/..
apimlBaseUrl = "/" + baseUrl;
}
else {
apimlBaseUrl = baseUrl;
}
}
else {
apimlBaseUrl = baseUrl;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,14 @@ public ConfigProperties getConfigProperties() {
ConfigProperties configProperties = new ConfigProperties();
configProperties.setApimlHost(host);
configProperties.setApimlPort(port);
configProperties.setApimlBaseUrl(baseUrl);
configProperties.setKeyStorePath(keyStorePath);
configProperties.setKeyStorePassword(keyStorePassword);
configProperties.setKeyStoreType(keyStoreType);
configProperties.setTrustStorePath(trustStorePath);
configProperties.setTrustStorePassword(trustStorePassword);
configProperties.setTrustStoreType(trustStoreType);
configProperties.setNonStrictVerifySslCertificatesOfServices(nonStrictVerifySslCertificatesOfServices);

String updatedBaseUrl;
if (!baseUrl.startsWith("/gateway")) {
// rearrange path to match new base url format - {service id}/{type}/{api version} - both paths supported until March 2023
updatedBaseUrl = "/gateway" + baseUrl.substring(0, baseUrl.indexOf("/gateway")) + "/auth";
} else {
updatedBaseUrl = baseUrl;
}
configProperties.setApimlBaseUrl(updatedBaseUrl);
return configProperties;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.zaasclient.service.internal;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.zowe.apiml.zaasclient.config.ConfigProperties;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

class ZaasClientApimlBaseUrlTest {

private static final String ZOWE_V2_BASE_URL = "/gateway/api/v1/auth";

@ParameterizedTest
@ValueSource(strings = {"/api/v1/gateway/auth", "api/v1/gateway/auth", "/gateway/api/v1/auth", "gateway/api/v1/auth"})
void givenBaseUrl_thenTransformToOrDontChangeZoweV2BaseUrl(String baseUrl) {
ConfigProperties configProperties = new ConfigProperties();
configProperties.setApimlBaseUrl(baseUrl);
assertThat(configProperties.getApimlBaseUrl(), is(ZOWE_V2_BASE_URL));
}

@ParameterizedTest
@ValueSource(strings = {"/api/v1/zaasClient/auth", "api.v1.zaasClient.auth"})
void givenBaseUrl_thenDontChangeBaseUrl(String baseUrl) {
ConfigProperties configProperties = new ConfigProperties();
configProperties.setApimlBaseUrl(baseUrl);
assertThat(configProperties.getApimlBaseUrl(), is(baseUrl));
}

@Test
void givenBaseUrlIsNull_thenTransformToZoweV2BaseUrl() {
ConfigProperties configProperties = new ConfigProperties();
configProperties.setApimlBaseUrl(null);
assertThat(configProperties.getApimlBaseUrl(), is(ZOWE_V2_BASE_URL));
}
}

0 comments on commit 0fa4f7b

Please sign in to comment.