Skip to content

Instantly share code, notes, and snippets.

@savagematt
Last active September 5, 2019 12:31
Show Gist options
  • Save savagematt/005efb23a11328af261026ff3791bdcf to your computer and use it in GitHub Desktop.
Save savagematt/005efb23a11328af261026ff3791bdcf to your computer and use it in GitHub Desktop.
Automate 3D secure when testing strong customer authentication flows with Stripe
const { Builder, By, until } = require("selenium-webdriver");
const tcpPortUsed = require("tcp-port-used");
const { exec } = require("child_process");
process.env.SELENIUM_BROWSER = "chrome:75:LINUX";
process.env.SELENIUM_REMOTE_URL = "http://localhost:4444/wd/hub";
let driver = () => {
const result = new Builder().forBrowser("chrome").build();
driver = () => result;
return result;
};
module.exports.hack3dSecure = async threeDSecureUrl => {
const seleniumRunning = await tcpPortUsed.check(4444, "127.0.0.1");
if (!seleniumRunning) {
await new Promise((resolve, reject) =>
exec(
"docker run -d -p 4444:4444 selenium/standalone-chrome",
(err, stdout, stderr) => {
console.log(stdout);
console.error(stderr);
if (err) {
reject(err);
} else resolve();
}
)
);
}
await tcpPortUsed.waitUntilUsed(4444);
const d = driver();
await d.get(threeDSecureUrl);
await d.wait(
until.elementLocated(By.id("test-source-authorize-3ds")),
5 * 1000
);
await d.findElement(By.id("test-source-authorize-3ds")).click();
await d.wait(until.elementLocated(By.id("message")), 5 * 1000);
};
@savagematt
Copy link
Author

const confirm = await stripe.paymentIntents.confirm(intentId);
expect(confirm.status).oneOf(["requires_source_action","requires_action"]);
await hack3dSecure(confirm.next_action.use_stripe_sdk.stripe_js);
const confirm = await stripe.setupIntents.confirm(intentId);
expect(confirm.status).oneOf(["requires_source_action","requires_action"]);
await hack3dSecure(confirm.next_action.use_stripe_sdk.stripe_js);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment