1 /* 2 * 3 * Copyright 2016 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 #ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H 20 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <string.h> 25 26 #include "src/core/lib/security/credentials/credentials.h" 27 28 #define GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS \ 29 "grpc.fake_security.expected_targets" 30 31 /* -- Fake transport security credentials. -- */ 32 33 /* Creates a fake transport security credentials object for testing. */ 34 grpc_channel_credentials* grpc_fake_transport_security_credentials_create(void); 35 36 /* Creates a fake server transport security credentials object for testing. */ 37 grpc_server_credentials* grpc_fake_transport_security_server_credentials_create( 38 void); 39 40 /* Used to verify the target names given to the fake transport security 41 * connector. 42 * 43 * The syntax of \a expected_targets by example: 44 * For LB channels: 45 * "backend_target_1,backend_target_2,...;lb_target_1,lb_target_2,..." 46 * For regular channels: 47 * "backend_taget_1,backend_target_2,..." 48 * 49 * That is to say, LB channels have a heading list of LB targets separated from 50 * the list of backend targets by a semicolon. For non-LB channels, only the 51 * latter is present. */ 52 grpc_arg grpc_fake_transport_expected_targets_arg(char* expected_targets); 53 54 /* Return the value associated with the expected targets channel arg or NULL */ 55 const char* grpc_fake_transport_get_expected_targets( 56 const grpc_channel_args* args); 57 58 /* -- Metadata-only Test credentials. -- */ 59 60 class grpc_md_only_test_credentials : public grpc_call_credentials { 61 public: grpc_md_only_test_credentials(const char * md_key,const char * md_value,bool is_async)62 grpc_md_only_test_credentials(const char* md_key, const char* md_value, 63 bool is_async) 64 : grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_OAUTH2, 65 GRPC_SECURITY_NONE), 66 md_(grpc_mdelem_from_slices(grpc_slice_from_copied_string(md_key), 67 grpc_slice_from_copied_string(md_value))), 68 is_async_(is_async) {} ~grpc_md_only_test_credentials()69 ~grpc_md_only_test_credentials() override { GRPC_MDELEM_UNREF(md_); } 70 71 bool get_request_metadata(grpc_polling_entity* pollent, 72 grpc_auth_metadata_context context, 73 grpc_credentials_mdelem_array* md_array, 74 grpc_closure* on_request_metadata, 75 grpc_error** error) override; 76 77 void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array, 78 grpc_error* error) override; 79 debug_string()80 std::string debug_string() override { return "MD only Test Credentials"; }; 81 82 private: 83 grpc_mdelem md_; 84 bool is_async_; 85 }; 86 87 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H */ 88