Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator with logging and masking #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generator/cybersource-php-template/ApiClient.mustache
Original file line number Diff line number Diff line change
@@ -235,7 +235,7 @@ class ApiClient

// debugging for curl
if ($this->config->getDebug()) {
//$postData = $this->dataMasking($postData);
$postData = $this->dataMasking($postData);
error_log("[DEBUG] HTTP Request body ~BEGIN~".PHP_EOL.print_r($postData, true).PHP_EOL."~END~".PHP_EOL, 3, $this->config->getDebugFile());

curl_setopt($curl, CURLOPT_VERBOSE, 1);
@@ -252,7 +252,7 @@ class ApiClient
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = $this->httpParseHeaders(substr($response, 0, $http_header_size));
$http_body = substr($response, $http_header_size);
//$http_body = $this->dataMasking($http_body);
$http_body = $this->dataMasking($http_body);
$response_info = curl_getinfo($curl);

// debug HTTP response body
67 changes: 56 additions & 11 deletions lib/ApiClient.php
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@
use CyberSource\Authentication\Core\Authentication as Authentication;
use CyberSource\Authentication\Util\GlobalParameter as GlobalParameter;
use CyberSource\Authentication\PayloadDigest\PayloadDigest as PayloadDigest;

/**
* ApiClient Class Doc Comment
*
@@ -147,12 +146,12 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
(array)$this->config->getDefaultHeaders(),
(array)$headerParams
);

if (!empty($queryParams)) {
if (!empty($queryParams)) {
$resourcePath = ($resourcePath . '?' . http_build_query($queryParams));
$queryParams=null;
}

foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
@@ -163,10 +162,13 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
} elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers, true)) { // json model
$postData = json_encode(\CyberSource\ObjectSerializer::sanitizeForSerialization($postData));
}
$resourcePath= utf8_encode($resourcePath);
$authHeader = $this->callAuthenticationHeader($method, $postData, $resourcePath);
$resourcePath= utf8_encode($resourcePath);
$authHeader = $this->callAuthenticationHeader($method, $postData, $resourcePath);
$headers = array_merge($headers, $authHeader);
print_r($headers);
foreach ($headers as $value) {
$splitArr= explode(":", $value, 2);
$this->config->addRequestHeader($splitArr[0], $splitArr[1]);
}
$url = GlobalParameter::HTTPS_PREFIX.$this->config->getHost() . $resourcePath;

$curl = curl_init();
@@ -183,6 +185,7 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

// disable SSL verification, if needed
if ($this->config->getSSLVerification() === false) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
@@ -210,7 +213,7 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
if (!empty($queryParams)) {
$url = ($url . '?' . http_build_query($queryParams));
}

if ($this->config->getAllowEncoding()) {
curl_setopt($curl, CURLOPT_ENCODING, '');
}
@@ -242,6 +245,8 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header

// debugging for curl
if ($this->config->getDebug()) {
//Added Infy for masking request
$postData = $this->dataMasking($postData);
error_log("[DEBUG] HTTP Request body ~BEGIN~".PHP_EOL.print_r($postData, true).PHP_EOL."~END~".PHP_EOL, 3, $this->config->getDebugFile());

curl_setopt($curl, CURLOPT_VERBOSE, 1);
@@ -258,6 +263,8 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = $this->httpParseHeaders(substr($response, 0, $http_header_size));
$http_body = substr($response, $http_header_size);
//Added Infy for masking response
$http_body = $this->dataMasking($http_body);
$response_info = curl_getinfo($curl);

// debug HTTP response body
@@ -383,12 +390,11 @@ protected function httpParseHeaders($raw_headers)

/*
* Purpose : This function calling the Authentication and making an Auth Header
*
* Added infy Authentication SDK
*/
public function callAuthenticationHeader($method, $postData, $resourcePath)
{
require_once 'Resources/ExternalConfiguration.php';

require_once './Resources/ExternalConfiguration.php';
$ExternalConfigurationObj = new ExternalConfiguration();
$merchantConfig = $ExternalConfigurationObj->merchantConfigObject();
$authentication = new Authentication();
@@ -420,5 +426,44 @@ public function callAuthenticationHeader($method, $postData, $resourcePath)
}
return $headers;

}
//set Fields to be mask
//Added infy for masking
public function dataMasking($postData_json_raw)
{
$toBeMask = array("email"=>"XXXXX","firstName"=>"XXXXX","lastName"=>"XXXXX","phoneNumber"=>"XXXXX","type"=>"XXXXX","securityCode"=>"XXXXX");

$postData_json = json_decode($postData_json_raw, JSON_UNESCAPED_SLASHES);
if($postData_json == null){
return $postData_json_raw;
}else {
$postData_json = $this->dataMaskingIterate($postData_json, $toBeMask);
return json_encode($postData_json);

}

}

