8
8
import static org .assertj .core .api .Assertions .assertThat ;
9
9
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
10
10
import static org .awaitility .Awaitility .await ;
11
+ import static org .junit .jupiter .api .Named .named ;
12
+ import static org .junit .jupiter .params .provider .Arguments .arguments ;
11
13
12
14
import com .linecorp .armeria .common .grpc .protocol .ArmeriaStatusException ;
13
15
import com .linecorp .armeria .server .ServerBuilder ;
16
18
import com .linecorp .armeria .testing .junit5 .server .SelfSignedCertificateExtension ;
17
19
import com .linecorp .armeria .testing .junit5 .server .ServerExtension ;
18
20
import io .github .netmikey .logunit .api .LogCapturer ;
21
+ import io .netty .handler .ssl .ClientAuth ;
19
22
import io .opentelemetry .internal .testing .slf4j .SuppressLogger ;
20
23
import io .opentelemetry .sdk .extension .trace .jaeger .proto .api_v2 .Sampling ;
21
24
import io .opentelemetry .sdk .extension .trace .jaeger .proto .api_v2 .Sampling .RateLimitingSamplingStrategy ;
29
32
import java .util .concurrent .CompletionStage ;
30
33
import java .util .concurrent .ConcurrentLinkedQueue ;
31
34
import java .util .concurrent .TimeUnit ;
35
+ import java .util .stream .Stream ;
32
36
import javax .annotation .Nullable ;
33
37
import org .awaitility .core .ThrowingRunnable ;
34
38
import org .junit .jupiter .api .BeforeEach ;
35
39
import org .junit .jupiter .api .Order ;
36
40
import org .junit .jupiter .api .Test ;
41
+ import org .junit .jupiter .api .extension .ExtensionContext ;
37
42
import org .junit .jupiter .api .extension .RegisterExtension ;
43
+ import org .junit .jupiter .params .ParameterizedTest ;
44
+ import org .junit .jupiter .params .provider .Arguments ;
45
+ import org .junit .jupiter .params .provider .ArgumentsProvider ;
46
+ import org .junit .jupiter .params .provider .ArgumentsSource ;
38
47
import org .slf4j .event .Level ;
39
48
import org .slf4j .event .LoggingEvent ;
40
49
@@ -61,7 +70,12 @@ private static void addGrpcError(int code, @Nullable String message) {
61
70
@ RegisterExtension
62
71
static final SelfSignedCertificateExtension certificate = new SelfSignedCertificateExtension ();
63
72
73
+ @ RegisterExtension
64
74
@ Order (2 )
75
+ static final SelfSignedCertificateExtension clientCertificate =
76
+ new SelfSignedCertificateExtension ();
77
+
78
+ @ Order (3 )
65
79
@ RegisterExtension
66
80
static final ServerExtension server =
67
81
new ServerExtension () {
@@ -98,6 +112,11 @@ protected CompletionStage<byte[]> handleMessage(
98
112
sb .http (0 );
99
113
sb .https (0 );
100
114
sb .tls (certificate .certificateFile (), certificate .privateKeyFile ());
115
+ sb .tlsCustomizer (
116
+ ssl -> {
117
+ ssl .clientAuth (ClientAuth .OPTIONAL );
118
+ ssl .trustManager (clientCertificate .certificate ());
119
+ });
101
120
}
102
121
};
103
122
@@ -140,6 +159,36 @@ void tlsConnectionWorks() throws IOException {
140
159
}
141
160
}
142
161
162
+ @ ParameterizedTest
163
+ @ ArgumentsSource (ClientPrivateKeyProvider .class )
164
+ void clientTlsConnectionWorks (byte [] privateKey ) throws IOException {
165
+ try (JaegerRemoteSampler sampler =
166
+ JaegerRemoteSampler .builder ()
167
+ .setEndpoint (server .httpsUri ().toString ())
168
+ .setPollingInterval (1 , TimeUnit .SECONDS )
169
+ .setTrustedCertificates (Files .readAllBytes (certificate .certificateFile ().toPath ()))
170
+ .setClientTls (
171
+ privateKey , Files .readAllBytes (clientCertificate .certificateFile ().toPath ()))
172
+ .setServiceName (SERVICE_NAME )
173
+ .build ()) {
174
+
175
+ await ().untilAsserted (samplerIsType (sampler , RateLimitingSampler .class ));
176
+
177
+ // verify
178
+ assertThat (sampler .getDescription ()).contains ("RateLimitingSampler{999.00}" );
179
+ }
180
+ }
181
+
182
+ private static class ClientPrivateKeyProvider implements ArgumentsProvider {
183
+ @ Override
184
+ @ SuppressWarnings ("PrimitiveArrayPassedToVarargsMethod" )
185
+ public Stream <? extends Arguments > provideArguments (ExtensionContext context ) throws Exception {
186
+ return Stream .of (
187
+ arguments (named ("PEM" , Files .readAllBytes (clientCertificate .privateKeyFile ().toPath ()))),
188
+ arguments (named ("DER" , clientCertificate .privateKey ().getEncoded ())));
189
+ }
190
+ }
191
+
143
192
@ Test
144
193
void description () {
145
194
try (JaegerRemoteSampler sampler =
0 commit comments