REM:
1. 更新冒烟测试用例
2. test环境配置修改为不验证请求超时
This commit is contained in:
HuangXin 2020-05-08 12:10:58 +08:00
parent 8dd0abf850
commit 04328f9b3b
4 changed files with 79 additions and 5 deletions

View File

@ -52,6 +52,6 @@ phoenix.response-enc-switch=false
phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ==
#====custom config,begin with phoenix====
#调试配置
dispose.check-protocol-timeout=true
dispose.check-protocol-timeout=false
dispose.check-request-token=true
dispose.check-admin-permission=true

View File

@ -76,6 +76,9 @@ public class AuthController {
.expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS)
.build();
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
rspInfo.setMessage(ErrorCode.ERR_OK.getMsg());
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}

View File

@ -3,8 +3,10 @@ package com.dispose.Global;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.common.GlobalVar;
import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.po.MReturnType;
import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
@ -82,8 +84,44 @@ public class InitTestEnvironment {
return logToken;
}
/**
* Verify resp string.
*
* @param resp the resp
* @return the string
*/
public String verifyResp(String resp) {
try {
ObjectMapper objectMapper = new ObjectMapper();
ProtocolRespDTO rspInfo = objectMapper.readValue(resp, ProtocolRespDTO.class);
// 校验版本
if (rspInfo.getVer() < ConstValue.Protocol.VERSION) {
Assert.fail();
}
// 校验时间错
if (GlobalVar.IS_CHECK_REQUEST_TIMEOUT
&& Math.abs(System.currentTimeMillis() - rspInfo.getTimeStamp()) >= ConstValue.Protocol.REQUEST_TIMEOUT_MS) {
Assert.fail();
}
return rspInfo.getMsgContent();
} catch (Exception ex) {
Assert.fail();
}
Assert.fail();
return "";
}
/**
* Check response body.
*
* @param data the data
* @param reqTime the req time
* @return the string
* @throws JSONException the json exception
*/
public String verifyRep(String data, Long reqTime) throws JSONException {
Long verValue = 2L;

View File

@ -4,10 +4,13 @@ import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.vo.auth.LoginReq;
import com.dispose.pojo.vo.auth.LoginRsp;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -45,7 +48,37 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
private ObjectMapper objectMapper;
@Test
public void t1_VerExceptionTest() throws Exception {
public void t1_NormalAuthTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"password\\\"" +
":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":\\\"admin\\\"}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
LoginRsp logRsp = objectMapper.readValue(verifyResp(ret), LoginRsp.class) ;
Assert.assertNotNull(logRsp);
Assert.assertNotNull(logRsp.getUserName());
Assert.assertNotNull(logRsp.getLogTime());
Assert.assertNotNull(logRsp.getToken());
Assert.assertNotNull(logRsp.getExpireTime());
Assert.assertNotNull(logRsp.getMessage());
Assert.assertNotNull(logRsp.getStatus());
Assert.assertEquals(Long.valueOf(logRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
}
@Test
public void t2_VerExceptionTest() throws Exception {
String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":" +
"\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":\\\"admin\\\"}\"}";
@ -53,7 +86,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(reqData)))
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
@ -67,9 +100,9 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(reqData)))
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();