Skip to content

Commit

Permalink
[6.5] Handle deprecated SSL config settings. (#26208)
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin authored Nov 26, 2018
1 parent 6649097 commit b4aff5a
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 8 deletions.
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

0 comments on commit b4aff5a

Please sign in to comment.