forked from getodk/central-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes getodk#1305
- Loading branch information
alxndrsn
committed
Nov 27, 2024
1 parent
1c7ea7a
commit 21a9862
Showing
1 changed file
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
const { omit } = require('ramda'); | ||
const { testService } = require('../setup'); | ||
|
||
const { httpZipResponseToFiles } = require('../../util/zip'); | ||
|
||
describe('api: /backup', () => { | ||
describe('POST', () => { | ||
describe('POST', function () { | ||
this.timeout(10000); | ||
it('should reject if the user cannot backup', testService((service) => | ||
service.login('chelsea', (asChelsea) => | ||
asChelsea.post('/v1/backup').expect(403)))); | ||
|
||
it('should return a valid zip file if the user can backup @slow', testService((service) => | ||
service.login('alice', (asAlice) => | ||
httpZipResponseToFiles(asAlice.post('/v1/backup').expect(200)) | ||
.then(res => { | ||
const constantProps = ['filenames', 'keepalive', 'keys.json', 'toc.dat']; | ||
res.should.have.properties(constantProps); | ||
|
||
const datFiles = Object.keys(omit(constantProps, res)); | ||
// Because /backup ALWAYS uses config('default.database'), this list | ||
// may be empty in some environments, including CI. | ||
datFiles.should.matchEvery(/\.dat\.gz$/); | ||
|
||
res.should.only.have.keys(...constantProps, ...datFiles); | ||
|
||
const keysJson = JSON.parse(res['keys.json']); | ||
keysJson.should.only.have.keys('iv', 'local', 'privkey', 'pubkey', 'salt'); | ||
keysJson.iv.should.be.a.String(); | ||
keysJson.privkey.should.be.a.String(); | ||
keysJson.pubkey.should.be.a.String(); | ||
keysJson.salt.should.be.a.String(); | ||
keysJson.local.should.only.have.keys('key', 'ivs'); | ||
keysJson.local.key.should.be.a.String(); | ||
keysJson.local.ivs.should.only.have.keys('toc.dat', ...datFiles); | ||
})))); | ||
}); | ||
}); | ||
|