Skip to content

Commit 531b222

Browse files
committed
token test
1 parent 1b6141a commit 531b222

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

library/src/androidTest/java/com/qiniu/android/FormUploadTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
7070
Assert.assertTrue(info.isOK());
7171
Assert.assertNotNull(info.reqId);
7272
Assert.assertNotNull(resp);
73+
Assert.assertEquals("/", info.path);
7374
}
7475

7576
@SmallTest
@@ -106,6 +107,7 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
106107
Assert.assertEquals(expectKey, key);
107108
Assert.assertTrue(info.isOK());
108109
Assert.assertNotNull(info.reqId);
110+
Assert.assertEquals("/", info.path);
109111
Assert.assertNotNull(resp);
110112
Assert.assertEquals("Fqr0xh3cxeii2r7eDztILNmuqUNN", resp.optString("key", ""));
111113
}

library/src/androidTest/java/com/qiniu/android/TokenTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,18 @@ public void testRight() {
1414
UpToken t = UpToken.parse(TestConfig.token);
1515
Assert.assertNotNull(t);
1616
}
17+
18+
public void testEmpty() {
19+
UpToken t = UpToken.parse(null);
20+
Assert.assertNull(t);
21+
22+
t = UpToken.parse("");
23+
Assert.assertNull(t);
24+
}
25+
26+
public void testReturnUrl() {
27+
UpToken t = UpToken.parse("QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm:1jLiztn4plVyeB8Hie1ryO5z9uo=:eyJzY29wZSI6InB5c2RrIiwiZGVhZGxpbmUiOjE0MzM0ODM5MzYsInJldHVyblVybCI6Imh0dHA6Ly8xMjcuMC4wLjEvIn0=");
28+
Assert.assertTrue(t.hasReturnUrl());
29+
}
30+
1731
}

