PROX-39: added logs (#2)

This commit is contained in:
Anatoly Cherkasov 2016-12-20 13:34:39 +03:00 committed by GitHub
parent a98161cc29
commit a42e285204
3 changed files with 61 additions and 2 deletions

View File

@ -4,9 +4,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.rbkmoney.proxy.test.mpi.model.Card;
import com.rbkmoney.proxy.test.mpi.utils.CardUtils;
import com.rbkmoney.proxy.test.mpi.utils.MpiAction;
import com.rbkmoney.proxy.test.mpi.utils.MpiUtils;
import com.rbkmoney.proxy.test.mpi.utils.constant.MpiCavvAlgorithm;
import com.rbkmoney.proxy.test.mpi.utils.constant.MpiEnrollmentStatus;
import com.rbkmoney.proxy.test.mpi.utils.constant.MpiTransactionStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
@ -25,6 +28,8 @@ import java.util.*;
@RequestMapping(value = "/mpi")
public class ProxyTestMpiController {
private final static Logger LOGGER = LoggerFactory.getLogger(ProxyTestMpiController.class);
public final static String DATETIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
@Value("${fixture.cards}")
@ -46,6 +51,9 @@ public class ProxyTestMpiController {
@RequestParam(value = "year", required = true) String year,
@RequestParam(value = "month", required = true) String month
) throws IOException {
LOGGER.info("VerifyEnrollment input params: pan {}, year {}, month {}",
MpiUtils.maskNumber(pan), year, month
);
CardUtils cardUtils = new CardUtils(cardList);
Optional<Card> card = cardUtils.getCardByPan(pan);
@ -59,7 +67,10 @@ public class ProxyTestMpiController {
map.put("acsUrl", proxyTestMpiCallbackUrl + "/mpi/acs");
}
return new ObjectMapper().writeValueAsString(map);
String response = new ObjectMapper().writeValueAsString(map);
LOGGER.info("VerifyEnrollment response {}", response);
return response;
}
@RequestMapping(value = "validatePaRes", method = RequestMethod.POST)
@ -68,6 +79,8 @@ public class ProxyTestMpiController {
@RequestParam(value = "paRes", required = true) String paRes
) throws IOException {
LOGGER.info("ValidatePaRes input params: pan {}, paRes {}", MpiUtils.maskNumber(pan), paRes);
CardUtils cardUtils = new CardUtils(cardList);
Optional<Card> card = cardUtils.getCardByPan(pan);
Map<String, String> map = new HashMap<>();
@ -93,7 +106,10 @@ public class ProxyTestMpiController {
map.put("transactionStatus", MpiTransactionStatus.AUTHENTICATION_COULD_NOT_BE_PERFORMED);
}
return new ObjectMapper().writeValueAsString(map);
String response = new ObjectMapper().writeValueAsString(map);
LOGGER.info("ValidatePaRes response {}", response);
return response;
}
@RequestMapping(value = "acs", method = RequestMethod.POST)
@ -102,12 +118,15 @@ public class ProxyTestMpiController {
@RequestParam(value = "MD", required = true) String md,
@RequestParam(value = "TermUrl", required = true) String termUrl
) {
LOGGER.info("Form ACS input params: paReq {}, MD {}, TermUrl {}", paReq, md, termUrl);
ModelAndView model = new ModelAndView();
model.setViewName("acs_form");
model.addObject("action", termUrl);
model.addObject("pan", "XXXX XXXX XXXX XXXX");
model.addObject("PaRes", "PaRes");
model.addObject("MD", md);
LOGGER.info("Form ACS show the form");
return model;
}

View File

@ -0,0 +1,24 @@
package com.rbkmoney.proxy.test.mpi.utils;
import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;
public class MpiUtils {
public final static String MASK_CHAR = "*";
public static String maskNumber(final String creditCardNumber, int startLength, int endLength, String maskChar) {
final String cardNumber = creditCardNumber.replaceAll("\\D", "");
final int start = startLength;
final int end = cardNumber.length() - endLength;
final String overlay = StringUtils.repeat(maskChar, end - start);
return StringUtils.overlay(cardNumber, overlay, start, end);
}
public static String maskNumber(final String creditCardNumber) {
return maskNumber(creditCardNumber, 4, 4, MASK_CHAR);
}
}

View File

@ -0,0 +1,16 @@
package com.rbkmoney.proxy.test.mpi.utils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class MpiUtilsTest {
@Test
public void maskNumber() throws Exception {
assertEquals("4242********8989", MpiUtils.maskNumber("4242545467678989"));
assertEquals("4253*********8449", MpiUtils.maskNumber("42535444557678449"));
}
}