Skip to content

Commit

Permalink
Add test for /backup
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Nov 27, 2024
1 parent 1c7ea7a commit 8bbbe81
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/integration/api/backup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
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));
datFiles.length.should.be.greaterThan(0);
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);
}))));
});
});

0 comments on commit 8bbbe81

Please sign in to comment.