Introduce channel arg to disable authority filter

pull/14893/head
Muxi Yan 7 years ago
parent 834aeca180
commit dfbf607ccb
  1. 3
      include/grpc/impl/codegen/grpc_types.h
  2. 11
      src/core/ext/filters/http/client_authority_filter.cc
  3. 11
      src/objective-c/GRPCClient/private/GRPCHost.m
  4. 6
      src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.mm
  5. 14
      src/objective-c/tests/CronetUnitTests/CronetUnitTests.m
  6. 1
      src/objective-c/tests/Podfile

@ -333,6 +333,9 @@ typedef struct {
/** Channel arg that carries the bridged objective c object for custom metrics
* logging filter. */
#define GRPC_ARG_MOBILE_LOG_CONFIG "grpc.mobile_log_config"
/** If non-zero, client authority filter is disabled for the channel */
#define GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER \
"grpc.disable_client_authority_filter"
/** \} */
/** Result of a grpc call. If the caller satisfies the prerequisites of a

@ -129,6 +129,17 @@ const grpc_channel_filter grpc_client_authority_filter = {
static bool add_client_authority_filter(grpc_channel_stack_builder* builder,
void* arg) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* disable_client_authority_filter_arg = grpc_channel_args_find(
channel_args, GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
if (disable_client_authority_filter_arg != nullptr) {
const bool is_client_authority_filter_disabled =
grpc_channel_arg_get_bool(disable_client_authority_filter_arg, false);
if (is_client_authority_filter_disabled) {
return true;
}
}
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}

@ -192,7 +192,7 @@ static NSMutableDictionary *kHostCache;
return YES;
}
- (NSDictionary *)channelArgs {
- (NSDictionary *)channelArgsUsingCronet:(BOOL)useCronet {
NSMutableDictionary *args = [NSMutableDictionary dictionary];
// TODO(jcanizales): Add OS and device information (see
@ -226,14 +226,19 @@ static NSMutableDictionary *kHostCache;
args[@GRPC_ARG_MOBILE_LOG_CONFIG] = logConfig;
}
if (useCronet) {
args[@GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER] = [NSNumber numberWithInt:1];
}
return args;
}
- (GRPCChannel *)newChannel {
NSDictionary *args = [self channelArgs];
BOOL useCronet = NO;
#ifdef GRPC_COMPILE_WITH_CRONET
BOOL useCronet = [GRPCCall isUsingCronet];
useCronet = [GRPCCall isUsingCronet];
#endif
NSDictionary *args = [self channelArgsUsingCronet:useCronet];
if (_secure) {
GRPCChannel *channel;
@synchronized(self) {

@ -82,8 +82,14 @@ static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
stream_engine *cronetEngine) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
grpc_arg arg;
arg.key = const_cast<char*>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
arg.type = GRPC_ARG_INTEGER;
arg.value.integer = 1;
client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1);
f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr,
client_args, NULL);
grpc_channel_args_destroy(client_args);
GPR_ASSERT(f->client != NULL);
}

@ -126,6 +126,14 @@ unsigned int parse_h2_length(const char *field) {
((unsigned int)(unsigned char)(field[2]));
}
grpc_channel_args *add_disable_client_authority_filter_args(grpc_channel_args *args) {
grpc_arg arg;
arg.key = const_cast<char*>(GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER);
arg.type = GRPC_ARG_INTEGER;
arg.value.integer = 1;
return grpc_channel_args_copy_and_add(args, &arg, 1);
}
- (void)testInternalError {
grpc_call *c;
grpc_slice request_payload_slice =
@ -147,8 +155,10 @@ unsigned int parse_h2_length(const char *field) {
gpr_join_host_port(&addr, "127.0.0.1", port);
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
stream_engine *cronetEngine = [Cronet getGlobalEngine];
grpc_channel_args *client_args = add_disable_client_authority_filter_args(NULL);
grpc_channel *client =
grpc_cronet_secure_channel_create(cronetEngine, addr, NULL, NULL);
grpc_cronet_secure_channel_create(cronetEngine, addr, client_args, NULL);
grpc_channel_args_destroy(client_args);
cq_verifier *cqv = cq_verifier_create(cq);
grpc_op ops[6];
@ -262,6 +272,8 @@ unsigned int parse_h2_length(const char *field) {
arg.type = GRPC_ARG_INTEGER;
arg.value.integer = useCoalescing ? 1 : 0;
grpc_channel_args *args = grpc_channel_args_copy_and_add(NULL, &arg, 1);
args = add_disable_client_authority_filter_args(args);
grpc_call *c;
grpc_slice request_payload_slice =
grpc_slice_from_copied_string("hello world");

@ -8,7 +8,6 @@ GRPC_LOCAL_SRC = '../../..'
# Install the dependencies in the main target plus all test targets.
%w(
Tests
AllTests
RxLibraryUnitTests
InteropTestsRemote

Loading…
Cancel
Save