1 //
2 //
3 // Copyright 2015 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 #include <memory>
20
21 #include "absl/types/optional.h"
22 #include "gtest/gtest.h"
23
24 #include <grpc/impl/channel_arg_names.h>
25 #include <grpc/status.h>
26
27 #include "src/core/lib/channel/channel_args.h"
28 #include "src/core/lib/gprpp/time.h"
29 #include "test/core/end2end/end2end_tests.h"
30
31 namespace grpc_core {
32 namespace {
33
CORE_END2END_TEST(CoreClientChannelTest,CallHostOverride)34 CORE_END2END_TEST(CoreClientChannelTest, CallHostOverride) {
35 InitClient(ChannelArgs().Set(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
36 "foo.test.google.fr:1234"));
37 InitServer(ChannelArgs());
38 auto c = NewClientCall("/foo")
39 .Timeout(Duration::Seconds(30))
40 .Host("foo.test.google.fr:1234")
41 .Create();
42 EXPECT_NE(c.GetPeer(), absl::nullopt);
43 CoreEnd2endTest::IncomingStatusOnClient server_status;
44 CoreEnd2endTest::IncomingMetadata server_initial_metadata;
45 c.NewBatch(1)
46 .SendInitialMetadata({})
47 .SendCloseFromClient()
48 .RecvInitialMetadata(server_initial_metadata)
49 .RecvStatusOnClient(server_status);
50 auto s = RequestCall(101);
51 Expect(101, true);
52 Step();
53 EXPECT_NE(s.GetPeer(), absl::nullopt);
54 EXPECT_NE(c.GetPeer(), absl::nullopt);
55 CoreEnd2endTest::IncomingCloseOnServer client_close;
56 s.NewBatch(102)
57 .SendInitialMetadata({})
58 .SendStatusFromServer(GRPC_STATUS_UNIMPLEMENTED, "xyz", {})
59 .RecvCloseOnServer(client_close);
60 Expect(102, true);
61 Expect(1, true);
62 Step();
63 EXPECT_EQ(server_status.status(), GRPC_STATUS_UNIMPLEMENTED);
64 EXPECT_EQ(server_status.message(), "xyz");
65 EXPECT_EQ(s.method(), "/foo");
66 EXPECT_EQ(s.host(), "foo.test.google.fr:1234");
67 EXPECT_FALSE(client_close.was_cancelled());
68 }
69
70 } // namespace
71 } // namespace grpc_core
72