UserInfoTest.java
3.13 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.xkl;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static com.xkl.TokenTest.loginAndGetToken;
/**
* Created by win7 on 2016/12/25.
* 用户注册、修改密码、获取个人信息
*/
public class UserInfoTest {
private static final String URL_USER = Constants.URL_PREFIX + "/userInfo";
/**
* 用户注册
*/
@Test
public void testRegister(){
register("15211112222","pass152");
}
/**
* 用户修改密码
*/
@Test
public void testModPass(){
register("15211112222","pass152");
Map<String,String> params = new HashMap<String, String>();
params.put("password",EncodeTools.encode("MD5","pass152_new"));
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
//获取token
String token = loginAndGetToken("15211112222","pass152");
System.out.println(token);
String response = HttpTools.requestByMapWithToken(URL_USER,"PUT",params,token);
System.out.println(response);
}
/**
* 个人信息查询接口
*/
@Test
public void testGetUserInfo(){
Map<String,String> params = new HashMap<String, String>();
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
//获取token
String token = loginAndGetToken("user1","pass1");
System.out.println(token);
String response = HttpTools.requestByMapWithToken(URL_USER,"GET",params,token);
System.out.println(response);
}
public void register(String user,String pass){
Map<String,String> params = new HashMap<String, String>();
params.put("username",user);
params.put("password",EncodeTools.encode("MD5",pass));
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_USER,"POST",params);
System.out.println(response);
}
/**
* 错误的注册:不带sign
*/
@Test
public void testRegisterNoSign(){
Map<String,String> params = new HashMap<String, String>();
params.put("username","15211112222");
params.put("password",EncodeTools.encode("MD5","pass152"));
params.put("t",HttpTools.getNow());
params.put("type","1");
params.put("sign","nosign");
String response = HttpTools.requestByMap(URL_USER,"POST",params);
System.out.println(response);
}
/**
* 错误注册:客户端与服务端时间差距过大
*/
@Test
public void testRegisterWrongTime(){
Map<String,String> params = new HashMap<String, String>();
params.put("username","15211112222");
params.put("password",EncodeTools.encode("MD5","pass152"));
params.put("t",HttpTools.getNow()+100000);
params.put("type","1");
params.put("sign",HttpTools.getSign(params));
String response = HttpTools.requestByMap(URL_USER,"POST",params);
System.out.println(response);
}
}