Auto-merge for PR #651 via VersionBot

Don't generate config fields in offline mode
This commit is contained in:
resin-io-versionbot[bot] 2018-05-21 14:20:40 +00:00 committed by GitHub
commit 82123d3591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 12 deletions

View File

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## v7.7.1 - 2018-05-21
* Don't generate config fields in offline mode #651 [Cameron Diver]
## v7.7.0 - 2018-05-18 ## v7.7.0 - 2018-05-18
* Add support for changing config.txt on balena fin devices #663 [Pablo Carranza Velez] * Add support for changing config.txt on balena fin devices #663 [Pablo Carranza Velez]

View File

@ -1,7 +1,7 @@
{ {
"name": "resin-supervisor", "name": "resin-supervisor",
"description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.",
"version": "7.7.0", "version": "7.7.1",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -241,14 +241,20 @@ module.exports = class Config extends EventEmitter
deviceRegister.generateUniqueKey() deviceRegister.generateUniqueKey()
generateRequiredFields: => generateRequiredFields: =>
@getMany([ 'uuid', 'deviceApiKey', 'apiSecret', 'logsChannelSecret' ]) @getMany([ 'uuid', 'deviceApiKey', 'apiSecret', 'logsChannelSecret', 'offlineMode' ])
.then ({ uuid, deviceApiKey, apiSecret, logsChannelSecret }) => .then ({ uuid, deviceApiKey, apiSecret, logsChannelSecret, offlineMode }) =>
if !uuid? or !deviceApiKey? or !apiSecret? or !logsChannelSecret? # These fields need to be set regardless
if !uuid? or !apiSecret?
uuid ?= @newUniqueKey() uuid ?= @newUniqueKey()
deviceApiKey ?= @newUniqueKey()
apiSecret ?= @newUniqueKey() apiSecret ?= @newUniqueKey()
logsChannelSecret ?= @newUniqueKey() @set({ uuid, apiSecret })
@set({ uuid, deviceApiKey, apiSecret, logsChannelSecret }) .then =>
# These fields only need set when we're not in offlineMode
return if offlineMode
if !deviceApiKey? or !logsChannelSecret?
deviceApiKey ?= @newUniqueKey()
logsChannelSecret ?= @newUniqueKey()
@set({ deviceApiKey, logsChannelSecret })
regenerateRegistrationFields: => regenerateRegistrationFields: =>
uuid = deviceRegister.generateUniqueKey() uuid = deviceRegister.generateUniqueKey()

View File

@ -12,11 +12,11 @@ Config = require('../src/config')
DeviceState = require('../src/device-state') DeviceState = require('../src/device-state')
APIBinder = require('../src/api-binder') APIBinder = require('../src/api-binder')
initModels = -> initModels = (filename) ->
@timeout(5000) @timeout(5000)
prepare() prepare()
@db = new DB() @db = new DB()
@config = new Config({ @db, configPath: '/config-apibinder.json' }) @config = new Config({ @db, configPath: filename })
@eventTracker = { @eventTracker = {
track: stub().callsFake (ev, props) -> track: stub().callsFake (ev, props) ->
console.log(ev, props) console.log(ev, props)
@ -49,7 +49,7 @@ describe 'APIBinder', ->
# We do not support older OS versions anymore, so we only test this case # We do not support older OS versions anymore, so we only test this case
describe 'on an OS with deviceApiKey support', -> describe 'on an OS with deviceApiKey support', ->
before -> before ->
initModels.call(this) initModels.call(this, '/config-apibinder.json')
it 'provisions a device', -> it 'provisions a device', ->
promise = @apiBinder.provisionDevice() promise = @apiBinder.provisionDevice()
@ -79,7 +79,7 @@ describe 'APIBinder', ->
describe 'fetchDevice', -> describe 'fetchDevice', ->
before -> before ->
initModels.call(this) initModels.call(this, '/config-apibinder.json')
it 'gets a device by its uuid from the Resin API', -> it 'gets a device by its uuid from the Resin API', ->
# Manually add a device to the mocked API # Manually add a device to the mocked API
@ -97,7 +97,7 @@ describe 'APIBinder', ->
describe '_exchangeKeyAndGetDevice', -> describe '_exchangeKeyAndGetDevice', ->
before -> before ->
initModels.call(this) initModels.call(this, '/config-apibinder.json')
it 'returns the device if it can fetch it with the deviceApiKey', -> it 'returns the device if it can fetch it with the deviceApiKey', ->
spy(resinAPI.resinBackend, 'deviceKeyHandler') spy(resinAPI.resinBackend, 'deviceKeyHandler')
@ -135,3 +135,27 @@ describe 'APIBinder', ->
expect(@apiBinder.fetchDevice).to.be.calledTwice expect(@apiBinder.fetchDevice).to.be.calledTwice
@apiBinder.fetchDevice.restore() @apiBinder.fetchDevice.restore()
resinAPI.resinBackend.deviceKeyHandler.restore() resinAPI.resinBackend.deviceKeyHandler.restore()
describe 'offline mode', ->
before ->
initModels.call(this, '/config-apibinder-offline.json')
it 'does not generate a key if the device is in offline mode', ->
@config.get('offlineMode').then (mode) =>
# Ensure offline mode is set
expect(mode).to.equal(true)
# Check that there is no deviceApiKey
@config.getMany([ 'deviceApiKey', 'uuid' ]).then (conf) ->
expect(conf['deviceApiKey']).to.be.undefined
expect(conf['uuid']).to.not.be.undefined
describe 'Minimal config offline mode', ->
before ->
initModels.call(this, '/config-apibinder-offline2.json')
it 'does not generate a key with the minimal config', ->
@config.get('offlineMode').then (mode) =>
expect(mode).to.equal(true)
@config.getMany([ 'deviceApiKey', 'uuid' ]).then (conf) ->
expect(conf['deviceApiKey']).to.be.undefined
expect(conf['uuid']).to.not.be.undefined

View File

@ -0,0 +1 @@
{"applicationName":"supertestrpi3","applicationId":78373,"deviceType":"raspberrypi3","userId":1001,"username":"someone","appUpdatePollInterval":3000,"listenPort":2345,"vpnPort":443,"apiEndpoint":"http://0.0.0.0:3000","vpnEndpoint":"vpn.resin.io","registryEndpoint":"registry2.resin.io","deltaEndpoint":"https://delta.resin.io","pubnubSubscribeKey":"foo","pubnubPublishKey":"bar","mixpanelToken":"baz","apiKey":"boo","version":"2.0.6+rev3.prod","supervisorOfflineMode":true}

View File

@ -0,0 +1 @@
{"deviceType": "raspberrypi3"}

View File

@ -16,3 +16,12 @@ module.exports = ->
try try
fs.writeFileSync('./test/data/config.json', fs.readFileSync('./test/data/testconfig.json')) fs.writeFileSync('./test/data/config.json', fs.readFileSync('./test/data/testconfig.json'))
fs.writeFileSync('./test/data/config-apibinder.json', fs.readFileSync('./test/data/testconfig-apibinder.json')) fs.writeFileSync('./test/data/config-apibinder.json', fs.readFileSync('./test/data/testconfig-apibinder.json'))
fs.writeFileSync(
'./test/data/config-apibinder-offline.json',
fs.readFileSync('./test/data/testconfig-apibinder-offline.json')
)
fs.writeFileSync(
'./test/data/config-apibinder-offline2.json',
fs.readFileSync('./test/data/testconfig-apibinder-offline2.json')
)