make sure caps are sanitized (fix #2103)

This commit is contained in:
Jonathan Lipps
2014-03-20 16:56:46 -07:00
parent 5ddc136a84
commit fd24d65ffe
3 changed files with 35 additions and 9 deletions
+1
View File
@@ -223,6 +223,7 @@ Appium.prototype.getDeviceTypeFromArgs = function (args) {
Appium.prototype.configure = function (args, desiredCaps, cb) {
var deviceType;
try {
deviceType = this.getDeviceType(args, desiredCaps);
} catch (e) {
+21 -8
View File
@@ -1,5 +1,6 @@
"use strict";
var _ = require('underscore')
, logger = require('./logger.js').get('appium')
, warnDeprecated = require('../helpers.js').logDeprecationWarning;
var capsConversion = {
@@ -8,19 +9,31 @@ var capsConversion = {
};
var Capabilities = function (capabilities) {
this.desired = capabilities;
this.warnings = {};
this.setDesired(capabilities);
_.each(capabilities, function (cap, name) {
if (_.contains(_.keys(capsConversion), name)) {
warnDeprecated('capability', name, capsConversion[name]);
_.each(this.desired, function (value, cap) {
if (_.contains(_.keys(capsConversion), cap)) {
warnDeprecated('capability', cap, capsConversion[cap]);
}
// Hacky alias for version
if (name.indexOf('platformVersion') !== -1) {
this.version = cap;
if (cap.indexOf('platformVersion') !== -1) {
this.version = value;
}
this[name] = cap;
this[cap] = value;
}, this);
};
module.exports = Capabilities;
Capabilities.prototype.setDesired = function (caps) {
_.each(caps, function (value, cap) {
if (typeof value === "object" && value !== null) {
logger.warn("Converting cap " + cap + " to string, since it was an " +
"object. This might be a user error. Original value was: " +
JSON.stringify(value));
caps[cap] = JSON.stringify(value);
}
});
this.desired = caps;
};
module.exports = Capabilities;
+13 -1
View File
@@ -10,6 +10,18 @@ var Capabilities = require('../../lib/server/capabilities.js')
describe('capabilities', function () {
describe('#new', function () {
it('should convert object caps to strings', function () {
var c = new Capabilities({app: {some: 'object'}, platformVersion: 'hi'});
c.app.should.equal('{"some":"object"}');
});
it('should leave undefined, null, numbers alone', function () {
var c = new Capabilities({appPackage: null, bob: undefined, platformVersion: 7.0});
should.not.exist(c.appPackage);
(typeof c.appPackage).should.equal("object");
(typeof c.bob).should.equal("undefined");
c.platformVersion.should.equal(7.0);
(typeof c.platformVersion).should.equal("number");
});
describe('with pre-mjsonwp capabilities', function () {
var capabilityConversion = [
['device', 'platformName']
@@ -71,4 +83,4 @@ describe('capabilities', function () {
});
});
});
});
});