Authored by zhaoyue

Add login and mod password

git add --all src/*
git add push.sh
git add pom.xml
git commit -m "Mod to https"
git commit -m "Add login and mod password"
git push origin master
git status
git pull
... ...
... ... @@ -19,7 +19,6 @@ public class AccountTest {
private static final String URL_LOGIN = Constants.URL_PREFIX + "/uspih/account";
/**
*
* @param user user account
* @param pass user password
* @return
... ... @@ -37,19 +36,57 @@ public class AccountTest {
}
/**
* login success test
* @param user user account
* @param pass user password
* @param newpwd new user password
* @return
*/
public static String loginModPwdAndGetToken(String user, String pass, String newpwd) {
Map<String, String> params = new HashMap<String, String>();
params.put("account", user);
params.put("password", EncodeTools.encode("MD5", pass)); // encode password with MD5 algorithm
params.put("newpwd", EncodeTools.encode("MD5", newpwd)); // encode password with MD5 algorithm
params.put("t", HttpTools.getNow());
String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
System.out.println("login success:" + response);
JSONObject jsonObject = new JSONObject(response);
JSONObject content = jsonObject.getJSONObject("content");
return content.getString("userId") + "_" + content.getString("token");
}
/**
* login success test
*/
@Test
public void testLoginSuccess() {
System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD));
}
/**
* login fail test
* login fail test
*/
@Test
public void testLoginFail() {
System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT+"ppppp", Data.ADMIN_PWD));
System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT + "ppppp", Data.ADMIN_PWD));
}
/**
* login and modify password success test
*/
@Test
public void testLoginModPwdSuccess() {
System.out.println(loginModPwdAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD, Data.ADMIN_PWD));
}
/**
* login and modify password fail test
*/
@Test
public void testLoginModPwdFail() {
System.out.println(loginModPwdAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD + "pppppp", Data.ADMIN_PWD));
}
@Test
public void testLogout() {
String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
... ... @@ -64,7 +101,7 @@ public class AccountTest {
String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
Map<String, String> params = new HashMap<String, String>();
params.put("t", HttpTools.getNow());
String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token+"PPPPPP");
String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token + "PPPPPP");
System.out.println("logout success:" + response);
}
}
... ...
... ... @@ -46,7 +46,7 @@ public class ReportTest {
public void testDelReport() {
String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
Map<String, String> params = new HashMap<String, String>();
params.put("report_id", "100");
params.put("report_id", "133");
String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token);
System.out.println("delete report:" + response);
}
... ...