//Data masking iteration
//Added infy for masking
public function dataMaskingIterate($responceArr, $callback)
{
if(!empty($responceArr)){
foreach ($responceArr as $k => $v)
{
if(is_array($v)) {
$responceArr[$k] = $this->dataMaskingIterate($v, $callback);
}
else
{
if(array_key_exists($k, $callback))
{
$responceArr[$k]="XXXXXX";
}
}
}
}
return $responceArr;

}
}
3 changes: 2 additions & 1 deletion lib/Authentication/Log/Logger.php
Original file line number Diff line number Diff line change
@@ -42,8 +42,9 @@ private function rotateLogFile($path, $fileName, $logSize) {
if($fileMemory >= $logSize){
$updateOldFile = $path."Cybs_".date("YmdHis").".log";
rename($filePath, $updateOldFile);
fopen($filePath, "w");
}
fopen($filePath, "w");


}
}
52 changes: 50 additions & 2 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
@@ -82,6 +82,13 @@ class Configuration
* @var array
*/
protected $defaultHeaders = [];

/**
* The default header(s)
*
* @var array
*/
protected $requestHeaders = [];

/**
* The host
@@ -341,8 +348,7 @@ public function getDefaultHeaders()
{
return $this->defaultHeaders;
}

/**
/**
* Deletes a default header
*
* @param string $headerName the header to delete
@@ -354,6 +360,48 @@ public function deleteDefaultHeader($headerName)
unset($this->defaultHeaders[$headerName]);
return $this;
}

/**
* Adds a request header
*
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
*
* @throws \InvalidArgumentException
* @return $this
*/
public function addRequestHeader($headerName, $headerValue)
{
if (!is_string($headerName)) {
throw new \InvalidArgumentException('Header name must be a string.');
}

$this->requestHeaders[$headerName] = $headerValue;
return $this;
}

/**
* Gets the request header
*
* @return array An array of request header(s)
*/
public function getRequestHeaders()
{
return $this->requestHeaders;
}

/**
* Deletes a request header
*
* @param string $headerName the header to delete
*
* @return $this
*/
public function deleteRequestHeader($headerName)
{
unset($this->requestHeaders[$headerName]);
return $this;
}

