Created
June 16, 2016 01:23
-
-
Save bguiz/d52aa70ebb408e3fa4f7fc42851d2957 to your computer and use it in GitHub Desktop.
Braintree SDK test demo'ing invalid nonces letting TXs through
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const co = require('co'); | |
const chai = require('chai'); | |
const expect = chai.expect; | |
describe.only('[Braintree SDK]', function() { | |
this.timeout(5000); | |
let gateway; | |
before(() => { | |
return co(function* () { | |
const braintree = require('braintree'); | |
gateway = braintree.connect({ | |
environment: braintree.Environment.Sandbox, | |
merchantId: '...', | |
publicKey: '...', | |
privateKey: '...' | |
}); | |
}); | |
}); | |
describe('[invalid nonces]', () => { | |
let nonces = [ | |
// Processor rejected nonces | |
'fake-processor-declined-visa-nonce', | |
'fake-processor-declined-mastercard-nonce', | |
'fake-processor-declined-amex-nonce', | |
'fake-processor-declined-discover-nonce', | |
'fake-processor-failure-jcb-nonce', | |
// Gateway rejected nonces | |
'fake-luhn-invalid-nonce', | |
'fake-consumed-nonce', | |
'fake-gateway-rejected-fraud-nonce', | |
]; | |
nonces.forEach((paymentMethodNonce) => { | |
it(`should disallow TX when invalid nonce used: ${paymentMethodNonce}`, () => { | |
return co(function* () { | |
let params = { | |
amount: '19.95', | |
paymentMethodNonce, | |
options: { | |
submitForSettlement: true, | |
}, | |
}; | |
let response; | |
try { | |
response = yield gatewayTransactionSale(params); | |
} | |
catch (err) { | |
expect(err).to.be.undefined; | |
} | |
// Theere should be some errors | |
expect(response.errors).to.exist; | |
expect(response.errors).to.not.be.empty; | |
}); | |
}); | |
}); | |
}); | |
function gatewayTransactionSale(params) { | |
return new Promise((resolve, reject) => { | |
gateway.transaction.sale(params, function (err, response) { | |
if (err) { | |
return reject(err); | |
} | |
else { | |
return resolve(response); | |
} | |
}); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Braintree SDK] | |
[invalid nonces] | |
1) should disallow TX when invalid nonce used: fake-processor-declined-visa-nonce | |
2) should disallow TX when invalid nonce used: fake-processor-declined-mastercard-nonce | |
✓ should disallow TX when invalid nonce used: fake-processor-declined-amex-nonce (565ms) | |
✓ should disallow TX when invalid nonce used: fake-processor-declined-discover-nonce (533ms) | |
✓ should disallow TX when invalid nonce used: fake-processor-failure-jcb-nonce (552ms) | |
✓ should disallow TX when invalid nonce used: fake-luhn-invalid-nonce (590ms) | |
✓ should disallow TX when invalid nonce used: fake-consumed-nonce (574ms) | |
3) should disallow TX when invalid nonce used: fake-gateway-rejected-fraud-nonce | |
5 passing (8s) | |
3 failing | |
1) [Braintree SDK] [invalid nonces] should disallow TX when invalid nonce used: fake-processor-declined-visa-nonce: | |
AssertionError: expected undefined to exist | |
at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:296:33) | |
at null.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:286:25) | |
at Object.defineProperty.get (node_modules/chai/lib/chai/utils/overwriteProperty.js:50:37) | |
at test/unit/braintree-sdk.spec.js:58:37 | |
at next (native) | |
at onFulfilled (node_modules/co/index.js:65:19) | |
2) [Braintree SDK] [invalid nonces] should disallow TX when invalid nonce used: fake-processor-declined-mastercard-nonce: | |
AssertionError: expected undefined to exist | |
at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:296:33) | |
at null.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:286:25) | |
at Object.defineProperty.get (node_modules/chai/lib/chai/utils/overwriteProperty.js:50:37) | |
at test/unit/braintree-sdk.spec.js:58:37 | |
at next (native) | |
at onFulfilled (node_modules/co/index.js:65:19) | |
3) [Braintree SDK] [invalid nonces] should disallow TX when invalid nonce used: fake-gateway-rejected-fraud-nonce: | |
AssertionError: expected undefined to exist | |
at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:296:33) | |
at null.<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:286:25) | |
at Object.defineProperty.get (node_modules/chai/lib/chai/utils/overwriteProperty.js:50:37) | |
at test/unit/braintree-sdk.spec.js:58:37 | |
at next (native) | |
at onFulfilled (node_modules/co/index.js:65:19) | |
npm ERR! Test failed. See above for more details. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment