Skip to content

Commit

Permalink
Added flag to neuter sensitive information from logging
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnilhande committed Jan 30, 2018
1 parent 20043da commit c838ec2
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 2 deletions.
100 changes: 100 additions & 0 deletions src/functionalTest/java/com/litle/sdk/TestCommunication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.litle.sdk;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.FileInputStream;
import java.util.Properties;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.litle.sdk.Communication;
import com.litle.sdk.Configuration;
import com.litle.sdk.LitleOnline;
import com.litle.sdk.LitleOnlineException;
import com.litle.sdk.generate.ApplepayHeaderType;
import com.litle.sdk.generate.ApplepayType;
import com.litle.sdk.generate.Authorization;
import com.litle.sdk.generate.AuthorizationResponse;
import com.litle.sdk.generate.CardType;
import com.litle.sdk.generate.Contact;
import com.litle.sdk.generate.DetailTax;
import com.litle.sdk.generate.EnhancedData;
import com.litle.sdk.generate.MethodOfPaymentTypeEnum;
import com.litle.sdk.generate.OrderSourceType;
import com.litle.sdk.generate.PayPal;
import com.litle.sdk.generate.Pos;
import com.litle.sdk.generate.PosCapabilityTypeEnum;
import com.litle.sdk.generate.PosCardholderIdTypeEnum;
import com.litle.sdk.generate.PosEntryModeTypeEnum;
import com.litle.sdk.generate.ProcessingTypeEnum;

public class TestCommunication {

private Communication communication;

@Before
public void setup() throws Exception {
communication = new Communication();
}

@Test
public void testNeuterXml() {
String xml = null;
assertNull(communication.neuterXml(xml));

xml = "";
assertEquals("", communication.neuterXml(xml));

xml = "<?xml version=1.0 encoding=UTF-8 standalone=yes?>" +
"<litleOnlineRequest merchantId=123456 merchantSdk=Java;11.3.0 version=11.3 xmlns=http://www.litle.com/schema>" +
"<authentication>" +
"<user>DummyUser</user>" +
"<password>DummyPass</password>" +
"</authentication>" +
"<authorization reportGroup=Planets id=id>" +
"<orderId>12344</orderId>" +
"<amount>106</amount>" +
"<orderSource>ecommerce</orderSource>" +
"<card>" +
"<type>VI</type>" +
"<number>4100000000000000</number>" +
"<track>dummy track data</track>" +
"<expDate>1210</expDate>" +
"</card>" +
"<echeck>" +
"<accType>Checking</accType>" +
"<accNum>1234567890</accNum>" +
"</echeck>" +
"</authorization>" +
"</litleOnlineRequest>";
String neuteredXml = "<?xml version=1.0 encoding=UTF-8 standalone=yes?>" +
"<litleOnlineRequest merchantId=123456 merchantSdk=Java;11.3.0 version=11.3 xmlns=http://www.litle.com/schema>" +
"<authentication>" +
"<user>NEUTERED</user>" +
"<password>NEUTERED</password>" +
"</authentication>" +
"<authorization reportGroup=Planets id=id>" +
"<orderId>12344</orderId>" +
"<amount>106</amount>" +
"<orderSource>ecommerce</orderSource>" +
"<card>" +
"<type>VI</type>" +
"<number>NEUTERED</number>" +
"<track>NEUTERED</track>" +
"<expDate>1210</expDate>" +
"</card>" +
"<echeck>" +
"<accType>Checking</accType>" +
"<accNum>NEUTERED</accNum>" +
"</echeck>" +
"</authorization>" +
"</litleOnlineRequest>";
assertEquals(neuteredXml, communication.neuterXml(xml));
}

}
24 changes: 22 additions & 2 deletions src/main/java/com/litle/sdk/Communication.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
public class Communication {

private static final String[] SUPPORTED_PROTOCOLS = new String[] {"TLSv1.1", "TLSv1.2"};
private static final String NEUTER_STR = "NEUTERED";
private CloseableHttpClient httpClient;
private StreamData streamData;
private final int KEEP_ALIVE_DURATION = 8000;
Expand Down Expand Up @@ -124,9 +125,12 @@ public String requestToServer(String xmlRequest, Properties configuration) {
post.setConfig(requestConfig);
HttpEntity entity = null;
try {
boolean printxml = configuration.getProperty("printxml") != null
&& configuration.getProperty("printxml").equalsIgnoreCase("true");
boolean printxml = "true".equalsIgnoreCase(configuration.getProperty("printxml"));
boolean neuterXml = "true".equalsIgnoreCase(configuration.getProperty("neuterXml"));
if (printxml) {
if (neuterXml) {
xmlRequest = neuterXml(xmlRequest);
}
System.out.println("Request XML: " + xmlRequest);
}
post.setEntity(new StringEntity(xmlRequest,"UTF-8"));
Expand All @@ -140,6 +144,9 @@ public String requestToServer(String xmlRequest, Properties configuration) {
xmlResponse = EntityUtils.toString(entity,"UTF-8");

if (printxml) {
if (neuterXml) {
xmlResponse = neuterXml(xmlResponse);
}
System.out.println("Response XML: " + xmlResponse);
}
} catch (IOException e) {
Expand Down Expand Up @@ -327,4 +334,17 @@ public void receiveLitleRequestResponseFileFromSFTP(File requestFile, File respo
void setStreamData(StreamData streamData) {
this.streamData = streamData;
}

/* Method to neuter out sensitive information from xml */
public String neuterXml(String xml) {
if (xml == null) {
return xml;
}
xml = xml.replaceAll("<accNum>.*</accNum>", "<accNum>" + NEUTER_STR + "</accNum>");
xml = xml.replaceAll("<user>.*</user>", "<user>" + NEUTER_STR + "</user>");
xml = xml.replaceAll("<password>.*</password>", "<password>" + NEUTER_STR + "</password>");
xml = xml.replaceAll("<track>.*</track>", "<track>" + NEUTER_STR + "</track>");
xml = xml.replaceAll("<number>.*</number>", "<number>" + NEUTER_STR + "</number>");
return xml;
}
}

0 comments on commit c838ec2

Please sign in to comment.