/**
* Sets the host
43 changes: 43 additions & 0 deletions test/SamplesQA/CSV_Files/Driver/driver.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
dirName,fileName,Flag
Flex/CoreServices,GenerateKey,0
Flex/CoreServices,TokenizeCard,0
Payouts/CoreServices,ProcessPayout,0
TMS/CoreServices,CreateInstrumentIdentifier,0
TMS/CoreServices,CreatePaymentInstrument,0
TMS/CoreServices,RetrieveAllPaymentInstruments,0
TMS/CoreServices,RetrieveInstrumentIdentifier,0
TMS/CoreServices,RetrievePaymentInstrument,0
TMS/CoreServices,UpdateInstrumentIdentifier,0
TMS/CoreServices,UpdatePaymentInstrument,0
TMS/CoreServices,DeleteInstrumentIdentifier,0
TMS/CoreServices,DeletePaymentInstrument,0
Payments/CoreServices,ProcessPayment,0
Payments/CoreServices,CapturePayment,0
Payments/CoreServices,ProcessAuthorizationReversal,0
Payments/CoreServices,RefundPayment,0
Payments/CoreServices,RefundCapture,0
Payments/CoreServices,ProcessCredit,0
Payments/CoreServices,VoidPayment,0
Payments/CoreServices,VoidCapture,0
Payments/CoreServices,VoidRefund,0
Payments/CoreServices,VoidCredit,0
TransactionSearch/CoreServices,CreateSearchRequest,0
TransactionSearch/CoreServices,GetSearchResults,0
UserManagement/CoreServices,GetUserInformation,0
TransactionBatches/CoreServices,GetIndividualBatchFile,0
TransactionBatches/CoreServices,GetListOfBatchFiles,0
TransactionDetails/CoreServices,RetrieveTransaction,0
SecureFileShare/CoreServices,DownloadFileWithFileIdentifier,0
SecureFileShare/CoreServices,GetListOfFiles,0
Reporting/CoreServices,GetNotificationOfChanges,0
Reporting/CoreServices,GetPurchaseAndRefundDetails,0
Reporting/CoreServices,GetReportDefinition,0
Reporting/CoreServices,GetReportingResourceInformation,0
Reporting/CoreServices,GetAllSubscriptions,0
Reporting/CoreServices,GetSubscriptionForReportName,0
Reporting/CoreServices,CreateReportSubscriptionForReportNameByOrganization,0
Reporting/CoreServices,DeleteSubscriptionOfReportNameByOrganization,0
Reporting/CoreServices,RetrieveAvailableReports,0
Reporting/CoreServices,CreateAdhocReport,0
Reporting/CoreServices,GetReportBasedOnReportid,0
Reporting/CoreServices,DownloadReport,0
3 changes: 3 additions & 0 deletions test/SamplesQA/CSV_Files/Flex/CoreServices/GenerateKey.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testCaseId,encryptionType,message
CKeyGen_01,None,Success
CKeyGen_02,SSRT,Fails due to invalid encryptionType
4 changes: 4 additions & 0 deletions test/SamplesQA/CSV_Files/Flex/CoreServices/TokenizeCard.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,keyId,message
CTokC_01,08rV37jKiBShwrjkzXouukjYuGigYi4p,Success
CTokC_02,0023154mudgshfyrtdgfj456fhdggdg1,Fails due to invalid keyId

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CAO_01,2854.00,Success
CAO_02,200.0,Fails due to mismatch amount
CAO_03,ADHJ5,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CMI_01,2016.05,Success
CMI_02,200.0,Fails due to mismatch amount
CMI_03,ZNK9,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CMUD_01,2016.05,Success
CMUD_02,200.0,Fails due to mismatch amount
CMUD_03,QWERT3,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CSU_01,106.00,Success
CSU_02,200.0,Fails due to mismatch amount
CSU_03,SDRT12,Fails due to onvalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CV_01,100.00,Success
CV_02,200.0,Fails due to mismatch amount
CV_03,HGFWQ3,Fails due to invalid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testCaseId,amount,message
CNR_01,2401.00,Success
CNR_02,FDE32,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CR_01,100.00,Success
CR_02,200.0,Fails due to mismatch amount
CR_03,DSWAZ1,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CAVSO_01,2861.00,Success
CAVSO_02,2500,Fails due to mismatch amount
CAVSO_03,LKA9,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CAE_01,100.00,Success
CAE_02,200.0,Fails due to mismatch amount
CAE_03,KLTR7,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CD_01,2016.05,Success
CD_02,200.0,Fails due to mismatch amount
CD_03,GHTR3,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CMC_01,2016.05,Success
CMC_02,200.0,Fails due to mismatch amount
CMC_03,HGWQ5,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CV_01,100.00,Success
CV_02,200.0,Fails due to mismatch amount
CV_03,POTR8,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CAES_01,100.00,Success
CAES_02,200,Fails due to mismatch amount
CAES_03,GHP12,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CBPA_01,72210.00,Success
CBPA_02,6700,Fails due to mismatch amount
CBPA_03,AQWA9,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CAC_01,2854.00,Success
CAC_02,200.0,Fails due to mismatch amount
CAC_03,ZDFRT6,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CDC_01,2839.00,Success
CDC_02,200.0,Fails due to mismatch amount
CDC_03,GHTR56,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CMIC_01,2016.05,Success
CMIC_02,200.0,Fails due to mismatch amount
CMIC_03,BVFC27,Fails due to invalid amount
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testCaseId,amount,message
CMUD_01,2016.05,Success
CMUD_02,200.0,Fails due to mismatch amount
CMUD_03,IUYTR2,Fails due to invalid amount
Loading