library/src/main/java/com/qiniu/android/http/ResponseHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ public final class ResponseHandler extends AsyncHttpResponseHandler {
5353
*/
5454
private int port = -1;
5555

56+
private String path = null;
57+
5658
public ResponseHandler(String url, CompletionHandler completionHandler, ProgressHandler progressHandler) {
5759
super(Looper.getMainLooper());
5860
URI uri = null;
5961
try {
6062
uri = new URI(url);
6163
this.host = uri.getHost();
6264
this.port = uri.getPort();
65+
this.path = uri.getPath();
6366
} catch (URISyntaxException e) {
6467
this.host = "N/A";
6568
e.printStackTrace();
@@ -69,7 +72,7 @@ public ResponseHandler(String url, CompletionHandler completionHandler, Progress
6972
}
7073

7174
private static ResponseInfo buildResponseInfo(int statusCode, Header[] headers, byte[] responseBody,
72-
String host, String ip, int port, double duration, Throwable error) {
75+
String host, String path, String ip, int port, double duration, Throwable error) {
7376

7477
if (error != null && error instanceof CancellationHandler.CancellationException) {
7578
return ResponseInfo.cancelled();
@@ -138,7 +141,7 @@ private static ResponseInfo buildResponseInfo(int statusCode, Header[] headers,
138141
}
139142
}
140143

141-
return new ResponseInfo(statusCode, reqId, xlog, xvia, host, ip, port, duration, err);
144+
return new ResponseInfo(statusCode, reqId, xlog, xvia, host, path, ip, port, duration, err);
142145
}
143146

144147
private static JSONObject buildJsonResp(byte[] body) throws Exception {
@@ -156,15 +159,15 @@ public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
156159
} catch (Exception e) {
157160
exception = e;
158161
}
159-
ResponseInfo info = buildResponseInfo(statusCode, headers, null, host, ip, port, duration, exception);
162+
ResponseInfo info = buildResponseInfo(statusCode, headers, null, host, path, ip, port, duration, exception);
160163
Log.i("upload----success", info.toString());
161164
completionHandler.complete(info, obj);
162165
}
163166

164167
@Override
165168
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
166169
double duration = (System.currentTimeMillis() - reqStartTime) / 1000.0;
167-
ResponseInfo info = buildResponseInfo(statusCode, headers, responseBody, host, ip, port, duration, error);
170+
ResponseInfo info = buildResponseInfo(statusCode, headers, responseBody, host, path, ip, port, duration, error);
168171
Log.i("upload----failed", info.toString());
169172
completionHandler.complete(info, null);
170173
}

library/src/main/java/com/qiniu/android/http/ResponseInfo.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,40 @@ public final class ResponseInfo {
5858
*/
5959
public final int port;
6060

61-
public ResponseInfo(int statusCode, String reqId, String xlog, String xvia, String host, String ip, int port, double duration, String error) {
61+
/**
62+
* 访问路径
63+
*/
64+
public final String path;
65+
66+
public ResponseInfo(int statusCode, String reqId, String xlog, String xvia, String host, String path, String ip, int port, double duration, String error) {
6267
this.statusCode = statusCode;
6368
this.reqId = reqId;
6469
this.xlog = xlog;
6570
this.xvia = xvia;
6671
this.host = host;
72+
this.path = path;
6773
this.duration = duration;
6874
this.error = error;
6975
this.ip = ip;
7076
this.port = port;
7177
}
7278

7379
public static ResponseInfo cancelled() {
74-
return new ResponseInfo(Cancelled, "", "", "", "", "", -1, 0, "cancelled by user");
80+
return new ResponseInfo(Cancelled, "", "", "", "", "", "", -1, 0, "cancelled by user");
7581
}
7682

7783
public static ResponseInfo invalidArgument(String message) {
78-
return new ResponseInfo(InvalidArgument, "", "", "", "", "", -1, 0,
84+
return new ResponseInfo(InvalidArgument, "", "", "", "", "", "", -1, 0,
7985
message);
8086
}
8187

8288
public static ResponseInfo invalidToken(String message) {
83-
return new ResponseInfo(InvalidToken, "", "", "", "", "", -1, 0,
89+
return new ResponseInfo(InvalidToken, "", "", "", "", "", "", -1, 0,
8490
message);
8591
}
8692

8793
public static ResponseInfo fileError(Exception e) {
88-
return new ResponseInfo(InvalidFile, "", "", "", "", "", -1,
94+
return new ResponseInfo(InvalidFile, "", "", "", "", "", "", -1,
8995
0, e.getMessage());
9096
}
9197

@@ -122,7 +128,7 @@ public boolean isNotQiniu() {
122128
}
123129

124130
public String toString() {
125-
return String.format(Locale.ENGLISH, "{ResponseInfo:%s,status:%d, reqId:%s, xlog:%s, xvia:%s, host:%s, ip:%s, port:%d, duration:%f s, error:%s}",
126-
super.toString(), statusCode, reqId, xlog, xvia, host, ip, port, duration, error);
131+
return String.format(Locale.ENGLISH, "{ResponseInfo:%s,status:%d, reqId:%s, xlog:%s, xvia:%s, host:%s, path:%s, ip:%s, port:%d, duration:%f s, error:%s}",
132+
super.toString(), statusCode, reqId, xlog, xvia, host, path, ip, port, duration, error);
127133
}
128134
}

library/src/main/java/com/qiniu/android/storage/FormUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ public void complete(ResponseInfo info, JSONObject response) {
138138
}
139139

140140
private static String genUploadAddress(String host, int port) {
141-
return "http://" + host + ":" + port;
141+
return "http://" + host + ":" + port + "/";
142142
}
143143
}

library/src/main/java/com/qiniu/android/storage/UpToken.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public String toString(){
4949
return token;
5050
}
5151

52-
boolean hasReturnUrl(){
52+
public boolean hasReturnUrl(){
5353
return !returnUrl.equals("");
5454
}
5555

0 commit comments

Comments
 (0)