Skip to content

Commit 83e58a1

Browse files
author
Kerkesni
committed
add unit tests
Issue: CLDSRV-618
1 parent 112c0a6 commit 83e58a1

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

tests/unit/management/configuration.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getConfig() {
3636

3737
// Original Config
3838
const overlayVersionOriginal = Object.assign({}, config.overlayVersion);
39-
const authDataOriginal = Object.assign({}, config.authData);
39+
const authDataOriginal = Object.assign({}, config.authData).accounts;
4040
const locationConstraintsOriginal = Object.assign({},
4141
config.locationConstraints);
4242
const restEndpointsOriginal = Object.assign({}, config.restEndpoints);
@@ -48,10 +48,12 @@ const publicInstanceId = crypto.createHash('sha256')
4848

4949
function resetConfig() {
5050
config.overlayVersion = overlayVersionOriginal;
51-
config.authData = authDataOriginal;
51+
config.authData = { accounts: authDataOriginal };
5252
config.locationConstraints = locationConstraintsOriginal;
5353
config.restEndpoints = restEndpointsOriginal;
5454
config.browserAccessEnabled = browserAccessEnabledOriginal;
55+
// reset auth data inside the in-memory vault backend
56+
config.emit('authdata-update');
5557
}
5658

5759
function assertConfig(actualConf, expectedConf) {
@@ -70,6 +72,9 @@ describe('patchConfiguration', () => {
7072
beforeEach(() => {
7173
resetConfig();
7274
});
75+
after(() => {
76+
resetConfig();
77+
});
7378

7479
it('should modify config using the new config', done => {
7580
const newConf = {

tests/unit/routes/routeBackbeat.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,64 @@ describe('routeBackbeat', () => {
220220
assert.deepStrictEqual(mockResponse.body, {});
221221
});
222222

223+
it('should put metadata after updating account info', async () => {
224+
mockRequest.method = 'PUT';
225+
mockRequest.url = '/_/backbeat/metadata/bucket0/key0'+
226+
'?accountId=123456789012&versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf';
227+
mockRequest.headers = {
228+
'x-scal-versioning-required': 'true',
229+
};
230+
mockRequest.destroy = () => {};
231+
232+
sandbox.stub(metadata, 'putObjectMD').callsFake((bucketName, objectKey, omVal, options, logParam, cb) => {
233+
assert.strictEqual(omVal['owner-display-name'], 'Bart');
234+
assert.strictEqual(omVal['owner-id'], '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be');
235+
cb(null, {});
236+
});
237+
238+
metadataUtils.standardMetadataValidateBucketAndObj.callsFake((params, denies, log, callback) => {
239+
const bucketInfo = {
240+
getVersioningConfiguration: () => ({ Status: 'Enabled' }),
241+
isVersioningEnabled: () => true,
242+
};
243+
const objMd = {};
244+
callback(null, bucketInfo, objMd);
245+
});
246+
247+
routeBackbeat('127.0.0.1', mockRequest, mockResponse, log);
248+
249+
void await endPromise;
250+
251+
assert.strictEqual(mockResponse.statusCode, 200);
252+
assert.deepStrictEqual(mockResponse.body, {});
253+
});
254+
255+
it('should fail to put metadata when accountId is invalid', async () => {
256+
mockRequest.method = 'PUT';
257+
mockRequest.url = '/_/backbeat/metadata/bucket0/key0'+
258+
'?accountId=invalid&versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf';
259+
mockRequest.headers = {
260+
'x-scal-versioning-required': 'true',
261+
};
262+
mockRequest.destroy = () => {};
263+
264+
metadataUtils.standardMetadataValidateBucketAndObj.callsFake((params, denies, log, callback) => {
265+
const bucketInfo = {
266+
getVersioningConfiguration: () => ({ Status: 'Enabled' }),
267+
isVersioningEnabled: () => true,
268+
};
269+
const objMd = {};
270+
callback(null, bucketInfo, objMd);
271+
});
272+
273+
routeBackbeat('127.0.0.1', mockRequest, mockResponse, log);
274+
275+
void await endPromise;
276+
277+
assert.strictEqual(mockResponse.statusCode, 404);
278+
assert.deepStrictEqual(mockResponse.body.code, 'AccountNotFound');
279+
});
280+
223281
it('should handle error when putting metadata', async () => {
224282
mockRequest.method = 'PUT';
225283
mockRequest.url = '/_/backbeat/metadata/bucket0/key0';

0 commit comments

Comments
 (0)