1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.client5.testing.async;
28
29 import java.util.Arrays;
30 import java.util.Collection;
31
32 import org.apache.hc.client5.http.AuthenticationStrategy;
33 import org.apache.hc.client5.http.auth.AuthSchemeFactory;
34 import org.apache.hc.client5.http.config.RequestConfig;
35 import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
36 import org.apache.hc.client5.http.impl.async.H2AsyncClientBuilder;
37 import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
38 import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
39 import org.apache.hc.client5.testing.SSLTestContexts;
40 import org.apache.hc.core5.http.HttpVersion;
41 import org.apache.hc.core5.http.URIScheme;
42 import org.apache.hc.core5.http.config.Lookup;
43 import org.junit.Rule;
44 import org.junit.rules.ExternalResource;
45 import org.junit.runner.RunWith;
46 import org.junit.runners.Parameterized;
47
48 @RunWith(Parameterized.class)
49 public class TestH2ClientAuthentication extends AbstractHttpAsyncClientAuthentication<CloseableHttpAsyncClient> {
50
51 @Parameterized.Parameters(name = "HTTP/2 {0}")
52 public static Collection<Object[]> protocols() {
53 return Arrays.asList(new Object[][]{
54 {URIScheme.HTTP},
55 {URIScheme.HTTPS},
56 });
57 }
58
59 protected H2AsyncClientBuilder clientBuilder;
60 protected PoolingAsyncClientConnectionManager connManager;
61
62 @Rule
63 public ExternalResource clientResource = new ExternalResource() {
64
65 @Override
66 protected void before() throws Throwable {
67 clientBuilder = H2AsyncClientBuilder.create()
68 .setDefaultRequestConfig(RequestConfig.custom()
69 .setConnectionRequestTimeout(TIMEOUT)
70 .setConnectTimeout(TIMEOUT)
71 .build())
72 .setTlsStrategy(new DefaultClientTlsStrategy(SSLTestContexts.createClientSSLContext()));
73 }
74
75 };
76
77 public TestH2ClientAuthentication(final URIScheme scheme) {
78 super(scheme, HttpVersion.HTTP_2);
79 }
80
81 @Override
82 void setDefaultAuthSchemeRegistry(final Lookup<AuthSchemeFactory> authSchemeRegistry) {
83 clientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
84 }
85
86 @Override
87 void setTargetAuthenticationStrategy(final AuthenticationStrategy targetAuthStrategy) {
88 clientBuilder.setTargetAuthenticationStrategy(targetAuthStrategy);
89 }
90
91 @Override
92 protected CloseableHttpAsyncClient createClient() throws Exception {
93 return clientBuilder.build();
94 }
95
96 }