Skip to content

Commit bd2bcca

Browse files
committed
Merge branch 'feature/CLDSRV-886-configurable-server-header' into q/9.2
2 parents 030a944 + 34362d9 commit bd2bcca

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
@@ -972,6 +972,8 @@ class Config extends EventEmitter {
972972
'bad config: internalPort must be a positive integer');
973973
}
974974

975+
this.serverHeader = config.serverHeader || 'S3 Server';
976+
975977
this.port = config.port;
976978
this.listenOn = this._parseEndpoints(config.listenOn, 'listenOn');
977979
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
@@ -21,7 +21,7 @@
2121
"dependencies": {
2222
"@azure/storage-blob": "^12.28.0",
2323
"@hapi/joi": "^17.1.1",
24-
"arsenal": "git+https://github.com/scality/arsenal#8.2.48",
24+
"arsenal": "git+https://github.com/scality/arsenal#8.2.50",
2525
"async": "2.6.4",
2626
"aws-sdk": "^2.1692.0",
2727
"bucketclient": "scality/bucketclient#8.2.7",

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
@@ -983,4 +983,31 @@ describe('Config', () => {
983983
assert.throws(() => new ConfigObject());
984984
});
985985
});
986+
987+
describe('serverHeader', () => {
988+
let sandbox;
989+
let readFileStub;
990+
991+
beforeEach(() => {
992+
sandbox = sinon.createSandbox();
993+
readFileStub = sandbox.stub(fs, 'readFileSync');
994+
readFileStub.callThrough();
995+
});
996+
997+
afterEach(() => {
998+
sandbox.restore();
999+
});
1000+
1001+
it('should default to "S3 Server" when not configured', () => {
1002+
const config = new ConfigObject();
1003+
assert.strictEqual(config.serverHeader, 'S3 Server');
1004+
});
1005+
1006+
it('should use the configured value when set', () => {
1007+
const modifiedConfig = { ...defaultConfig, serverHeader: 'ScalityS3' };
1008+
readFileStub.withArgs(sinon.match(/config.json$/)).returns(JSON.stringify(modifiedConfig));
1009+
const config = new ConfigObject();
1010+
assert.strictEqual(config.serverHeader, 'ScalityS3');
1011+
});
1012+
});
9861013
});

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,9 +1527,9 @@ arraybuffer.prototype.slice@^1.0.4:
15271527
optionalDependencies:
15281528
ioctl "^2.0.2"
15291529

1530-
"arsenal@git+https://github.com/scality/arsenal#8.2.48":
1531-
version "8.2.48"
1532-
resolved "git+https://github.com/scality/arsenal#362f7908b6126709add96ee981d5235d96bab58c"
1530+
"arsenal@git+https://github.com/scality/arsenal#8.2.50":
1531+
version "8.2.50"
1532+
resolved "git+https://github.com/scality/arsenal#2b0a8026cb62e0f6a621738e78f5e9fcc977275e"
15331533
dependencies:
15341534
"@azure/identity" "^4.13.0"
15351535
"@azure/storage-blob" "^12.28.0"

0 commit comments

Comments
 (0)