diff --git a/build/models/device.js b/build/models/device.js index 1e640b60e..452606f85 100644 --- a/build/models/device.js +++ b/build/models/device.js @@ -75,6 +75,9 @@ limitations under the License. */ exports.ensureSupervisorCompatibility = ensureSupervisorCompatibility = Promise.method(function(version, minVersion) { + if (!semver.valid(version)) { + throw new Error("Invalid supervisor version: " + version); + } if (semver.lt(version, minVersion)) { throw new Error("Incompatible supervisor version: " + version + " - must be >= " + minVersion); } diff --git a/lib/models/device.coffee b/lib/models/device.coffee index 5d4a27262..28ae444c2 100644 --- a/lib/models/device.coffee +++ b/lib/models/device.coffee @@ -65,6 +65,9 @@ CONTAINER_ACTION_ENDPOINT_TIMEOUT = 50000 # }); ### exports.ensureSupervisorCompatibility = ensureSupervisorCompatibility = Promise.method (version, minVersion) -> + if not semver.valid(version) + throw new Error("Invalid supervisor version: #{version}") + if semver.lt(version, minVersion) throw new Error("Incompatible supervisor version: #{version} - must be >= #{minVersion}") diff --git a/tests/integration.coffee b/tests/integration.coffee index 09c55f2d8..9fe4db20d 100644 --- a/tests/integration.coffee +++ b/tests/integration.coffee @@ -351,6 +351,22 @@ describe 'SDK Integration Tests', -> m.chai.expect(manifest.slug).to.equal('raspberry-pi') .nodeify(done) + describe 'resin.models.device.ensureSupervisorCompatibility()', -> + MIN_VERSION = '1.0.0' + + it 'should be fulfilled if supervisor version is compatible', -> + promise = resin.models.device.ensureSupervisorCompatibility('1.1.0', MIN_VERSION) + m.chai.expect(promise).to.be.fulfilled + + it 'should be rejected if supervisor version is not compatible', -> + promise = resin.models.device.ensureSupervisorCompatibility('0.9.0', MIN_VERSION) + m.chai.expect(promise).to.be.rejected + + it 'should be rejected if supervisor version is not semver-compatible', -> + INVALID_VERSION = 'InvalidSemver' + promise = resin.models.device.ensureSupervisorCompatibility(INVALID_VERSION, MIN_VERSION) + m.chai.expect(promise).to.be.rejectedWith("Invalid supervisor version: #{INVALID_VERSION}") + describe 'given no applications', -> describe 'Application Model', ->