Skip to content

Commit 2d32803

Browse files
committed
Merge branches 'w/9.4/feature/CLDSRV-886-configurable-server-header' and 'q/w/6141/9.3/feature/CLDSRV-886-configurable-server-header' into tmp/octopus/q/9.4
3 parents 2489923 + 1d2dd63 + b388fbd commit 2d32803

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

lib/Config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ class Config extends EventEmitter {
956956
'bad config: internalPort must be a positive integer');
957957
}
958958

959+
this.serverHeader = config.serverHeader || 'S3 Server';
960+
959961
this.port = config.port;
960962
this.listenOn = this._parseEndpoints(config.listenOn, 'listenOn');
961963
this.internalPort = config.internalPort;

lib/server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const https = require('https');
33
const cluster = require('cluster');
44
const { series } = require('async');
55
const arsenal = require('arsenal');
6+
const { setServerHeader } = arsenal.s3routes.routesUtils;
67
const { RedisClient, StatsClient } = arsenal.metrics;
78
const monitoringClient = require('./utilities/monitoringHandler');
89

@@ -34,6 +35,8 @@ const websiteEndpoints = _config.websiteEndpoints;
3435
let client = dataWrapper.client;
3536
const implName = dataWrapper.implName;
3637

38+
setServerHeader(_config.serverHeader);
39+
3740
let allEndpoints;
3841
function updateAllEndpoints() {
3942
allEndpoints = Object.keys(_config.restEndpoints);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@azure/storage-blob": "^12.28.0",
3434
"@hapi/joi": "^17.1.1",
3535
"@smithy/node-http-handler": "^3.0.0",
36-
"arsenal": "git+https://github.com/scality/Arsenal#8.3.8",
36+
"arsenal": "git+https://github.com/scality/Arsenal#8.3.9",
3737
"async": "2.6.4",
3838
"bucketclient": "scality/bucketclient#8.2.7",
3939
"bufferutil": "^4.0.8",

tests/functional/healthchecks/test/checkRoutes.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ if (config.healthChecks.enableInternalRoute) {
131131
});
132132
}
133133

134+
describe('Server response header', () => {
135+
it('should return the configured serverHeader value on S3 API responses', done => {
136+
const getOptions = deepCopy(options);
137+
getOptions.method = 'GET';
138+
getOptions.path = '/';
139+
getOptions.port = config.port || 8000;
140+
getOptions.agent = makeAgent();
141+
const req = transport.request(getOptions, res => {
142+
assert.strictEqual(res.headers['server'], config.serverHeader);
143+
done();
144+
});
145+
req.on('error', done);
146+
req.end();
147+
});
148+
});
149+
134150
describe('Healthcheck stats', () => {
135151
const totalReqs = 5;
136152
beforeEach(done => {

tests/unit/Config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,4 +987,31 @@ describe('Config', () => {
987987
assert.throws(() => new ConfigObject());
988988
});
989989
});
990+
991+
describe('serverHeader', () => {
992+
let sandbox;
993+
let readFileStub;
994+
995+
beforeEach(() => {
996+
sandbox = sinon.createSandbox();
997+
readFileStub = sandbox.stub(fs, 'readFileSync');
998+
readFileStub.callThrough();
999+
});
1000+
1001+
afterEach(() => {
1002+
sandbox.restore();
1003+
});
1004+
1005+
it('should default to "S3 Server" when not configured', () => {
1006+
const config = new ConfigObject();
1007+
assert.strictEqual(config.serverHeader, 'S3 Server');
1008+
});
1009+
1010+
it('should use the configured value when set', () => {
1011+
const modifiedConfig = { ...defaultConfig, serverHeader: 'ScalityS3' };
1012+
readFileStub.withArgs(sinon.match(/config.json$/)).returns(JSON.stringify(modifiedConfig));
1013+
const config = new ConfigObject();
1014+
assert.strictEqual(config.serverHeader, 'ScalityS3');
1015+
});
1016+
});
9901017
});

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6114,9 +6114,9 @@ arraybuffer.prototype.slice@^1.0.4:
61146114
optionalDependencies:
61156115
ioctl "^2.0.2"
61166116

6117-
"arsenal@git+https://github.com/scality/Arsenal#8.3.8":
6118-
version "8.3.8"
6119-
resolved "git+https://github.com/scality/Arsenal#ded10b14ec7e1cc4ab813a88439a27a74c7e2a19"
6117+
"arsenal@git+https://github.com/scality/Arsenal#8.3.9":
6118+
version "8.3.9"
6119+
resolved "git+https://github.com/scality/Arsenal#51e5b761f7f0612a722c828fa3d43b438c50ab7c"
61206120
dependencies:
61216121
"@aws-sdk/client-kms" "^3.975.0"
61226122
"@aws-sdk/client-s3" "^3.975.0"

0 commit comments

Comments
 (0)