Skip to content

Commit cd7fb6a

Browse files
authored
Merge pull request #226 from sxci/add_test_xvar
添加 x:foo 测试
2 parents c3c037f + 1bf3bd1 commit cd7fb6a

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/main/java/com/qiniu/storage/ResumeUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void accept(String key, Object value) {
168168
b.append("/");
169169
b.append(key);
170170
b.append("/");
171-
b.append(value);
171+
b.append(UrlSafeBase64.encodeToString("" + value));
172172
}
173173
});
174174
}

src/test/java/com/qiniu/storage/FormUploadTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,33 @@ public void complete(String key, Response r) {
196196
}
197197
}
198198

199+
@Test
200+
public void testXVar() {
201+
final String expectKey = "世/界";
202+
File f = null;
203+
try {
204+
f = TempFile.createFile(1);
205+
} catch (IOException e) {
206+
e.printStackTrace();
207+
}
208+
assert f != null;
209+
StringMap params = new StringMap().put("x:foo", "foo_val");
210+
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
211+
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
212+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
213+
new StringMap().put("returnBody", returnBody));
214+
215+
try {
216+
Response res = uploadManager.put(f, expectKey, token, params, null, true);
217+
StringMap m = res.jsonToMap();
218+
assertEquals("foo_val", m.get("foo"));
219+
} catch (QiniuException e) {
220+
fail();
221+
} finally {
222+
TempFile.remove(f);
223+
}
224+
}
225+
199226
@Test
200227
public void testFname() {
201228
final String expectKey = "世/界";

src/test/java/com/qiniu/storage/ResumeUploadTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,35 @@
1717

1818
public class ResumeUploadTest {
1919

20+
@Test
21+
public void testXVar() throws IOException {
22+
final String expectKey = "世/界";
23+
File f = null;
24+
try {
25+
f = TempFile.createFile(1024 * 4 + 2341);
26+
} catch (IOException e) {
27+
e.printStackTrace();
28+
}
29+
assert f != null;
30+
StringMap params = new StringMap().put("x:foo", "foo_val");
31+
final String returnBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsize\":\"$(fsize)\""
32+
+ ",\"fname\":\"$(fname)\",\"mimeType\":\"$(mimeType)\",\"foo\":\"$(x:foo)\"}";
33+
String token = TestConfig.testAuth.uploadToken(TestConfig.bucket, expectKey, 3600,
34+
new StringMap().put("returnBody", returnBody));
35+
36+
try {
37+
UploadManager uploadManager = new UploadManager();
38+
Response res = uploadManager.put(f, expectKey, token, params, null, true);
39+
StringMap m = res.jsonToMap();
40+
assertEquals("foo_val", m.get("foo"));
41+
} catch (QiniuException e) {
42+
assertEquals("", e.response.bodyString());
43+
fail();
44+
} finally {
45+
TempFile.remove(f);
46+
}
47+
}
48+
2049
private void template(int size) throws IOException {
2150
final String expectKey = "\r\n?&r=" + size + "k";
2251
final File f = TempFile.createFile(size);

0 commit comments

Comments
 (0)