Skip to content

Commit 97b490a

Browse files
authored
Merge pull request #2926 from murgatroid99/grpc-js_reject_unauthorized_fix
grpc-js: Don't check authorized when rejectUnauthorized is false
2 parents 5572bbd + 18fddad commit 97b490a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/grpc-js/src/channel-credentials.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class SecureConnectorImpl implements SecureConnector {
268268
};
269269
return new Promise<SecureConnectResult>((resolve, reject) => {
270270
const tlsSocket = tlsConnect(tlsConnectOptions, () => {
271-
if (!tlsSocket.authorized) {
271+
if ((this.connectionOptions.rejectUnauthorized ?? true) && !tlsSocket.authorized) {
272272
reject(tlsSocket.authorizationError);
273273
return;
274274
}
@@ -364,7 +364,7 @@ class CertificateProviderChannelCredentialsImpl extends ChannelCredentials {
364364
const tlsSocket = tlsConnect(tlsConnectOptions, () => {
365365
tlsSocket.removeListener('close', closeCallback);
366366
tlsSocket.removeListener('error', errorCallback);
367-
if (!tlsSocket.authorized) {
367+
if ((this.parent.verifyOptions.rejectUnauthorized ?? true) && !tlsSocket.authorized) {
368368
reject(tlsSocket.authorizationError);
369369
return;
370370
}

packages/grpc-js/test/test-channel-credentials.ts

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ describe('ChannelCredentials usage', () => {
218218
}
219219
);
220220
});
221+
it('Should accept self-signed certs with acceptUnauthorized', done => {
222+
const client = new echoService(`localhost:${portNum}`, grpc.credentials.createSsl(null, null, null, {rejectUnauthorized: false}));
223+
client.echo({ value: 'test value', value2: 3 }, (error: ServiceError | null, response: any) => {
224+
client.close();
225+
assert.ifError(error);
226+
assert.deepStrictEqual(response, { value: 'test value', value2: 3 });
227+
done();
228+
});
229+
});
221230
});
222231

223232
describe('Channel credentials mtls', () => {

0 commit comments

Comments
 (0)