Authored by zhaoyue

Add login and mod password

1 git add --all src/* 1 git add --all src/*
2 git add push.sh 2 git add push.sh
3 git add pom.xml 3 git add pom.xml
4 -git commit -m "Mod to https" 4 +git commit -m "Add login and mod password"
5 git push origin master 5 git push origin master
6 git status 6 git status
7 git pull 7 git pull
@@ -19,7 +19,6 @@ public class AccountTest { @@ -19,7 +19,6 @@ public class AccountTest {
19 private static final String URL_LOGIN = Constants.URL_PREFIX + "/uspih/account"; 19 private static final String URL_LOGIN = Constants.URL_PREFIX + "/uspih/account";
20 20
21 /** 21 /**
22 - *  
23 * @param user user account 22 * @param user user account
24 * @param pass user password 23 * @param pass user password
25 * @return 24 * @return
@@ -37,19 +36,57 @@ public class AccountTest { @@ -37,19 +36,57 @@ public class AccountTest {
37 } 36 }
38 37
39 /** 38 /**
40 - * login success test 39 + * @param user user account
  40 + * @param pass user password
  41 + * @param newpwd new user password
  42 + * @return
  43 + */
  44 + public static String loginModPwdAndGetToken(String user, String pass, String newpwd) {
  45 + Map<String, String> params = new HashMap<String, String>();
  46 + params.put("account", user);
  47 + params.put("password", EncodeTools.encode("MD5", pass)); // encode password with MD5 algorithm
  48 + params.put("newpwd", EncodeTools.encode("MD5", newpwd)); // encode password with MD5 algorithm
  49 + params.put("t", HttpTools.getNow());
  50 + String response = HttpTools.requestByMap(URL_LOGIN, "POST", params);
  51 + System.out.println("login success:" + response);
  52 + JSONObject jsonObject = new JSONObject(response);
  53 + JSONObject content = jsonObject.getJSONObject("content");
  54 + return content.getString("userId") + "_" + content.getString("token");
  55 + }
  56 +
  57 + /**
  58 + * login success test
41 */ 59 */
42 @Test 60 @Test
43 public void testLoginSuccess() { 61 public void testLoginSuccess() {
44 System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD)); 62 System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD));
45 } 63 }
  64 +
46 /** 65 /**
47 - * login fail test 66 + * login fail test
48 */ 67 */
49 @Test 68 @Test
50 public void testLoginFail() { 69 public void testLoginFail() {
51 - System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT+"ppppp", Data.ADMIN_PWD)); 70 + System.out.println(loginAndGetToken(Data.ADMIN_ACCOUNT + "ppppp", Data.ADMIN_PWD));
52 } 71 }
  72 +
  73 + /**
  74 + * login and modify password success test
  75 + */
  76 + @Test
  77 + public void testLoginModPwdSuccess() {
  78 + System.out.println(loginModPwdAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD, Data.ADMIN_PWD));
  79 + }
  80 +
  81 + /**
  82 + * login and modify password fail test
  83 + */
  84 + @Test
  85 + public void testLoginModPwdFail() {
  86 + System.out.println(loginModPwdAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD + "pppppp", Data.ADMIN_PWD));
  87 + }
  88 +
  89 +
53 @Test 90 @Test
54 public void testLogout() { 91 public void testLogout() {
55 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD); 92 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
@@ -64,7 +101,7 @@ public class AccountTest { @@ -64,7 +101,7 @@ public class AccountTest {
64 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD); 101 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
65 Map<String, String> params = new HashMap<String, String>(); 102 Map<String, String> params = new HashMap<String, String>();
66 params.put("t", HttpTools.getNow()); 103 params.put("t", HttpTools.getNow());
67 - String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token+"PPPPPP"); 104 + String response = HttpTools.requestByMapWithToken(URL_LOGIN, "DELETE", params, token + "PPPPPP");
68 System.out.println("logout success:" + response); 105 System.out.println("logout success:" + response);
69 } 106 }
70 } 107 }
@@ -46,7 +46,7 @@ public class ReportTest { @@ -46,7 +46,7 @@ public class ReportTest {
46 public void testDelReport() { 46 public void testDelReport() {
47 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD); 47 String token = loginAndGetToken(Data.ADMIN_ACCOUNT, Data.ADMIN_PWD);
48 Map<String, String> params = new HashMap<String, String>(); 48 Map<String, String> params = new HashMap<String, String>();
49 - params.put("report_id", "100"); 49 + params.put("report_id", "133");
50 String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token); 50 String response = HttpTools.requestByMapWithToken(URL_REPORT, "DELETE", params, token);
51 System.out.println("delete report:" + response); 51 System.out.println("delete report:" + response);
52 } 52 }