1 // Copyright 2021 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GRPC_TEST_CORE_UTIL_MOCK_AUTHORIZATION_ENDPOINT_H 16 #define GRPC_TEST_CORE_UTIL_MOCK_AUTHORIZATION_ENDPOINT_H 17 18 #include <string> 19 20 #include "absl/strings/string_view.h" 21 22 #include <grpc/support/port_platform.h> 23 24 #include "src/core/lib/iomgr/endpoint.h" 25 26 namespace grpc_core { 27 28 class MockAuthorizationEndpoint : public grpc_endpoint { 29 public: MockAuthorizationEndpoint(absl::string_view local_uri,absl::string_view peer_uri)30 MockAuthorizationEndpoint(absl::string_view local_uri, 31 absl::string_view peer_uri) 32 : local_address_(local_uri), peer_address_(peer_uri) { 33 static constexpr grpc_endpoint_vtable vtable = { 34 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 35 nullptr, GetPeer, GetLocalAddress, nullptr, nullptr}; 36 grpc_endpoint::vtable = &vtable; 37 } 38 GetPeer(grpc_endpoint * ep)39 static absl::string_view GetPeer(grpc_endpoint* ep) { 40 MockAuthorizationEndpoint* m = 41 reinterpret_cast<MockAuthorizationEndpoint*>(ep); 42 return m->peer_address_; 43 } 44 GetLocalAddress(grpc_endpoint * ep)45 static absl::string_view GetLocalAddress(grpc_endpoint* ep) { 46 MockAuthorizationEndpoint* m = 47 reinterpret_cast<MockAuthorizationEndpoint*>(ep); 48 return m->local_address_; 49 } 50 SetPeer(absl::string_view peer_address)51 void SetPeer(absl::string_view peer_address) { 52 peer_address_ = std::string(peer_address); 53 } 54 SetLocalAddress(absl::string_view local_address)55 void SetLocalAddress(absl::string_view local_address) { 56 local_address_ = std::string(local_address); 57 } 58 59 private: 60 std::string local_address_; 61 std::string peer_address_; 62 }; 63 64 } // namespace grpc_core 65 66 #endif // GRPC_TEST_CORE_UTIL_MOCK_AUTHORIZATION_ENDPOINT_H 67