Bump java version (#5)

* Bump java version

* Add build_utils

* Fix tests

* Add more lombok anotation

* Return toString in card object

* Update pom.xml

Co-Authored-By: Pavel Popov <tolkonepiu@users.noreply.github.com>

* Add jacoco

* Add registry value

* Add metrics

* Bump shared resources

* Bump base java image

* Add name for metrics
This commit is contained in:
Pavel Popov 2019-06-27 13:29:34 +03:00 committed by GitHub
parent 6a11cb90c5
commit 5268a8d657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 180 additions and 478 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "build_utils"]
path = build_utils
url = git@github.com:rbkmoney/build_utils.git

51
Jenkinsfile vendored
View File

@ -1,47 +1,18 @@
#!groovy
build('googlepay-provider', 'java-maven') {
checkoutRepo()
loadBuildUtils()
def serviceName = env.REPO_NAME
def mvnArgs = '-DjvmArgs="-Xmx256m"'
// Run mvn and generate docker file
runStage('Maven package') {
withCredentials([[$class: 'FileBinding', credentialsId: 'java-maven-settings.xml', variable: 'SETTINGS_XML']]) {
def mvn_command_arguments = ' --batch-mode --settings $SETTINGS_XML -P ci ' +
" -Dgit.branch=${env.BRANCH_NAME} " +
" ${mvnArgs}"
if (env.BRANCH_NAME == 'master') {
sh 'mvn deploy' + mvn_command_arguments
} else {
sh 'mvn package' + mvn_command_arguments
}
def javaServicePipeline
runStage('load JavaService pipeline') {
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy")
}
}
def serviceImage;
def imgShortName = 'rbkmoney/' + "${serviceName}" + ':' + '$COMMIT_ID';
getCommitId()
runStage('Build Service image') {
serviceImage = docker.build(imgShortName, '-f ./target/Dockerfile ./target')
}
def serviceName = env.REPO_NAME
def mvnArgs = '-DjvmArgs="-Xmx256m"'
def useJava11 = true
def registry = 'dr2.rbkmoney.com'
def registryCredsId = 'jenkins_harbor'
try {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic')) {
runStage('Push Service image') {
docker.withRegistry('https://dr.rbkmoney.com/v2/', 'dockerhub-rbkmoneycibot') {
serviceImage.push();
}
// Push under 'withRegistry' generates 2d record with 'long name' in local docker registry.
// Untag the long-name
sh "docker rmi dr.rbkmoney.com/${imgShortName}"
}
}
}
finally {
runStage('Remove local image') {
// Remove the image to keep Jenkins runner clean.
sh "docker rmi ${imgShortName}"
}
}
}
javaServicePipeline(serviceName, useJava11, mvnArgs, registry, registryCredsId)
}

1
build_utils Submodule

@ -0,0 +1 @@
Subproject commit ea4aa042f482551d624fd49a570d28488f479e93

40
pom.xml
View File

