Skip to content

Commit

Permalink
Fix issue #494
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Sep 17, 2024
1 parent bf085e5 commit a5e72f1
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public API updateAPIProxy(API api) throws AppException {
}
}

private String[] getSerializeAllExcept() throws AppException {
public String[] getSerializeAllExcept() throws AppException {
String[] serializeAllExcept;
// queryStringPassThrough added in inboundProfiles on API manager version 7.7.20220530
if (queryStringPassThroughBreakingVersion.contains(APIManagerAdapter.getInstance().getApiManagerVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class EnvironmentProperties implements Map<String, String> {
public static final String FALSE = "false";
public static final boolean RETAIN_BACKEND_URL = Boolean.parseBoolean(System.getenv().getOrDefault("retain.backend.url", FALSE));
public static final boolean PRINT_CONFIG_CONSOLE = Boolean.parseBoolean(System.getenv().getOrDefault("print_console", FALSE));
public static final boolean OVERRIDE_CERTIFICATES = Boolean.parseBoolean(System.getenv().getOrDefault("override_certificates", FALSE));
public static final boolean CHECK_CATALOG = Boolean.parseBoolean(System.getenv().getOrDefault("check_catalog", FALSE));
private static final Logger LOG = LoggerFactory.getLogger(EnvironmentProperties.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.axway.apim.WiremockWrapper;
import com.axway.apim.adapter.APIManagerAdapter;
import com.axway.apim.adapter.client.apps.ClientAppFilter;
import com.axway.apim.adapter.jackson.QuotaRestrictionDeserializer;
import com.axway.apim.api.API;
import com.axway.apim.api.model.*;
import com.axway.apim.api.model.apps.ClientApplication;
Expand All @@ -11,7 +12,15 @@
import com.axway.apim.lib.CoreParameters;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.utils.Utils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -786,4 +795,28 @@ public boolean parse(byte[] apiSpecificationContent) throws AppException {
}


@Test
public void updateAPIProxyWithBasicAuthEmptyPassword() throws IOException {
String testConfig = this.getClass().getResource("/com/axway/apim/adapter/conf/outbound_basic_auth_empty_password.json").getPath();
File file = new File(testConfig);
ObjectMapper mapper = Utils.createObjectMapper(new File(testConfig));
SimpleModule module = new SimpleModule();
module.addDeserializer(QuotaRestriction.class, new QuotaRestrictionDeserializer(QuotaRestrictionDeserializer.DeserializeMode.configFile, false));
// We would like to get back the original AppExcepption instead of a JsonMappingException
mapper.disable(DeserializationFeature.WRAP_EXCEPTIONS);
mapper.registerModule(module);
ObjectReader reader = mapper.reader();
API baseConfig = reader.forType(API.class).readValue(file);
System.out.println(baseConfig.getAuthenticationProfiles());

ObjectMapper objectMapper = new ObjectMapper();
String[] serializeAllExcept = apiManagerAPIAdapter.getSerializeAllExcept();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
FilterProvider filter = new SimpleFilterProvider().setDefaultFilter(
SimpleBeanPropertyFilter.serializeAllExcept(serializeAllExcept));
objectMapper.setFilterProvider(filter);

System.out.println(objectMapper.writeValueAsString(baseConfig));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "test",
"path": "/test",
"state": "Published",
"version": "1.0.0",
"organization": "orga",
"authenticationProfiles": [
{
"name": "_default",
"isDefault": true,
"parameters": {
"username": "daskdjaskldjaskljdklasjdl",
"password": ""
},
"type": "http_basic"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.error.ErrorCode;
import com.axway.apim.lib.utils.Utils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -96,7 +95,6 @@ public APIImportConfigAdapter(String apiConfigFileName, String stage, String pat
// We would like to get back the original AppExcepption instead of a JsonMappingException
mapper.disable(DeserializationFeature.WRAP_EXCEPTIONS);
mapper.registerModule(module);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
ObjectReader reader = mapper.reader();
API baseConfig = reader.withAttribute(VALIDATE_ORGANIZATION, validateOrganization).forType(DesiredAPI.class).readValue(Utils.substituteVariables(this.apiConfigFile));
if (stageConfigFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.axway.apim.lib.APIPropertiesExport;
import com.axway.apim.lib.error.AppException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -64,6 +65,10 @@ public void execute(APIChangeState changes, boolean reCreation) throws AppExcept
rollback.addRollbackAction(new RollbackAPIProxy(createdAPI)); // In any case, register the API just created for a potential rollback

try {
if(EnvironmentProperties.OVERRIDE_CERTIFICATES){
//Ignore certificates downloaded from backend.
createdAPI.setCaCerts(new ArrayList<>());
}
// ... here we basically need to add all props to initially bring the API in sync!
APIChangeState.initCreatedAPI(desiredAPI, createdAPI);
//handle backend base path update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class APIImportConfigAdapterTest extends WiremockWrapper {

private static final Logger LOG = LoggerFactory.getLogger(APIImportConfigAdapterTest.class);
private String apimCliHome;

@BeforeClass
public void initWiremock() {
super.initWiremock();
Expand All @@ -42,6 +43,7 @@ public void initWiremock() {
}

}

@AfterClass
public void close() {
super.close();
Expand Down Expand Up @@ -272,8 +274,8 @@ public void testMarkdownLocalList() throws AppException {
DesiredAPI apiConfig = (DesiredAPI) adapter.getApiConfig();
Assert.assertEquals(apiConfig.getName(), "API with classic markdown local list");
Assert.assertEquals(apiConfig.getDescriptionManual(), "THIS IS THE API-DESCRIPTION FROM A LOCAL MARKDOWN!\n"
+ "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\n"
+ "THIS IS THE SECOND API-DESCRIPTION FROM A LOCAL MARKDOWN!");
+ "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\n"
+ "THIS IS THE SECOND API-DESCRIPTION FROM A LOCAL MARKDOWN!");
}

@Test
Expand Down Expand Up @@ -306,7 +308,7 @@ public void completeCaCertsWithCertChain() throws AppException {
APIImportConfigAdapter adapter = new APIImportConfigAdapter(testConfig, null, "petstore.json", null);
API api = new API();
CaCert caCert = new CaCert();
// caCert.setAlias("CN=test");
// caCert.setAlias("CN=test");
caCert.setInbound("true");
caCert.setOutbound("false");
caCert.setCertFile("certchain.pem");
Expand All @@ -317,4 +319,19 @@ public void completeCaCertsWithCertChain() throws AppException {
Assert.assertEquals(api.getCaCerts().size(), 3);
}

@Test
public void testOutboundBasicAuthEmptyPassword() throws AppException {
// Create Environment properties without any stage (basically loads env.properties)
EnvironmentProperties props = new EnvironmentProperties(null, apimCliHome);
APIImportParams params = new APIImportParams();
params.setProperties(props);
params.setHostname("localhost");
params.setUsername("test");
params.setPassword(Utils.getEncryptedPassword());
String testConfig = this.getClass().getResource("/com/axway/apim/test/files/basic/outbound_basic_auth_empty_password.json").getFile();
APIImportConfigAdapter adapter = new APIImportConfigAdapter(testConfig, null, "notRelavantForThis Test", null);
API apiConfig = adapter.getApiConfig();
Assert.assertEquals("", apiConfig.getAuthenticationProfiles().get(0).getParameters().get("password"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "test",
"path": "/test",
"state": "Published",
"version": "1.0.0",
"organization": "orga",
"authenticationProfiles": [
{
"name": "_default",
"isDefault": true,
"parameters": {
"username": "daskdjaskldjaskljdklasjdl",
"password": ""
},
"type": "http_basic"
}
]
}

0 comments on commit a5e72f1

Please sign in to comment.