Skip to content

Commit 3af32fa

Browse files
author
Stephane Landelle
committed
Upgrade Jetty 9 and clean tests
1 parent 311aafa commit 3af32fa

File tree

100 files changed

+1864
-2571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1864
-2571
lines changed

api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ public final static MultipartRequestEntity createMultipartRequestEntity(List<Par
379379
return new MultipartRequestEntity(parts, requestHeaders);
380380
}
381381

382+
// FIXME remove this: tests should use IOUtils and main shouldn't read Stream but... stream them!
383+
@Deprecated
382384
public final static byte[] readFully(InputStream in, int[] lengthWrapper) throws IOException {
383385
// just in case available() returns bogus (or -1), allocate non-trivial chunk
384386
byte[] b = new byte[Math.max(512, in.available())];

api/src/test/java/org/asynchttpclient/RealmTest.java

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,110 +12,112 @@
1212
*/
1313
package org.asynchttpclient;
1414

15-
import org.asynchttpclient.Realm;
16-
import org.asynchttpclient.Realm.AuthScheme;
17-
import org.asynchttpclient.Realm.RealmBuilder;
18-
import org.testng.Assert;
15+
import static org.testng.Assert.assertEquals;
16+
1917
import java.math.BigInteger;
2018
import java.security.MessageDigest;
2119

20+
import org.asynchttpclient.Realm.AuthScheme;
21+
import org.asynchttpclient.Realm.RealmBuilder;
2222
import org.testng.annotations.Test;
2323

2424
public class RealmTest {
2525
@Test(groups = "fast")
2626
public void testClone() {
2727
RealmBuilder builder = new RealmBuilder();
28-
builder.setPrincipal( "user" ).setPassword( "pass" );
29-
builder.setEnconding( "enc" ).setUsePreemptiveAuth( true );
30-
builder.setRealmName( "realm" ).setAlgorithm( "algo" );
31-
builder.setScheme( AuthScheme.BASIC );
28+
builder.setPrincipal("user").setPassword("pass");
29+
builder.setEnconding("enc").setUsePreemptiveAuth(true);
30+
builder.setRealmName("realm").setAlgorithm("algo");
31+
builder.setScheme(AuthScheme.BASIC);
3232
Realm orig = builder.build();
33-
34-
Realm clone = new RealmBuilder().clone( orig ).build();
35-
Assert.assertEquals( clone.getPrincipal(), orig.getPrincipal() );
36-
Assert.assertEquals( clone.getPassword(), orig.getPassword() );
37-
Assert.assertEquals( clone.getEncoding(), orig.getEncoding() );
38-
Assert.assertEquals( clone.getUsePreemptiveAuth(), orig.getUsePreemptiveAuth() );
39-
Assert.assertEquals( clone.getRealmName(), orig.getRealmName() );
40-
Assert.assertEquals( clone.getAlgorithm(), orig.getAlgorithm() );
41-
Assert.assertEquals( clone.getAuthScheme(), orig.getAuthScheme() );
33+
34+
Realm clone = new RealmBuilder().clone(orig).build();
35+
assertEquals(clone.getPrincipal(), orig.getPrincipal());
36+
assertEquals(clone.getPassword(), orig.getPassword());
37+
assertEquals(clone.getEncoding(), orig.getEncoding());
38+
assertEquals(clone.getUsePreemptiveAuth(), orig.getUsePreemptiveAuth());
39+
assertEquals(clone.getRealmName(), orig.getRealmName());
40+
assertEquals(clone.getAlgorithm(), orig.getAlgorithm());
41+
assertEquals(clone.getAuthScheme(), orig.getAuthScheme());
4242
}
43+
4344
@Test(groups = "fast")
4445
public void testOldDigestEmptyString() {
45-
String qop="";
46+
String qop = "";
4647
testOldDigest(qop);
4748
}
49+
4850
@Test(groups = "fast")
4951
public void testOldDigestNull() {
50-
String qop=null;
52+
String qop = null;
5153
testOldDigest(qop);
5254
}
5355

54-
private void testOldDigest(String qop){
55-
String user="user";
56-
String pass="pass";
57-
String realm="realm";
58-
String nonce="nonce";
59-
String method="GET";
60-
String uri="/foo";
56+
private void testOldDigest(String qop) {
57+
String user = "user";
58+
String pass = "pass";
59+
String realm = "realm";
60+
String nonce = "nonce";
61+
String method = "GET";
62+
String uri = "/foo";
6163
RealmBuilder builder = new RealmBuilder();
62-
builder.setPrincipal( user ).setPassword( pass );
63-
builder.setNonce( nonce );
64-
builder.setUri( uri );
64+
builder.setPrincipal(user).setPassword(pass);
65+
builder.setNonce(nonce);
66+
builder.setUri(uri);
6567
builder.setMethodName(method);
66-
builder.setRealmName( realm );
68+
builder.setRealmName(realm);
6769
builder.setQop(qop);
68-
builder.setScheme( AuthScheme.DIGEST );
70+
builder.setScheme(AuthScheme.DIGEST);
6971
Realm orig = builder.build();
7072

71-
String ha1=getMd5(user +":" + realm +":"+pass);
72-
String ha2=getMd5(method +":"+ uri);
73-
String expectedResponse=getMd5(ha1 +":" + nonce +":" + ha2);
73+
String ha1 = getMd5(user + ":" + realm + ":" + pass);
74+
String ha2 = getMd5(method + ":" + uri);
75+
String expectedResponse = getMd5(ha1 + ":" + nonce + ":" + ha2);
7476

75-
Assert.assertEquals(expectedResponse,orig.getResponse());
77+
assertEquals(expectedResponse, orig.getResponse());
7678
}
7779

7880
@Test(groups = "fast")
7981
public void testStrongDigest() {
80-
String user="user";
81-
String pass="pass";
82-
String realm="realm";
83-
String nonce="nonce";
84-
String method="GET";
85-
String uri="/foo";
86-
String qop="auth";
82+
String user = "user";
83+
String pass = "pass";
84+
String realm = "realm";
85+
String nonce = "nonce";
86+
String method = "GET";
87+
String uri = "/foo";
88+
String qop = "auth";
8789
RealmBuilder builder = new RealmBuilder();
88-
builder.setPrincipal( user ).setPassword( pass );
89-
builder.setNonce( nonce );
90-
builder.setUri( uri );
90+
builder.setPrincipal(user).setPassword(pass);
91+
builder.setNonce(nonce);
92+
builder.setUri(uri);
9193
builder.setMethodName(method);
92-
builder.setRealmName( realm );
94+
builder.setRealmName(realm);
9395
builder.setQop(qop);
94-
builder.setScheme( AuthScheme.DIGEST );
96+
builder.setScheme(AuthScheme.DIGEST);
9597
Realm orig = builder.build();
9698

9799
String nc = orig.getNc();
98100
String cnonce = orig.getCnonce();
99-
String ha1=getMd5(user +":" + realm +":"+pass);
100-
String ha2=getMd5(method +":"+ uri);
101-
String expectedResponse=getMd5(ha1 +":" + nonce +":" + nc + ":" + cnonce +":" + qop + ":" + ha2);
101+
String ha1 = getMd5(user + ":" + realm + ":" + pass);
102+
String ha2 = getMd5(method + ":" + uri);
103+
String expectedResponse = getMd5(ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + ha2);
102104

103-
Assert.assertEquals(expectedResponse,orig.getResponse());
105+
assertEquals(expectedResponse, orig.getResponse());
104106
}
105107

106-
private String getMd5(String what){
107-
try {
108+
private String getMd5(String what) {
109+
try {
108110
MessageDigest md = MessageDigest.getInstance("MD5");
109-
md.update(what.getBytes("ISO-8859-1"));
110-
byte[] hash = md.digest();
111-
BigInteger bi = new BigInteger(1, hash);
112-
String result = bi.toString(16);
113-
if (result.length() % 2 != 0) {
114-
return "0" + result;
115-
}
116-
return result;
117-
} catch (Exception e) {
118-
throw new RuntimeException(e);
111+
md.update(what.getBytes("ISO-8859-1"));
112+
byte[] hash = md.digest();
113+
BigInteger bi = new BigInteger(1, hash);
114+
String result = bi.toString(16);
115+
if (result.length() % 2 != 0) {
116+
return "0" + result;
119117
}
118+
return result;
119+
} catch (Exception e) {
120+
throw new RuntimeException(e);
121+
}
120122
}
121123
}

api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,18 @@
1515
*/
1616
package org.asynchttpclient.async;
1717

18-
import java.io.File;
19-
import java.net.URL;
18+
import static org.asynchttpclient.async.util.TestUtils.*;
2019

21-
import org.eclipse.jetty.server.Server;
22-
import org.eclipse.jetty.server.ssl.SslSocketConnector;
23-
import org.eclipse.jetty.util.ssl.SslContextFactory;
24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
2620
import org.testng.annotations.BeforeClass;
2721

2822
public abstract class AbstractBasicHttpsTest extends AbstractBasicTest {
29-
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractBasicHttpsTest.class);
3023

3124
@BeforeClass(alwaysRun = true)
3225
public void setUpGlobal() throws Exception {
33-
server = new Server();
3426
port1 = findFreePort();
35-
36-
ClassLoader cl = getClass().getClassLoader();
37-
38-
URL keystoreUrl = cl.getResource("ssltest-keystore.jks");
39-
String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath();
40-
LOGGER.info("SSL keystore path: {}", keyStoreFile);
41-
SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile);
42-
sslContextFactory.setKeyStorePassword("changeit");
43-
44-
String trustStoreFile = new File(cl.getResource("ssltest-cacerts.jks").toURI()).getAbsolutePath();
45-
LOGGER.info("SSL certs path: {}", trustStoreFile);
46-
sslContextFactory.setTrustStore(trustStoreFile);
47-
sslContextFactory.setTrustStorePassword("changeit");
48-
49-
SslSocketConnector connector = new SslSocketConnector(sslContextFactory);
50-
connector.setHost("127.0.0.1");
51-
connector.setPort(port1);
52-
server.addConnector(connector);
53-
27+
server = newJettyHttpsServer(port1);
5428
server.setHandler(configureHandler());
5529
server.start();
56-
LOGGER.info("Local HTTP server started successfully");
30+
logger.info("Local HTTP server started successfully");
5731
}
5832
}

0 commit comments

Comments
 (0)