mirror of https://github.com/grpc/grpc-node.git
Merge pull request #1690 from murgatroid99/grpc-js_auth_error_codes
grpc-js: Don't propagate non-numeric errors from auth plugins
This commit is contained in:
commit
a45c5c314c
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
@ -51,12 +52,21 @@ export class CallCredentialsFilter extends BaseFilter implements Filter {
|
|||
service_url: this.serviceUrl,
|
||||
});
|
||||
const resultMetadata = await metadata;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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}`
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue