Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00dbf54

Browse files
committed
Fix RealmTest MD5 String computation,closeAsyncHttpClient#1301
1 parentaf3e161 commit00dbf54

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

‎client/src/test/java/org/asynchttpclient/RealmTest.java‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
importstaticorg.asynchttpclient.Dsl.*;
1717
importstaticorg.testng.Assert.assertEquals;
1818

19-
importjava.math.BigInteger;
2019
importjava.nio.charset.StandardCharsets;
2120
importjava.security.MessageDigest;
2221

2322
importorg.asynchttpclient.uri.Uri;
23+
importorg.asynchttpclient.util.StringUtils;
2424
importorg.testng.annotations.Test;
2525

2626
publicclassRealmTest {
@@ -42,18 +42,16 @@ public void testClone() {
4242
}
4343

4444
@Test(groups ="standalone")
45-
publicvoidtestOldDigestEmptyString() {
46-
Stringqop ="";
47-
testOldDigest(qop);
45+
publicvoidtestOldDigestEmptyString()throwsException {
46+
testOldDigest("");
4847
}
4948

5049
@Test(groups ="standalone")
51-
publicvoidtestOldDigestNull() {
52-
Stringqop =null;
53-
testOldDigest(qop);
50+
publicvoidtestOldDigestNull()throwsException {
51+
testOldDigest(null);
5452
}
5553

56-
privatevoidtestOldDigest(Stringqop) {
54+
privatevoidtestOldDigest(Stringqop)throwsException{
5755
Stringuser ="user";
5856
Stringpass ="pass";
5957
Stringrealm ="realm";
@@ -65,7 +63,8 @@ private void testOldDigest(String qop) {
6563
.setUri(uri)//
6664
.setMethodName(method)//
6765
.setRealmName(realm)//
68-
.setQop(qop).build();
66+
.setQop(qop)//
67+
.build();
6968

7069
Stringha1 =getMd5(user +":" +realm +":" +pass);
7170
Stringha2 =getMd5(method +":" +uri.getPath());
@@ -75,7 +74,7 @@ private void testOldDigest(String qop) {
7574
}
7675

7776
@Test(groups ="standalone")
78-
publicvoidtestStrongDigest() {
77+
publicvoidtestStrongDigest()throwsException{
7978
Stringuser ="user";
8079
Stringpass ="pass";
8180
Stringrealm ="realm";
@@ -88,7 +87,8 @@ public void testStrongDigest() {
8887
.setUri(uri)//
8988
.setMethodName(method)//
9089
.setRealmName(realm)//
91-
.setQop(qop).build();
90+
.setQop(qop)//
91+
.build();
9292

9393
Stringnc =orig.getNc();
9494
Stringcnonce =orig.getCnonce();
@@ -99,19 +99,10 @@ public void testStrongDigest() {
9999
assertEquals(orig.getResponse(),expectedResponse);
100100
}
101101

102-
privateStringgetMd5(Stringwhat) {
103-
try {
104-
MessageDigestmd =MessageDigest.getInstance("MD5");
105-
md.update(what.getBytes(StandardCharsets.ISO_8859_1));
106-
byte[]hash =md.digest();
107-
BigIntegerbi =newBigInteger(1,hash);
108-
Stringresult =bi.toString(16);
109-
if (result.length() %2 !=0) {
110-
return"0" +result;
111-
}
112-
returnresult;
113-
}catch (Exceptione) {
114-
thrownewRuntimeException(e);
115-
}
102+
privateStringgetMd5(Stringwhat)throwsException {
103+
MessageDigestmd =MessageDigest.getInstance("MD5");
104+
md.update(what.getBytes(StandardCharsets.ISO_8859_1));
105+
byte[]hash =md.digest();
106+
returnStringUtils.toHexString(hash);
116107
}
117108
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp