balena-settings-storage
Advanced tools
Comparing version 7.0.0-raise-eacces-errors-1995a3799b2589f9ff86e0a4b59f110b22007523 to 7.0.0-raise-eacces-errors-44a4c317a16e8cf4bab3650b2ec58f8ba7e5edc1
@@ -8,5 +8,4 @@ # Change Log | ||
# v7.0.0 | ||
## (2020-10-26) | ||
## (2020-11-02) | ||
* WIP: Fix tests to run on CI (2) [Paulo Castro] | ||
* Remove package-lock.json because it is not recommended for libraries 'package-lock.json' cannot be published to the npm registry, and will be ignored when npm-installed by packages that depend on resin-multibuild. This can lead to dependency-related errors being masked when resin-multibuild is tested in isolation. Reference: https://docs.npmjs.com/files/package-lock.json [josecoelho] | ||
@@ -13,0 +12,0 @@ * Change to raise error when file has no permission [josecoelho] |
{ | ||
"name": "balena-settings-storage", | ||
"version": "7.0.0-raise-eacces-errors-1995a3799b2589f9ff86e0a4b59f110b22007523", | ||
"version": "7.0.0-raise-eacces-errors-44a4c317a16e8cf4bab3650b2ec58f8ba7e5edc1", | ||
"description": "Balena settings storage utilities", | ||
@@ -38,6 +38,6 @@ "main": "build/storage.js", | ||
"@types/mocha": "^2.2.41", | ||
"balena-config-karma": "^2.0.0", | ||
"balena-config-karma": "^3.0.0", | ||
"balena-settings-client": "^4.0.0", | ||
"jsdoc-to-markdown": "^3.0.0", | ||
"karma": "^1.7.0", | ||
"karma": "^3.1.4", | ||
"mocha": "^3.5.0", | ||
@@ -44,0 +44,0 @@ "mochainon": "^2.0.0", |
@@ -144,18 +144,16 @@ import * as BalenaSettingsClientModule from 'balena-settings-client'; | ||
describe('with no read access', () => { | ||
let barPath: string; | ||
let fsReadFileStub: any; | ||
beforeEach(() => { | ||
barPath = path.join(dataDirectory!, 'bar'); | ||
fs.writeFileSync(barPath, 'hello world', { mode: 0o333 }); | ||
fsReadFileStub = m.sinon.stub(fs.promises, 'readFile'); | ||
fsReadFileStub.rejects({ code: 'EACCES' }); | ||
}); | ||
afterEach(() => { | ||
fs.unlinkSync(barPath); | ||
fsReadFileStub.restore(); | ||
}); | ||
it('should raise an error', () => { | ||
return runAsNobody(() => { | ||
return m.chai | ||
.expect(storage.get('bar')) | ||
.to.eventually.be.rejectedWith(BalenaSettingsPermissionError); | ||
}); | ||
return m.chai | ||
.expect(storage.get('bar')) | ||
.to.eventually.be.rejectedWith(BalenaSettingsPermissionError); | ||
}); | ||
@@ -207,26 +205,1 @@ }); | ||
}); | ||
async function runAsNobody( | ||
action: (...args: any) => Chai.PromisedAssertion, | ||
args: any[] = [], | ||
) { | ||
const euid = process.geteuid(); | ||
const restoreEUID = () => { | ||
if (euid === 0) { | ||
process.seteuid(euid); | ||
} | ||
}; | ||
if (euid === 0) { | ||
process.seteuid('nobody'); | ||
} | ||
return action(...args).then( | ||
(result) => { | ||
restoreEUID(); | ||
return result; | ||
}, | ||
(error) => { | ||
restoreEUID(); | ||
throw error; | ||
}, | ||
); | ||
} |
57475
964