diff --git a/package.json b/package.json index 21429b1..617e7bc 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "1.8.1", "description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning", "scripts": { - "testapp": "./scripts/build-test-app.sh && ./scripts/test-app.sh --ios --emulator", + "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", "testjs": "mocha ./test/js-mocha-specs.js", "test": "npm run testjs && npm run testapp", "release": "npm run test && ./scripts/release.sh" diff --git a/src/android/com/synconset/cordovahttp/CordovaHttp.java b/src/android/com/synconset/cordovahttp/CordovaHttp.java index 1e0bb0b..5e5c245 100644 --- a/src/android/com/synconset/cordovahttp/CordovaHttp.java +++ b/src/android/com/synconset/cordovahttp/CordovaHttp.java @@ -161,7 +161,7 @@ abstract class CordovaHttp { } protected void respondWithError(String msg) { - this.respondWithError(500, msg); + this.respondWithError(-1, msg); } protected void addResponseHeaders(HttpRequest request, JSONObject response) throws JSONException { @@ -241,7 +241,7 @@ abstract class CordovaHttp { } else if (e.getCause() instanceof SSLHandshakeException) { this.respondWithError("SSL handshake failed"); } else { - this.respondWithError("There was an error with the request"); + this.respondWithError("There was an error with the request: " + e.getMessage()); } } } diff --git a/src/android/com/synconset/cordovahttp/CordovaHttpDelete.java b/src/android/com/synconset/cordovahttp/CordovaHttpDelete.java index e91aab5..0a8e39e 100644 --- a/src/android/com/synconset/cordovahttp/CordovaHttpDelete.java +++ b/src/android/com/synconset/cordovahttp/CordovaHttpDelete.java @@ -57,7 +57,7 @@ class CordovaHttpDelete extends CordovaHttp implements Runnable { } else if (e.getCause() instanceof SSLHandshakeException) { this.respondWithError("SSL handshake failed"); } else { - this.respondWithError("There was an error with the request"); + this.respondWithError("There was an error with the request: " + e.getMessage()); } } catch (Exception e) { this.respondWithError(-1, e.getMessage()); diff --git a/test/app-mocha-specs/test.js b/test/app-mocha-specs/test.js index 6047e4c..6ca14dc 100644 --- a/test/app-mocha-specs/test.js +++ b/test/app-mocha-specs/test.js @@ -8,14 +8,16 @@ const testDefinitions = require('../app-test-definitions'); const pkgjson = require('../../package.json'); describe('Advanced HTTP', function() { + const isDevice = process.argv.includes('--device'); + const isAndroid = process.argv.includes('--android'); + const targetInfo = { isDevice, isAndroid }; + let driver = null; let allPassed = true; this.timeout(900000); const getCaps = appName => { - const isDevice = process.argv.includes('--device'); - const isAndroid = process.argv.includes('--android'); const desiredCaps = caps[(isAndroid ? 'android' : 'ios') + (isDevice ? 'Device' : 'Emulator')]; const desiredApp = apps[(isAndroid ? 'android' : 'ios') + appName]; @@ -57,7 +59,7 @@ describe('Advanced HTTP', function() { const validateResult = testDefinition => driver .safeExecute('app.lastResult') - .then(result => testDefinition.validationFunc(driver, result)); + .then(result => testDefinition.validationFunc(driver, result, targetInfo)); const clickNext = () => driver .elementById('nextBtn') diff --git a/test/app-test-definitions.js b/test/app-test-definitions.js index 7372e71..38251a1 100644 --- a/test/app-test-definitions.js +++ b/test/app-test-definitions.js @@ -37,41 +37,41 @@ const tests = [ description: 'should reject self signed cert (GET)', expected: 'rejected: {"status":-1,"error":"cancelled"}', func: function(resolve, reject) { cordova.plugin.http.get('https://self-signed.badssl.com/', {}, {}, resolve, reject); }, - validationFunc: function(driver, result) { + validationFunc: function(driver, result, targetInfo) { result.type.should.be.equal('rejected'); - result.data.should.be.eql({ status: -1, error:'cancelled' }); + result.data.should.be.eql({ status: -1, error: targetInfo.isAndroid ? 'SSL handshake failed' : 'cancelled' }); } },{ description: 'should reject self signed cert (PUT)', expected: 'rejected: {"status":-1,"error":"cancelled"}', func: function(resolve, reject) { cordova.plugin.http.put('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }, - validationFunc: function(driver, result) { + validationFunc: function(driver, result, targetInfo) { result.type.should.be.equal('rejected'); - result.data.should.be.eql({ status: -1, error:'cancelled' }); + result.data.should.be.eql({ status: -1, error: targetInfo.isAndroid ? 'SSL handshake failed' : 'cancelled' }); } },{ description: 'should reject self signed cert (POST)', expected: 'rejected: {"status":-1,"error":"cancelled"}', func: function(resolve, reject) { cordova.plugin.http.post('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }, - validationFunc: function(driver, result) { + validationFunc: function(driver, result, targetInfo) { result.type.should.be.equal('rejected'); - result.data.should.be.eql({ status: -1, error:'cancelled' }); + result.data.should.be.eql({ status: -1, error: targetInfo.isAndroid ? 'SSL handshake failed' : 'cancelled' }); } },{ description: 'should reject self signed cert (PATCH)', expected: 'rejected: {"status":-1,"error":"cancelled"}', func: function(resolve, reject) { cordova.plugin.http.patch('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }, - validationFunc: function(driver, result) { + validationFunc: function(driver, result, targetInfo) { result.type.should.be.equal('rejected'); - result.data.should.be.eql({ status: -1, error:'cancelled' }); + result.data.should.be.eql({ status: -1, error: targetInfo.isAndroid ? 'SSL handshake failed' : 'cancelled' }); } },{ description: 'should reject self signed cert (DELETE)', expected: 'rejected: {"status":-1,"error":"cancelled"}', func: function(resolve, reject) { cordova.plugin.http.delete('https://self-signed.badssl.com/', {}, {}, resolve, reject); }, - validationFunc: function(driver, result) { + validationFunc: function(driver, result, targetInfo) { result.type.should.be.equal('rejected'); - result.data.should.be.eql({ status: -1, error:'cancelled' }); + result.data.should.be.eql({ status: -1, error: targetInfo.isAndroid ? 'SSL handshake failed' : 'cancelled' }); } },{ description: 'should accept bad cert (GET)',