Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecated SSL config settings. #26196

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`#get correctly handles server config. 1`] = `
exports[`#get correctly handles server config.: default 1`] = `
Object {
"autoListen": true,
"basePath": "/abc",
Expand All @@ -17,6 +17,57 @@ Object {
}
`;

exports[`#get correctly handles server config.: deprecated missing ssl.enabled 1`] = `
Object {
"autoListen": true,
"basePath": "/abc",
"cors": false,
"host": "host",
"maxPayload": 1000,
"port": 1234,
"rewriteBasePath": false,
"ssl": Object {
"certificate": "cert",
"enabled": true,
"key": "key",
},
}
`;

exports[`#get correctly handles server config.: deprecated ssl.cert 1`] = `
Object {
"autoListen": true,
"basePath": "/abc",
"cors": false,
"host": "host",
"maxPayload": 1000,
"port": 1234,
"rewriteBasePath": false,
"ssl": Object {
"certificate": "deprecated-cert",
"enabled": true,
"key": "key",
},
}
`;

exports[`#get correctly handles server config.: disabled ssl 1`] = `
Object {
"autoListen": true,
"basePath": "/abc",
"cors": false,
"host": "host",
"maxPayload": 1000,
"port": 1234,
"rewriteBasePath": false,
"ssl": Object {
"certificate": "cert",
"enabled": false,
"key": "key",
},
}
`;

exports[`#get correctly handles silent logging config. 1`] = `
Object {
"appenders": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,59 @@ describe('#get', () => {
maxPayloadBytes: 1000,
port: 1234,
rewriteBasePath: false,
ssl: {
enabled: true,
keyPassphrase: 'some-phrase',
someNewValue: 'new',
},
ssl: { enabled: true, keyPassphrase: 'some-phrase', someNewValue: 'new' },
someNotSupportedValue: 'val',
},
});

expect(configAdapter.get('server')).toMatchSnapshot();
const configAdapterWithDisabledSSL = new LegacyObjectToConfigAdapter({
server: {
autoListen: true,
basePath: '/abc',
cors: false,
host: 'host',
maxPayloadBytes: 1000,
port: 1234,
rewriteBasePath: false,
ssl: { enabled: false, certificate: 'cert', key: 'key' },
someNotSupportedValue: 'val',
},
});

const configAdapterWithCert = new LegacyObjectToConfigAdapter({
server: {
autoListen: true,
basePath: '/abc',
cors: false,
host: 'host',
maxPayloadBytes: 1000,
port: 1234,
rewriteBasePath: false,
ssl: { enabled: true, cert: 'deprecated-cert', key: 'key' },
someNotSupportedValue: 'val',
},
});

const configAdapterWithoutSSLEnabled = new LegacyObjectToConfigAdapter({
server: {
autoListen: true,
basePath: '/abc',
cors: false,
host: 'host',
maxPayloadBytes: 1000,
port: 1234,
rewriteBasePath: false,
ssl: { certificate: 'cert', key: 'key' },
someNotSupportedValue: 'val',
},
});

expect(configAdapter.get('server')).toMatchSnapshot('default');
expect(configAdapterWithDisabledSSL.get('server')).toMatchSnapshot('disabled ssl');
expect(configAdapterWithCert.get('server')).toMatchSnapshot('deprecated ssl.cert');
expect(configAdapterWithoutSSLEnabled.get('server')).toMatchSnapshot(
'deprecated missing ssl.enabled'
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,26 @@ export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
maxPayload: configValue.maxPayloadBytes,
port: configValue.port,
rewriteBasePath: configValue.rewriteBasePath,
ssl: configValue.ssl,
ssl: configValue.ssl && LegacyObjectToConfigAdapter.transformSSL(configValue.ssl),
};
}

private static transformSSL(configValue: Record<string, any>) {
// `server.ssl.cert` is deprecated, legacy platform will issue deprecation warning.
if (configValue.cert) {
configValue.certificate = configValue.cert;
delete configValue.cert;
}

// Enabling ssl by only specifying server.ssl.certificate and server.ssl.key is deprecated,
// legacy platform will issue deprecation warning.
if (typeof configValue.enabled !== 'boolean' && configValue.certificate && configValue.key) {
configValue.enabled = true;
}

return configValue;
}

public get(configPath: ConfigPath) {
const configValue = super.get(configPath);
switch (configPath) {
Expand Down