@ -7,21 +7,24 @@
<parent>
<groupId>com.rbkmoney</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<version>2.1.1.RELEASE</version>
</parent>
<groupId>com.rbkmoney.provider</groupId>
<artifactId>googlepay</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.1.5-SNAPSHOT</version>
<name>provider-googlepay</name>
<properties>
<project.maintainer>Vladimir Pankrashkin &lt;v.pankrashkin@rbkmoney.com&gt;</project.maintainer>
<project.maintainer>Pavel Popov &lt;p.popov@rbkmoney.com&gt;</project.maintainer>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dockerfile.base.service.tag>22c57470c4fc47161894f036b7cf9d70f42b75f5</dockerfile.base.service.tag>
<dockerfile.base.service.tag>c0d0900ec19c907d866f8360031a836049985110</dockerfile.base.service.tag>
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
<damsel.version>1.236-1510cd7</damsel.version>
<shared.resources.version>0.3.2</shared.resources.version>
<shared.resources.version>0.3.6</shared.resources.version>
<server.port>8022</server.port>
<exposed.ports>${server.port}</exposed.ports>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
<dependencies>
@ -51,6 +54,11 @@
<artifactId>shared-resources</artifactId>
<version>${shared.resources.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>spring-boot-starter-metrics-statsd</artifactId>
<version>1.1.0</version>
</dependency>
<!--Thridparty libs-->
<dependency>
<groupId>com.google.crypto.tink</groupId>
@ -95,6 +103,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
<!--Test libs-->
<dependency>
@ -184,6 +197,23 @@
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -4,14 +4,10 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
/**
* Created by vpankrashkin on 29.05.18.
*/
@SpringBootApplication(scanBasePackages = "com.rbkmoney.provider.googlepay")
@ServletComponentScan
public class Application {
@SpringBootApplication(scanBasePackages = "com.rbkmoney.provider.googlepay")
public class GooglePayApplication {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(GooglePayApplication.class, args);
}
}

View File

@ -2,16 +2,12 @@ package com.rbkmoney.provider.googlepay.config;
import com.google.crypto.tink.apps.paymentmethodtoken.GooglePaymentsPublicKeysManager;
import com.google.crypto.tink.apps.paymentmethodtoken.PaymentMethodTokenRecipient;
import com.rbkmoney.damsel.base.InvalidRequest;
import com.rbkmoney.damsel.payment_tool_provider.PaymentToolProviderSrv;
import com.rbkmoney.damsel.payment_tool_provider.UnwrappedPaymentTool;
import com.rbkmoney.damsel.payment_tool_provider.WrappedPaymentTool;
import com.rbkmoney.provider.googlepay.iface.decrypt.HandlerSelector;
import com.rbkmoney.provider.googlepay.iface.decrypt.ProviderHandler;
import com.rbkmoney.provider.googlepay.service.DecryptionService;
import com.rbkmoney.provider.googlepay.service.GPKeyStore;
import com.rbkmoney.provider.googlepay.service.ValidationService;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@ -21,31 +17,28 @@ import org.springframework.core.io.Resource;
import java.io.IOException;
import java.security.GeneralSecurityException;
/**
* Created by vpankrashkin on 29.05.18.
*/
@Configuration
public class AppConfig {
@Bean
public DecryptionService testDecryptionService(@Value("${google.gateway_id}") String gatewayId, @Value("${google.test_keys_path}")Resource keys) throws GeneralSecurityException, IOException {
public DecryptionService testDecryptionService(@Value("${google.gateway_id}") String gatewayId, @Value("${google.test_keys_path}") Resource keys) throws GeneralSecurityException, IOException {
PaymentMethodTokenRecipient.Builder builder = new PaymentMethodTokenRecipient.Builder();
builder.fetchSenderVerifyingKeysWith(GooglePaymentsPublicKeysManager.INSTANCE_TEST)
.recipientId("gateway:"+gatewayId);
for (String key: new GPKeyStore(keys.getURI()).getKeys()) {
.recipientId("gateway:" + gatewayId);
for (String key : new GPKeyStore(keys.getURI()).getKeys()) {
builder.addRecipientPrivateKey(key);
}
return new DecryptionService(builder.build());
}
@Bean
public DecryptionService prodDecryptionService(@Value("${google.gateway_id}") String gatewayId, @Value("${google.prod_keys_path}")Resource keys) throws GeneralSecurityException, IOException {
public DecryptionService prodDecryptionService(@Value("${google.gateway_id}") String gatewayId, @Value("${google.prod_keys_path}") Resource keys) throws GeneralSecurityException, IOException {
PaymentMethodTokenRecipient.Builder builder = new PaymentMethodTokenRecipient.Builder();
builder.fetchSenderVerifyingKeysWith(GooglePaymentsPublicKeysManager.INSTANCE_PRODUCTION)
.recipientId("gateway:"+gatewayId);
for (String key: new GPKeyStore(keys.getURI()).getKeys()) {
.recipientId("gateway:" + gatewayId);
for (String key : new GPKeyStore(keys.getURI()).getKeys()) {
builder.addRecipientPrivateKey(key);
}
return new DecryptionService(builder.build());

View File

@ -1,8 +1,4 @@
package com.rbkmoney.provider.googlepay.domain;
/**
* Created by vpankrashkin on 28.05.18.
*/
public class Auth {
}

View File

@ -3,12 +3,16 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@NoArgsConstructor
@ToString(exclude = "cryptogram")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Auth3DS extends Auth {
private String cryptogram;
private String eci;
@ -20,30 +24,4 @@ public class Auth3DS extends Auth {
this.eci = eci;
}
public Auth3DS() {
}
public String getCryptogram() {
return cryptogram;
}
public void setCryptogram(String cryptogram) {
this.cryptogram = cryptogram;
}
public String getEci() {
return eci;
}
public void setEci(String eci) {
this.eci = eci;
}
@Override
public String toString() {
return "Auth3DS{" +
"cryptogram='" + (cryptogram == null ? null : "***") + '\'' +
", eci='" + eci + '\'' +
"}";
}
}

View File

@ -2,11 +2,15 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@Setter
@NoArgsConstructor
public class Card extends PaymentCredential {
private String pan;
private int expirationMonth;
private int expirationYear;
@ -21,39 +25,13 @@ public class Card extends PaymentCredential {
this.expirationYear = expirationYear;
}
public Card() {
}
public String getPan() {
return pan;
}
public void setPan(String pan) {
this.pan = pan;
}
public int getExpirationMonth() {
return expirationMonth;
}
public void setExpirationMonth(int expirationMonth) {
this.expirationMonth = expirationMonth;
}
public int getExpirationYear() {
return expirationYear;
}
public void setExpirationYear(int expirationYear) {
this.expirationYear = expirationYear;
}
@Override
public String toString() {
return "Card{" +
"pan='" + (pan == null ? null: "***") + '\'' +
"pan='" + (pan == null ? null : "***") + '\'' +
", expirationMonth=" + "**" +
", expirationYear=" + "****" +
'}';
}
}

View File

@ -3,12 +3,16 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@ToString
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class CardInfo {
private String cardDescription;
private String cardClass;
private String last4digits;
@ -19,55 +23,11 @@ public class CardInfo {
@JsonProperty(value = "cardDescription", required = true) String cardDescription,
@JsonProperty(value = "cardClass", required = true) String cardClass,
@JsonProperty(value = "cardDetails", required = true) String last4digits,
@JsonProperty(value = "cardNetwork", required = true) String cardNetwork) {
@JsonProperty(value = "cardNetwork", required = true) String cardNetwork) {
this.cardDescription = cardDescription;
this.cardClass = cardClass;
this.last4digits = last4digits;
this.cardNetwork = cardNetwork;
}
public CardInfo() {
}
public String getCardDescription() {
return cardDescription;
}
public void setCardDescription(String cardDescription) {
this.cardDescription = cardDescription;
}
public String getCardNetwork() {
return cardNetwork;
}
public void setCardNetwork(String cardNetwork) {
this.cardNetwork = cardNetwork;
}
public String getCardClass() {
return cardClass;
}
public void setCardClass(String cardClass) {
this.cardClass = cardClass;
}
public String getLast4digits() {
return last4digits;
}
public void setLast4digits(String last4digits) {
this.last4digits = last4digits;
}
@Override
public String toString() {
return "CardInfo{" +
"cardDescription='" + cardDescription + '\'' +
", cardClass='" + cardClass + '\'' +
", last4digits='" + last4digits + '\'' +
", cardNetwork='" + cardNetwork + '\'' +
'}';
}
}

View File

@ -4,15 +4,21 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.rbkmoney.provider.googlepay.service.DecryptedMessageDeserializer;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.time.Instant;
import java.util.Map;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@JsonDeserialize(using = DecryptedMessageDeserializer.class)
public class DecryptedMessage {
private Instant expiration;
private String messageId;
private String gatewayMerchantId;
@ -20,10 +26,6 @@ public class DecryptedMessage {
private PaymentCredential paymentCredential;
private Map<String, Object> paymentCredentialMap;
public DecryptedMessage() {
}
@JsonCreator
public DecryptedMessage(
@JsonProperty(value = "messageExpiration", required = true) Instant expiration,
@ -38,63 +40,4 @@ public class DecryptedMessage {
this.paymentCredentialMap = paymentCredentialMap;
}
public Instant getExpiration() {
return expiration;
}
public void setExpiration(Instant expiration) {
this.expiration = expiration;
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public String getGatewayMerchantId() {
return gatewayMerchantId;
}
public void setGatewayMerchantId(String gatewayMerchantId) {
this.gatewayMerchantId = gatewayMerchantId;
}
public PaymentMethod getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(PaymentMethod paymentMethod) {
this.paymentMethod = paymentMethod;
}
public PaymentCredential getPaymentCredential() {
return paymentCredential;
}
public void setPaymentCredential(PaymentCredential paymentCredential) {
this.paymentCredential = paymentCredential;
}
public Map<String, Object> getPaymentCredentialMap() {
return paymentCredentialMap;
}
public void setPaymentCredentialMap(Map<String, Object> paymentCredentialMap) {
this.paymentCredentialMap = paymentCredentialMap;
}
@Override
public String toString() {
return "DecryptedMessage{" +
"expiration=" + expiration +
", messageId='" + messageId + '\'' +
", gatewayMerchantId='" + gatewayMerchantId + '\'' +
", paymentMethod=" + paymentMethod +
", paymentCredential=" + paymentCredential +
", paymentCredentialMap=" + paymentCredentialMap.size() +
'}';
}
}

View File

@ -1,8 +1,4 @@
package com.rbkmoney.provider.googlepay.domain;
/**
* Created by vpankrashkin on 28.05.18.
*/
public class PaymentCredential {
}

View File

@ -3,12 +3,16 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@ToString
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class PaymentData {
private CardInfo cardInfo;
private PaymentToken paymentMethodToken;
@ -20,30 +24,4 @@ public class PaymentData {
this.cardInfo = cardInfo;
}
public PaymentData() {
}
public PaymentToken getPaymentMethodToken() {
return paymentMethodToken;
}
public void setPaymentMethodToken(PaymentToken paymentMethodToken) {
this.paymentMethodToken = paymentMethodToken;
}
public CardInfo getCardInfo() {
return cardInfo;
}
public void setCardInfo(CardInfo cardInfo) {
this.cardInfo = cardInfo;
}
@Override
public String toString() {
return "PaymentData{" +
"cardInfo=" + cardInfo +
", paymentMethodToken=" + paymentMethodToken +
'}';
}
}

View File

@ -2,9 +2,6 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by vpankrashkin on 28.05.18.
*/
public enum PaymentMethod {
@JsonProperty("TOKENIZED_CARD")
TOKENIZED,

View File

@ -2,11 +2,15 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@ToString
@NoArgsConstructor
public class PaymentToken {
private String token;
private TokenizationType tokenizationType;
@ -18,30 +22,4 @@ public class PaymentToken {
this.token = token;
}
public PaymentToken() {
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public TokenizationType getTokenizationType() {
return tokenizationType;
}
public void setTokenizationType(TokenizationType tokenizationType) {
this.tokenizationType = tokenizationType;
}
@Override
public String toString() {
return "PaymentToken{" +
"token='" + token + '\'' +
", tokenizationType=" + tokenizationType +
'}';
}
}

View File

@ -2,9 +2,6 @@ package com.rbkmoney.provider.googlepay.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by vpankrashkin on 28.05.18.
*/
public enum TokenizationType {
@JsonProperty("PAYMENT_GATEWAY")
GATEWAY,

View File

@ -5,13 +5,19 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.rbkmoney.provider.googlepay.service.TokenizedCardDeserializer;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
* Created by vpankrashkin on 28.05.18.
*/
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(using = TokenizedCardDeserializer.class)
@ToString(exclude = {"dpan", "expirationMonth", "expirationYear"})
public class TokenizedCard extends PaymentCredential {
private String dpan;
private int expirationMonth;
private int expirationYear;
@ -30,57 +36,4 @@ public class TokenizedCard extends PaymentCredential {
this.authType = authType;
}
public TokenizedCard() {
}
public String getDpan() {
return dpan;
}
public void setDpan(String dpan) {
this.dpan = dpan;
}
public int getExpirationMonth() {
return expirationMonth;
}
public void setExpirationMonth(int expirationMonth) {
this.expirationMonth = expirationMonth;
}
public int getExpirationYear() {
return expirationYear;
}
public void setExpirationYear(int expirationYear) {
this.expirationYear = expirationYear;
}
public AuthType getAuthType() {
return authType;
}
public void setAuthType(AuthType authType) {
this.authType = authType;
}
public Auth getAuth() {
return auth;
}
public void setAuth(Auth auth) {
this.auth = auth;
}
@Override
public String toString() {
return "TokenizedCard{" +
"dpan='" + (dpan == null ? null : "***") + '\'' +
", expirationMonth=" + "**" +
", expirationYear=" + "****" +
", authType=" + authType +
", auth=" + auth +
"} ";
}
}

View File

@ -3,18 +3,14 @@ package com.rbkmoney.provider.googlepay.iface.decrypt;
import com.rbkmoney.damsel.base.Content;
import com.rbkmoney.damsel.base.InvalidRequest;
import com.rbkmoney.damsel.payment_tool_provider.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.regex.Pattern;
/**
* Created by vpankrashkin on 18.06.18.
*/
@Slf4j
public class HandlerSelector implements PaymentToolProviderSrv.Iface {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final PaymentToolProviderSrv.Iface test;
private final PaymentToolProviderSrv.Iface prod;

View File

@ -14,19 +14,17 @@ import com.rbkmoney.provider.googlepay.service.CryptoException;
import com.rbkmoney.provider.googlepay.service.DecryptionService;
import com.rbkmoney.provider.googlepay.service.ValidationException;
import com.rbkmoney.provider.googlepay.service.ValidationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;
/**
* Created by vpankrashkin on 03.04.18.
*/
@Slf4j
@RequiredArgsConstructor
public class ProviderHandler implements PaymentToolProviderSrv.Iface {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final ValidationService validator;
private final DecryptionService decryptor;
@ -34,12 +32,6 @@ public class ProviderHandler implements PaymentToolProviderSrv.Iface {
private final ObjectReader resReader = new ObjectMapper().readerFor(DecryptedMessage.class);
private final boolean enableValidation;
public ProviderHandler(ValidationService validator, DecryptionService decryptor, boolean enableValidation) {
this.validator = validator;
this.decryptor = decryptor;
this.enableValidation = enableValidation;
}
@Override
public UnwrappedPaymentTool unwrap(WrappedPaymentTool payment_tool) throws InvalidRequest, TException {
Content content = payment_tool.getRequest().getGoogle().getPaymentToken();

View File

@ -9,9 +9,6 @@ import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
/**
* Created by vpankrashkin on 29.05.18.
*/
@WebServlet("/provider/google")
public class ProviderServlet extends GenericServlet {
private final Servlet handlerServlet;

View File

@ -1,8 +1,5 @@
package com.rbkmoney.provider.googlepay.service;
/**
* Created by vpankrashkin on 12.04.18.
*/
public class CryptoException extends Exception {
public CryptoException() {
}

View File

@ -16,9 +16,6 @@ import com.rbkmoney.provider.googlepay.domain.TokenizedCard;
import java.io.IOException;
/**
* Created by vpankrashkin on 28.05.18.
*/
public class DecryptedMessageDeserializer extends StdDeserializer<DecryptedMessage> {
private final ObjectMapper mapper;

View File

@ -1,24 +1,20 @@
package com.rbkmoney.provider.googlepay.service;
import com.google.crypto.tink.apps.paymentmethodtoken.PaymentMethodTokenRecipient;
import lombok.RequiredArgsConstructor;
import java.security.GeneralSecurityException;
/**
* Created by vpankrashkin on 29.05.18.
*/
@RequiredArgsConstructor
public class DecryptionService {
private final PaymentMethodTokenRecipient decryptor;
public DecryptionService(PaymentMethodTokenRecipient decryptor) {
this.decryptor = decryptor;
}
private final PaymentMethodTokenRecipient decryptor;
public String decryptToken(String paymentToken) throws CryptoException {
try {
return decryptor.unseal(paymentToken);
} catch (GeneralSecurityException | IllegalArgumentException e) {
throw new CryptoException("Message decryption failed: "+e.getMessage(), e);
throw new CryptoException("Message decryption failed: " + e.getMessage(), e);
}
}
}

View File

@ -1,20 +1,17 @@
package com.rbkmoney.provider.googlepay.service;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
/**
* Created by vpankrashkin on 29.05.18.
*/
@RequiredArgsConstructor
public class GPKeyStore {
private final URI path;
public GPKeyStore(URI path) {
this.path = path;
}
private final URI path;
public List<String> getKeys() throws IOException {
return Files.readAllLines(Paths.get(path));

View File

@ -13,9 +13,6 @@ import com.rbkmoney.provider.googlepay.domain.TokenizedCard;
import java.io.IOException;
/**
* Created by vpankrashkin on 28.05.18.
*/
public class TokenizedCardDeserializer extends JsonDeserializer<TokenizedCard> {
private final ObjectMapper mapper;

View File

@ -1,8 +1,5 @@
package com.rbkmoney.provider.googlepay.service;
/**
* Created by vpankrashkin on 28.05.18.
*/
public class ValidationException extends RuntimeException {
public ValidationException() {
}

View File

@ -4,9 +4,6 @@ import com.rbkmoney.provider.googlepay.domain.DecryptedMessage;
import java.time.Instant;
/**
* Created by vpankrashkin on 29.05.18.
*/
public class ValidationService {
public void validate(String gMerchantId, DecryptedMessage message) throws ValidationException {
if (!gMerchantId.equals(message.getGatewayMerchantId())) {
@ -14,7 +11,7 @@ public class ValidationService {
}
if (Instant.now().isAfter(message.getExpiration())) {
throw new ValidationException("Message expired: "+message.getExpiration());
throw new ValidationException("Message expired: " + message.getExpiration());
}
}
}

View File

@ -10,3 +10,5 @@ google.prod_keys_path=classpath:test_keys.txt
google.test_merchant_id_pattern=^[Tt][Ee][Ss][Tt].*$
google.use_validation=true
management.metrics.export.statsd.flavor=etsy
management.metrics.export.statsd.enabled=false

View File

@ -11,9 +11,6 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
/**
* Created by vpankrashkin on 25.05.18.Ø
*/
public class DataTest {
static {

View File

@ -2,9 +2,7 @@ package com.rbkmoney.provider.googlepay;
import com.rbkmoney.damsel.base.Content;
import com.rbkmoney.damsel.base.InvalidRequest;
import com.rbkmoney.damsel.domain.BankCardPaymentSystem;
import com.rbkmoney.damsel.payment_tool_provider.*;
import com.rbkmoney.woody.api.flow.error.WRuntimeException;
import com.rbkmoney.woody.thrift.impl.http.THClientBuilder;
import org.apache.thrift.TException;
import org.junit.Before;
@ -17,61 +15,57 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.time.Instant;
import static org.junit.Assert.*;
import static org.junit.Assert.fail;
/**
* Created by vpankrashkin on 29.05.18.
*/
@RunWith(SpringRunner.class)
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT
)
public class IntegrationTest {
@Value("http://127.0.0.1:${server.port}/provider/google")
private String url;
@Value("http://127.0.0.1:${server.port}/provider/google")
private String url;
private PaymentToolProviderSrv.Iface client;
private PaymentToolProviderSrv.Iface client;
private String encMsg = "{\n" +
" \"cardInfo\": {\n" +
" \"cardNetwork\": \"VISA\",\n" +
" \"cardDetails\": \"9391\",\n" +
" \"cardImageUri\": \"https://lh6.ggpht.com/NvYf_33MleY1waJfW6O98wb3KU6XeinwiahmvUIyu46LcWeQdTMGm7WYe81uZYWLUbkjvz0E\",\n" +
" \"cardDescription\": \"Visa••••9391\",\n" +
" \"cardClass\": \"CREDIT\"\n" +
" },\n" +
" \"paymentMethodToken\": {\n" +
" \"tokenizationType\": \"PAYMENT_GATEWAY\",\n" +
" \"token\": \"{\\\"signature\\\":\\\"MEUCIQCBj5ClFzpJTg3UB4yKdXRP5O12vqpcTCM+x51/99ugYAIgPnCmr8k2G4oKWQqxmAawPgTd42vX1rx91eyqIHgSju4\\\\u003d\\\",\\\"protocolVersion\\\":\\\"ECv1\\\",\\\"signedMessage\\\":\\\"{\\\\\\\"encryptedMessage\\\\\\\":\\\\\\\"tSj1k3qfKoVg5rcZg8uOzMaGrk31qTIUkjYehgjV7BVAC/SGVfPE40q9PHppoZJqFsRwM1xMKKpoZatHa/fct/2YlVwxySxNR5uu3PHR4ZzuWb7vh/Nnb8BWlSiUMMELLaHFA1+FR2zbLpgEG9QdmeQRpyq07SETaH43WF0MLTDbKr9Con3SLZVCnoNS6CZZsPVTYNm0IjLWABAf66O5VlMWAPwke+kMaiJmq5ttPaxn6zGVJq4/JT7T7iKuc/T0rWDh7BzzVEzi/wyvaYDl2SkOljqFcjNYMTEr76GHlsgpAjtzCCPJkPJ9m7wkd3v+mgdQgazJ+ZwFvKTk8Ru7wZ4eywgb1G36/+IBpH/7936PvkayOTuXgtQkjts027mnH9/SyRA3unoJrNXRpUPytxwVO048edVUBKB9Q4ZZYadeGErH4xRTg64fPS9KiHSswBeY\\\\\\\",\\\\\\\"ephemeralPublicKey\\\\\\\":\\\\\\\"BLeiRaJ1+9DkK9x8rPK1377KKgQVv3kSbomJZxoTgqaOugBa8PAR3QDIH3VfqscW8zfMbrNrA736Nm4AahbogaU\\\\\\\\u003d\\\\\\\",\\\\\\\"tag\\\\\\\":\\\\\\\"oBPVR6dw8t4GM0ZC3QLd45hcx6oeag5D98BSdIsV0No\\\\\\\\u003d\\\\\\\"}\\\"}\"\n" +
" },\n" +
" \"email\": \"keinasylum@gmail.com\"\n" +
"}";
private String encMsg = "{\n" +
" \"cardInfo\": {\n" +
" \"cardNetwork\": \"VISA\",\n" +
" \"cardDetails\": \"9391\",\n" +
" \"cardImageUri\": \"https://lh6.ggpht.com/NvYf_33MleY1waJfW6O98wb3KU6XeinwiahmvUIyu46LcWeQdTMGm7WYe81uZYWLUbkjvz0E\",\n" +
" \"cardDescription\": \"Visa••••9391\",\n" +
" \"cardClass\": \"CREDIT\"\n" +
" },\n" +
" \"paymentMethodToken\": {\n" +
" \"tokenizationType\": \"PAYMENT_GATEWAY\",\n" +
" \"token\": \"{\\\"signature\\\":\\\"MEUCIQCBj5ClFzpJTg3UB4yKdXRP5O12vqpcTCM+x51/99ugYAIgPnCmr8k2G4oKWQqxmAawPgTd42vX1rx91eyqIHgSju4\\\\u003d\\\",\\\"protocolVersion\\\":\\\"ECv1\\\",\\\"signedMessage\\\":\\\"{\\\\\\\"encryptedMessage\\\\\\\":\\\\\\\"tSj1k3qfKoVg5rcZg8uOzMaGrk31qTIUkjYehgjV7BVAC/SGVfPE40q9PHppoZJqFsRwM1xMKKpoZatHa/fct/2YlVwxySxNR5uu3PHR4ZzuWb7vh/Nnb8BWlSiUMMELLaHFA1+FR2zbLpgEG9QdmeQRpyq07SETaH43WF0MLTDbKr9Con3SLZVCnoNS6CZZsPVTYNm0IjLWABAf66O5VlMWAPwke+kMaiJmq5ttPaxn6zGVJq4/JT7T7iKuc/T0rWDh7BzzVEzi/wyvaYDl2SkOljqFcjNYMTEr76GHlsgpAjtzCCPJkPJ9m7wkd3v+mgdQgazJ+ZwFvKTk8Ru7wZ4eywgb1G36/+IBpH/7936PvkayOTuXgtQkjts027mnH9/SyRA3unoJrNXRpUPytxwVO048edVUBKB9Q4ZZYadeGErH4xRTg64fPS9KiHSswBeY\\\\\\\",\\\\\\\"ephemeralPublicKey\\\\\\\":\\\\\\\"BLeiRaJ1+9DkK9x8rPK1377KKgQVv3kSbomJZxoTgqaOugBa8PAR3QDIH3VfqscW8zfMbrNrA736Nm4AahbogaU\\\\\\\\u003d\\\\\\\",\\\\\\\"tag\\\\\\\":\\\\\\\"oBPVR6dw8t4GM0ZC3QLd45hcx6oeag5D98BSdIsV0No\\\\\\\\u003d\\\\\\\"}\\\"}\"\n" +
" },\n" +
" \"email\": \"keinasylum@gmail.com\"\n" +
"}";
private String encMechId = "rbkmoney";
private String encMechId = "rbkmoney";
@Before
public void setUp() throws URISyntaxException {
client = new THClientBuilder().withAddress(new URI(url)).build(PaymentToolProviderSrv.Iface.class);
}
@Test
public void testCard() throws TException {
UnwrappedPaymentTool res = null;
try {
res = client.unwrap(new WrappedPaymentTool(PaymentRequest.google(new GooglePayRequest("test" + encMechId, toContent(encMsg)))));
} catch (InvalidRequest e) {
if (!e.getErrors().get(0).contains("expired payload"))
fail("Token must be expired");
@Before
public void setUp() throws URISyntaxException {
client = new THClientBuilder().withAddress(new URI(url)).build(PaymentToolProviderSrv.Iface.class);
}
@Test
public void testCard() throws TException {
UnwrappedPaymentTool res = null;
try {
res = client.unwrap(new WrappedPaymentTool(PaymentRequest.google(new GooglePayRequest("test"+encMechId, toContent(encMsg)))));
} catch (InvalidRequest e) {
if (!e.getErrors().get(0).contains("expired payload"))
fail("Token must be expired");
}
try {
res = client.unwrap(new WrappedPaymentTool(PaymentRequest.google(new GooglePayRequest(encMechId, toContent(encMsg)))));
} catch (InvalidRequest e) {
if (!e.getErrors().get(0).contains("cannot verify signature"))
fail("Merchant id must be identified as prod, sign verification fail expected");
}
try {
res = client.unwrap(new WrappedPaymentTool(PaymentRequest.google(new GooglePayRequest(encMechId, toContent(encMsg)))));
} catch (InvalidRequest e) {
if (!e.getErrors().get(0).contains("cannot verify signature"))
fail("Merchant id must be identified as prod, sign verification fail expected");
}
/* assertEquals("4111111111111111", res.getPaymentData().getCard().getPan());
assertEquals(new ExpDate((byte) 12, (short) 2023), res.getPaymentData().getCard().getExpDate());
@ -82,19 +76,17 @@ public class IntegrationTest {
assertEquals("2018-06-05T12:36:44.549Z", res.getDetails().getGoogle().getMessageExpiration());
assertEquals("AH2EjtfIuPojiNSCv4SarecQOmML6hX1x-0yOZImfiPubV_vd6vVc0vScpQV0ExK1eJ2C9_D1KSeg4T45QyurCF6wTCJMoIgJR4zYcak0cAZ6XXOUk_hs72b45NLHbHEvAziG7ZJmLhv", res.getDetails().getGoogle().getMessageId());
*/}
@Test(expected = InvalidRequest.class)
public void testWrongMerchantId() throws TException {
client.unwrap(new WrappedPaymentTool(PaymentRequest.google(new GooglePayRequest(encMechId+"1", toContent(encMsg)))));
}
private Content toContent(String data) {
return new Content("application/json", ByteBuffer.wrap(data.getBytes()));
}
*/
}
@Test(expected = InvalidRequest.class)
public void testWrongMerchantId() throws TException {
client.unwrap(new WrappedPaymentTool(PaymentRequest.google(new GooglePayRequest(encMechId + "1", toContent(encMsg)))));
}
private Content toContent(String data) {
return new Content("application/json", ByteBuffer.wrap(data.getBytes()));
}
}