Skip to content

Commit

Permalink
coverage improvement and post reviews fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Feb 7, 2025
1 parent 909eb1a commit 2f3c20d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 28 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Arsenal

[![Public Build Status](https://github.com/scality/Arsenal/actions/workflows/tests.yaml/badge.svg)](https://github.com/scality/Arsenal/actions/workflows/tests.yaml)
[![codecov](https://codecov.io/gh/scality/Arsenal/branch/development/8.1/graph/badge.svg)](https://codecov.io/gh/scality/Arsenal)

Common utilities for the S3 project components

Within this repository, you will be able to find the shared libraries for the
Expand Down Expand Up @@ -153,4 +156,4 @@ to the process (which results in an immediate termination, and this signal
can't be caught).

[badgepub]: https://github.com/scality/Arsenal/actions/workflows/tests.yaml/badge.svg
[codecov]: https://codecov.io/gh/scality/Arsenal/branch/development/8.1/graph/badge.svg?token=X0esXhJSwb
[codecov]: https://codecov.io/gh/scality/Arsenal/branch/development/8.1/graph/badge.svg
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default tseslint.config(
'camelcase': 'off',
'no-param-reassign': 'off',
'new-cap': 'off',
'quotes': 'off',
'@typescript-eslint/no-unsafe-function-type':'off'
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/auth/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ function vaultSignatureCb(
{ errorMessage: err });
return callback(err);
}

const { ...userInfoWithoutEmail } = authInfo.message.body.userInfo;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { email: _, ...userInfoWithoutEmail } = authInfo.message.body.userInfo;
log.debug('received info from Vault', {
...authInfo,
message: {
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/v4/awsURIencode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function awsURIencode(
if (typeof input !== 'string') {
return '';
}
let encoded = '';
let encoded = "";
const slash = encodeSlash === undefined || encodeSlash ? '%2F' : '/';
const star = noEncodeStar !== undefined && noEncodeStar ? '*' : '%2A';
for (let i = 0; i < input.length; i++) {
Expand Down
12 changes: 6 additions & 6 deletions lib/network/kmsAWS/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export default class Client {
}

if (!data) {
const error = arsenalErrorAWSKMS('failed to generate data key: empty response');
logger.error('AWS KMS: failed to generate data key: empty response');
const error = arsenalErrorAWSKMS("failed to generate data key: empty response");
logger.error("AWS KMS: failed to generate data key: empty response");
cb(error);
return;
}
Expand Down Expand Up @@ -212,8 +212,8 @@ export default class Client {
}

if (!data) {
const error = arsenalErrorAWSKMS('failed to cipher data key: empty response');
logger.error('AWS KMS: failed to cipher data key: empty response');
const error = arsenalErrorAWSKMS("failed to cipher data key: empty response");
logger.error("AWS KMS: failed to cipher data key: empty response");
cb(error);
return;
}
Expand Down Expand Up @@ -247,8 +247,8 @@ export default class Client {
}

if (!data) {
const error = arsenalErrorAWSKMS('failed to decipher data key: empty response');
logger.error('AWS KMS: failed to decipher data key: empty response');
const error = arsenalErrorAWSKMS("failed to decipher data key: empty response");
logger.error("AWS KMS: failed to decipher data key: empty response");
cb(error);
return;
}
Expand Down
34 changes: 17 additions & 17 deletions lib/storage/metadata/mongoclient/MongoClientInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,6 @@ class MongoClientInterface {
// a master or re-delete it in between so place an
// atomic condition on the PHD flag and the mst
// version:

const filter = {
'value.isPHD': true,
'value.versionId': mst.versionId,
Expand Down Expand Up @@ -2587,7 +2586,8 @@ class MongoClientInterface {
bucketCount,
bucketInfos,
});
})).catch(err => {
})
).catch(err => {
log.error('could not get list of collections', {

Check warning on line 2591 in lib/storage/metadata/mongoclient/MongoClientInterface.ts

View check run for this annotation

Codecov / codecov/patch

lib/storage/metadata/mongoclient/MongoClientInterface.ts#L2590-L2591

Added lines #L2590 - L2591 were not covered by tests
method: 'getBucketInfos',
error: err,
Expand Down Expand Up @@ -2646,7 +2646,6 @@ class MongoClientInterface {
}

consolidateData(store, dataManaged) {

if (dataManaged && dataManaged.locations && dataManaged.total) {
const locations = dataManaged.locations;
store.dataManaged.total.curr += dataManaged.total.curr;
Expand Down Expand Up @@ -2976,21 +2975,22 @@ class MongoClientInterface {
collRes[targetData][site] = data[site];
}
});
}).then(() => {
const bucketStatus = bucketInfo.getVersioningConfiguration();
const isVer = (bucketStatus &&
(bucketStatus.Status === 'Enabled' ||
bucketStatus.Status === 'Suspended'));
const retResult = this._handleResults(collRes, isVer);
retResult.stalled = stalledCount;
return callback(null, retResult);
}).catch(err => {
log.error('Error when processing mongo entries', {
method: 'getObjectMDStats',
error: err,
})
.then(() => {

Check warning on line 2979 in lib/storage/metadata/mongoclient/MongoClientInterface.ts

View check run for this annotation

Codecov / codecov/patch

lib/storage/metadata/mongoclient/MongoClientInterface.ts#L2979

Added line #L2979 was not covered by tests
const bucketStatus = bucketInfo.getVersioningConfiguration();
const isVer = (bucketStatus &&
(bucketStatus.Status === 'Enabled' ||
bucketStatus.Status === 'Suspended'));

Check warning on line 2983 in lib/storage/metadata/mongoclient/MongoClientInterface.ts

View check run for this annotation

Codecov / codecov/patch

lib/storage/metadata/mongoclient/MongoClientInterface.ts#L2982-L2983

Added lines #L2982 - L2983 were not covered by tests
const retResult = this._handleResults(collRes, isVer);
retResult.stalled = stalledCount;
return callback(null, retResult);
}).catch(err => {
log.error('Error when processing mongo entries', {
method: 'getObjectMDStats',
error: err,
});
return callback(err);
});
return callback(err);
});
}

getIngestionBuckets(log: werelogs.Logger, cb: ArsenalCallback<BucketInfo[]>) {
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/policyEvaluator/RequestContext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,26 @@ describe('RequestContext', () => {
const ssoRC = new RequestContext(...ssoParams);
assert.strictEqual(ssoRC.getResource(), 'arn:scality:sso:::general-resource/specific-resource');
});

it('should return correct ARN for s3 service without specific resource', () => {
const s3Params = [...constructorParams];
s3Params[3] = undefined; // specificResource
const s3RC = new RequestContext(...s3Params);
assert.strictEqual(s3RC.getResource(), 'arn:aws:s3:::general-resource');
});

it('should return correct ARN for s3 service without general and specific resource', () => {
const s3Params = [...constructorParams];
s3Params[2] = undefined; // generalResource
s3Params[3] = undefined; // specificResource
const s3RC = new RequestContext(...s3Params);
assert.strictEqual(s3RC.getResource(), 'arn:aws:s3:::');
});

it('should return undefined for unknown service', () => {
const unknownParams = [...constructorParams];
unknownParams[7] = 'unknown';
const unknownRC = new RequestContext(...unknownParams);
assert.strictEqual(unknownRC.getResource(), undefined);
});
});
34 changes: 34 additions & 0 deletions tests/unit/s3routes/routeGET.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,38 @@ describe('routerGET', () => {
new ArsenalError('InternalError'), statsClient,
);
});

it('should call the appropriate bucket query methods based on query parameters', () => {
const queryMethods = {
acl: 'bucketGetACL',
replication: 'bucketGetReplication',
cors: 'bucketGetCors',
versioning: 'bucketGetVersioning',
website: 'bucketGetWebsite',
tagging: 'bucketGetTagging',
lifecycle: 'bucketGetLifecycle',
uploads: 'listMultipartUploads',
location: 'bucketGetLocation',
policy: 'bucketGetPolicy',
'object-lock': 'bucketGetObjectLock',
notification: 'bucketGetNotification',
encryption: 'bucketGetEncryption',
search: 'metadataSearch',
};

Object.keys(queryMethods).forEach(queryParam => {
request.bucketName = 'bucketName';
request.objectKey = undefined;
request.query = { [queryParam]: true };

routerGET(request, response, api, log, statsClient, dataRetrievalParams);

expect(api.callApiMethod).toHaveBeenCalledWith(
queryMethods[queryParam], request, response, log, expect.any(Function),
);

api.callApiMethod.mockClear();
});
});

});

0 comments on commit 2f3c20d

Please sign in to comment.