diff --git a/.gitignore b/.gitignore index c8e8f19..d8fdce6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/** +test/app-template/www/certificates/* tags .zedstate npm-debug.log diff --git a/package.json b/package.json index 4db04ca..a573d64 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,11 @@ "version": "2.0.0", "description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning", "scripts": { + "updatecert": "node ./scripts/update-test-cert.js", "buildbrowser": "./scripts/build-test-app.sh --browser", "testandroid": "./scripts/build-test-app.sh --android --emulator && ./scripts/test-app.sh --android --emulator", "testios": "./scripts/build-test-app.sh --ios --emulator && ./scripts/test-app.sh --ios --emulator", - "testapp": "npm run testandroid && npm run testios", + "testapp": "npm run updatecert && npm run testandroid && npm run testios", "testjs": "mocha ./test/js-mocha-specs.js", "test": "npm run testjs && npm run testapp", "release": "npm run test && ./scripts/release.sh" diff --git a/scripts/update-test-cert.js b/scripts/update-test-cert.js new file mode 100644 index 0000000..864a4ff --- /dev/null +++ b/scripts/update-test-cert.js @@ -0,0 +1,42 @@ +const fs = require('fs'); +const https = require('https'); +const path = require('path'); + +const SOURCE_HOST = 'httpbin.org'; +const TARGET_PATH = path.join(__dirname, '../test/app-template/www/certificates/httpbin.org.cer'); + +const getCert = hostname => new Promise((resolve, reject) => { + const options = { + hostname, + agent: false, + rejectUnauthorized: false, + ciphers: 'ALL' + }; + + const req = https.get(options, response => { + const certificate = response.socket.getPeerCertificate(); + + if (certificate === null) { + return reject({ message: 'The website did not provide a certificate' }); + } + + resolve(certificate); + }); + + req.on('error', error => { + return reject(error) + }); + + req.end(); +}); + +console.log(`Updating test certificate from ${SOURCE_HOST}`); + +getCert(SOURCE_HOST) + .then(cert => { + fs.writeFileSync(TARGET_PATH, cert.raw); + }) + .catch(error => { + console.error(`Updating test cert failed: ${error}`); + process.exit(1); + }); diff --git a/test/app-mocha-specs/test.js b/test/app-mocha-specs/test.js index 696a73a..4056e02 100644 --- a/test/app-mocha-specs/test.js +++ b/test/app-mocha-specs/test.js @@ -83,10 +83,10 @@ describe('Advanced HTTP', function() { })); testDefinitions.tests.forEach((definition, index) => { - it(definition.description, function() { + it(index + ': ' + definition.description, function() { return clickNext() .then(() => validateTestIndex(index)) - .then(() => validateTestTitle(this.test.title)) + .then(() => validateTestTitle(definition.description)) .then(() => waitToBeFinished(definition.timeout || 10000)) .then(() => validateResult(definition)) });