Skip to content

Commit

Permalink
Merge pull request #1690 from murgatroid99/grpc-js_auth_error_codes
Browse files Browse the repository at this point in the history
grpc-js: Don't propagate non-numeric errors from auth plugins
  • Loading branch information
murgatroid99 committed Feb 17, 2021
2 parents 24d1a04 + 40c19ea commit a45c5c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.2.7",
"version": "1.2.8",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
12 changes: 11 additions & 1 deletion packages/grpc-js/src/call-credentials-filter.ts
Expand Up @@ -21,6 +21,7 @@ import { BaseFilter, Filter, FilterFactory } from './filter';
import { Metadata } from './metadata';
import { Status } from './constants';
import { splitHostPort } from './uri-parser';
import { ServiceError } from './call';

export class CallCredentialsFilter extends BaseFilter implements Filter {
private serviceUrl: string;
Expand Down Expand Up @@ -51,12 +52,21 @@ export class CallCredentialsFilter extends BaseFilter implements Filter {
service_url: this.serviceUrl,
});
const resultMetadata = await metadata;
resultMetadata.merge(await credsMetadata);
try {
resultMetadata.merge(await credsMetadata);
} catch (error) {
this.stream.cancelWithStatus(
Status.UNAUTHENTICATED,
`Failed to retrieve auth metadata with error: ${error.message}`
);
return Promise.reject<Metadata>('Failed to retrieve auth metadata');
}
if (resultMetadata.get('authorization').length > 1) {
this.stream.cancelWithStatus(
Status.INTERNAL,
'"authorization" metadata cannot have multiple values'
);
return Promise.reject<Metadata>('"authorization" metadata cannot have multiple values');
}
return resultMetadata;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/src/channel.ts
Expand Up @@ -384,7 +384,7 @@ export class ChannelImplementation implements Channel {
(error: Error & { code: number }) => {
// We assume the error code isn't 0 (Status.OK)
callStream.cancelWithStatus(
error.code || Status.UNKNOWN,
(typeof error.code === 'number') ? error.code : Status.UNKNOWN,
`Getting metadata from plugin failed with error: ${error.message}`
);
}
Expand Down

0 comments on commit a45c5c3

Please sign in to comment.