balena-settings-storage
Advanced tools
Comparing version 7.0.0-raise-eacces-errors-08b9d2bdfa7e006ee5dc5ee3f443a88ef0f32fa6 to 7.0.0-raise-eacces-errors-1995a3799b2589f9ff86e0a4b59f110b22007523
@@ -10,2 +10,3 @@ # Change Log | ||
* 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] | ||
@@ -12,0 +13,0 @@ * Change to raise error when file has no permission [josecoelho] |
{ | ||
"name": "balena-settings-storage", | ||
"version": "7.0.0-raise-eacces-errors-08b9d2bdfa7e006ee5dc5ee3f443a88ef0f32fa6", | ||
"version": "7.0.0-raise-eacces-errors-1995a3799b2589f9ff86e0a4b59f110b22007523", | ||
"description": "Balena settings storage utilities", | ||
@@ -5,0 +5,0 @@ "main": "build/storage.js", |
@@ -155,5 +155,7 @@ import * as BalenaSettingsClientModule from 'balena-settings-client'; | ||
it('should raise an error', () => { | ||
return m.chai | ||
.expect(storage.get('bar')) | ||
.to.eventually.be.rejectedWith(BalenaSettingsPermissionError); | ||
return runAsNobody(() => { | ||
return m.chai | ||
.expect(storage.get('bar')) | ||
.to.eventually.be.rejectedWith(BalenaSettingsPermissionError); | ||
}); | ||
}); | ||
@@ -205,1 +207,26 @@ }); | ||
}); | ||
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; | ||
}, | ||
); | ||
} |
57982
990