diff --git a/Tests/spec/SogoToolSpec.js b/Tests/spec/SogoToolSpec.js index 764ee8f74..945d85aed 100644 --- a/Tests/spec/SogoToolSpec.js +++ b/Tests/spec/SogoToolSpec.js @@ -6,15 +6,18 @@ const path = require('path') const { execSync } = require('child_process') describe('sogo-tool tests', function() { - let tmpdir, userdir + let tmpdir, isRoot beforeAll(function() { - const { homedir } = os.userInfo() - userdir = homedir + const { uid } = os.userInfo() + isRoot = (uid == 0) }) beforeEach(function() { - tmpdir = mkdtempSync(path.join(userdir, 'sogo-')) + tmpdir = mkdtempSync(path.join(os.tmpdir(), 'sogo-')) + if (isRoot) { + execSync(`chown -R sogo:sogo ${tmpdir}`) + } }) afterEach(function() { @@ -22,8 +25,7 @@ describe('sogo-tool tests', function() { }) it('backup', async function() { - const { uid } = os.userInfo() - const sudo = uid == 0 ? `sudo -u sogo ` : `` + const sudo = isRoot ? `sudo -u sogo ` : `` execSync(`${sudo}sogo-tool backup ${tmpdir} ${config.username}`, (error, stdout, stderr) => { expect(error).not.toBeDefined() })