Print more advanced error message for non-supported protocols
MODIFY
lib/basedriver/helpers.js
lib/basedriver/helpers.js
@@ -53,10 +53,11 @@ async function configureApp (app, appExt, mountRoot="Volumes", windowsShareUserN
let newApp = app;
let shouldUnzipApp = false;
+ const {protocol} = url.parse(newApp);
+ const isUrl = ['http:', 'https:'].includes(protocol);
- let isUrl = false;
- // check if we're copying from a windows network share
if (newApp.startsWith('\\\\')) {
+ // Use the app from Windows network share
logger.info(`Downloading the application '${newApp}' from SMB share...`);
newApp = await copyFromWindowsNetworkShare(newApp, appExt,
mountRoot, windowsShareUserName, windowsSharePassword);
@@ -64,8 +65,8 @@ async function configureApp (app, appExt, mountRoot="Volumes", windowsShareUserN
throw new Error(`The application at '${app}' does not exist or is not accessible for download`);
}
logger.info(`Downloaded the app to '${newApp}'`);
- } else if (newApp.startsWith('http') && newApp.includes('://')) {
- isUrl = true;
+ } else if (isUrl) {
+ // Use the app from remote URL
const cachedPath = await getCachedApplicationPath(newApp);
if (cachedPath) {
if (await fs.exists(cachedPath)) {
@@ -81,13 +82,19 @@ async function configureApp (app, appExt, mountRoot="Volumes", windowsShareUserN
// the filetype may not be obvious for certain urls, so check the mime type too
shouldUnzipApp = _.includes(ZIP_EXTS, path.extname(newApp)) || contentType === ZIP_MIME_TYPE;
logger.info(`Downloaded the app to '${newApp}'`);
- } else {
+ } else if (await fs.exists(newApp)) {
+ // Use the local app
logger.info(`Using local app '${newApp}'`);
- if (!await fs.exists(newApp)) {
- throw new Error(`The application at '${newApp}' does not exist or is not accessible`);
- }
shouldUnzipApp = _.includes(ZIP_EXTS, path.extname(newApp));
newApp = shouldUnzipApp ? await copyLocalZip(newApp) : newApp;
+ } else {
+ let errorMessage = `The application at '${newApp}' does not exist or is not accessible`;
+ // protocol value for 'C:\\temp' is 'c:', so we check the length as well
+ if (_.isString(protocol) && protocol.length > 2) {
+ errorMessage = `The protocol '${protocol}' used in '${newApp}' is not supported. ` +
+ `Only http: and https: protocols are supported`;
+ }
+ throw new Error(errorMessage);
}
if (shouldUnzipApp) {

MODIFY
test/basedriver/helpers-e2e-specs.js
test/basedriver/helpers-e2e-specs.js
@@ -116,6 +116,16 @@ describe('app download and configuration', function () {
await h.configureApp('http://localhost:8000/missing/FakeIOSApp.app.zip', '.app')
.should.be.rejectedWith(/Problem downloading app from url/);
});
+ it('should handle invalid protocol', async function () {
+ await h.configureApp('file://C:/missing/FakeIOSApp.app.zip', '.app')
+ .should.be.rejectedWith(/is not supported/);
+ await h.configureApp('ftp://localhost:8000/missing/FakeIOSApp.app.zip', '.app')
+ .should.be.rejectedWith(/is not supported/);
+ });
+ it('should handle missing file in Windows path format', async function () {
+ await h.configureApp('C:\\missing\\FakeIOSApp.app.zip', '.app')
+ .should.be.rejectedWith(/does not exist or is not accessible/);
+ });
it('should recognize zip mime types and unzip the downloaded file', async function () {
let newAppPath = await h.configureApp('http://localhost:8000/FakeAndroidApp.asd?mime-zip', '.apk');
newAppPath.should.contain('FakeAndroidApp.apk');

Print more advanced error message for non-supported protocols (#189)