Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit fa9a616

Browse files
Release 4.3.0.
1 parent 1077dd1 commit fa9a616

File tree

8 files changed

+217
-68
lines changed

8 files changed

+217
-68
lines changed

__tests__/unit/utils/obfuscate.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
import each from "jest-each";
22
import * as http from "http";
3+
import * as _ from "lodash";
34
import * as obfuscate from "../../../src/utils/obfuscate";
5+
import { ObfuscationRule } from "../../../src/model";
6+
7+
import * as connectSdk from "../../../src";
8+
9+
connectSdk.init({
10+
host: "example.org",
11+
scheme: "https",
12+
port: -1,
13+
enableLogging: false,
14+
apiKeyId: "",
15+
secretApiKey: "",
16+
integrator: "Integration tests"
17+
});
418

519
/**
620
* @group unit:obfuscate
721
*/
822
describe("obfuscate.getObfuscated", () => {
23+
beforeEach(() => {
24+
delete connectSdk.context.getContext().obfuscationRules;
25+
});
26+
927
test("undefined body", () => {
1028
expect(obfuscate.getObfuscated(undefined)).toBe("");
1129
});
@@ -44,6 +62,41 @@ describe("obfuscate.getObfuscated", () => {
4462
expect(obfuscate.getObfuscated(body)).toBe(JSON.stringify(expected, null, 2));
4563
});
4664

65+
test("cardNumber with custom rule", () => {
66+
const body = {
67+
order: {
68+
amountOfMoney: {
69+
currencyCode: "CAD",
70+
amount: 2345
71+
},
72+
customer: {
73+
billingAddress: {
74+
countryCode: "CA"
75+
}
76+
}
77+
},
78+
cardPaymentMethodSpecificInput: {
79+
paymentProductId: 1,
80+
card: {
81+
cvv: "123",
82+
cardNumber: "1234567890123456",
83+
expiryDate: "1220"
84+
}
85+
}
86+
};
87+
const expected = JSON.parse(JSON.stringify(body));
88+
expected.cardPaymentMethodSpecificInput.card.cvv = "***";
89+
expected.cardPaymentMethodSpecificInput.card.cardNumber = "123456******3456";
90+
expected.cardPaymentMethodSpecificInput.card.expiryDate = "**20";
91+
92+
const obfuscationRule: ObfuscationRule = value => value.substring(0, 6) + _.padStart("", 6, "*") + value.substring(12);
93+
connectSdk.context.getContext().obfuscationRules = {
94+
cardNumber: obfuscationRule
95+
};
96+
97+
expect(obfuscate.getObfuscated(body)).toBe(JSON.stringify(expected, null, 2));
98+
});
99+
47100
test("iban", () => {
48101
const body = {
49102
sepaDirectDebit: {
@@ -140,4 +193,37 @@ describe("obfuscate.getObfuscated", () => {
140193

141194
expect(obfuscate.getObfuscated(headers, null, true)).toBe(JSON.stringify(expected, null, 2));
142195
});
196+
197+
const customHeadersTestData = [
198+
["Authorization", "Basic QWxhZGRpbjpPcGVuU2VzYW1l", "********"],
199+
["authorization", "Basic QWxhZGRpbjpPcGVuU2VzYW1l", "********"],
200+
["AUTHORIZATION", "Basic QWxhZGRpbjpPcGVuU2VzYW1l", "********"],
201+
202+
["X-GCS-Authentication-Token", "foobar", "********"],
203+
["x-gcs-authentication-token", "foobar", "********"],
204+
["X-GCS-AUTHENTICATION-TOKEN", "foobar", "********"],
205+
206+
["X-GCS-CallerPassword", "foobar", "********"],
207+
["x-gcs-callerpassword", "foobar", "********"],
208+
["X-GCS-CALLERPASSWORD", "foobar", "********"],
209+
210+
["Content-Type", "application/json", "****************"],
211+
["content-type", "application/json", "****************"],
212+
["CONTENT-TYPE", "application/json", "****************"]
213+
];
214+
each(customHeadersTestData).test("when the header is '%s'", (name, originalValue, expectedObfuscatedValue) => {
215+
const headers: http.IncomingHttpHeaders = {};
216+
headers[name] = originalValue;
217+
headers["content-length"] = "5";
218+
219+
const expected = JSON.parse(JSON.stringify(headers));
220+
expected[name] = expectedObfuscatedValue;
221+
222+
const obfuscationRule: ObfuscationRule = obfuscate.all();
223+
connectSdk.context.getContext().obfuscationRules = {
224+
"content-type": obfuscationRule
225+
};
226+
227+
expect(obfuscate.getObfuscated(headers, null, true)).toBe(JSON.stringify(expected, null, 2));
228+
});
143229
});

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "connect-sdk-nodejs",
3-
"version": "4.2.1",
3+
"version": "4.3.0",
44
"description": "SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API",
55
"homepage": "https://github.com/Ingenico-ePayments/connect-sdk-nodejs#readme",
66
"bugs": {

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import https = require("https");
66
import { CommunicatorLogger, ConnectSdk, Context } from "./model";
77
import sdkcontext = require("./utils/context");
8+
import obfuscate = require("./utils/obfuscate");
89

910
import hostedcheckouts = require("./hostedcheckouts");
1011
import hostedmandatemanagements = require("./hostedmandatemanagements");
@@ -89,6 +90,13 @@ const connectSdk: ConnectSdk = {
8990
files: files,
9091
context: sdkcontext,
9192

92-
webhooks: webhooks
93+
webhooks: webhooks,
94+
95+
obfuscate: {
96+
all: obfuscate.all,
97+
allButLast: obfuscate.allButLast,
98+
allButFirst: obfuscate.allButFirst,
99+
withFixedLength: obfuscate.withFixedLength
100+
}
93101
};
94102
export = connectSdk;

src/model/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file was auto-generated from the API references found at
33
* https://epayments-api.developer-ingenico.com/s2sapi/v1/
44
*/
5-
import { Context, SdkContext } from "./types";
5+
import { Context, ObfuscationRules, SdkContext } from "./types";
66
import { HostedcheckoutsClient } from "./hostedcheckouts";
77
import { HostedmandatemanagementsClient } from "./hostedmandatemanagements";
88
import { PaymentsClient } from "./payments";
@@ -42,6 +42,8 @@ export interface ConnectSdk {
4242
readonly context: SdkContext;
4343

4444
readonly webhooks: WebhooksHelper;
45+
46+
readonly obfuscate: ObfuscationRules;
4547
}
4648

4749
export * from "./types";

src/model/types.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface Context {
2121
integrator: string;
2222
shoppingCartExtension?: ShoppingCartExtension;
2323
httpOptions?: https.RequestOptions;
24+
obfuscationRules?: { [key: string]: ObfuscationRule };
2425
}
2526

2627
export interface FileMetaData {
@@ -55,6 +56,27 @@ export interface MultipartFormDataRequest extends SdkRequest {
5556
body: MultipartFormDataObject;
5657
}
5758

59+
export interface ObfuscationRules {
60+
/**
61+
* @returns An obfuscation rule that will replace all characters with *.
62+
*/
63+
all(): ObfuscationRule;
64+
/**
65+
* @returns An obfuscation rule that will keep a fixed number of characters at the end, then replaces all other characters with *.
66+
*/
67+
allButLast(count: number): ObfuscationRule;
68+
/**
69+
* @returns An obfuscation rule that will keep a fixed number of characters at the start, then replaces all other characters with *.
70+
*/
71+
allButFirst(count: number): ObfuscationRule;
72+
/**
73+
* @returns An obfuscation rule that will replace values with a fixed length string containing only *.
74+
*/
75+
withFixedLength(count: number): ObfuscationRule;
76+
}
77+
78+
export type ObfuscationRule = (value: string) => string;
79+
5880
export interface PaymentContext {
5981
extraHeaders?: Header[];
6082
idemPotence?: IdemPotence;

src/utils/headers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ServerMetaInfo {
1818
export function serverMetaInfo(sdkContext: SdkContext): Header {
1919
const info: ServerMetaInfo = {
2020
sdkCreator: "Ingenico",
21-
sdkIdentifier: "NodejsServerSDK/v4.2.1",
21+
sdkIdentifier: "NodejsServerSDK/v4.3.0",
2222
platformIdentifier: process.env["OS"] + " Node.js/" + process.versions.node
2323
};
2424
if (sdkContext.getIntegrator() !== null) {

0 commit comments

Comments
 (0)