parent
8dd0abf850
commit
04328f9b3b
|
@ -52,6 +52,6 @@ phoenix.response-enc-switch=false
|
||||||
phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ==
|
phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ==
|
||||||
#====custom config,begin with phoenix====
|
#====custom config,begin with phoenix====
|
||||||
#调试配置
|
#调试配置
|
||||||
dispose.check-protocol-timeout=true
|
dispose.check-protocol-timeout=false
|
||||||
dispose.check-request-token=true
|
dispose.check-request-token=true
|
||||||
dispose.check-admin-permission=true
|
dispose.check-admin-permission=true
|
||||||
|
|
|
@ -76,6 +76,9 @@ public class AuthController {
|
||||||
.expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS)
|
.expireTime(System.currentTimeMillis() + ConstValue.GlobalConfigure.TOKEN_EXPIRED_TIME_MS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
rspInfo.setStatus(ErrorCode.ERR_OK.getCode());
|
||||||
|
rspInfo.setMessage(ErrorCode.ERR_OK.getMsg());
|
||||||
|
|
||||||
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,10 @@ package com.dispose.Global;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.common.ErrorCode;
|
import com.dispose.common.ErrorCode;
|
||||||
import com.dispose.common.GlobalVar;
|
import com.dispose.common.GlobalVar;
|
||||||
|
import com.dispose.pojo.dto.ProtocolRespDTO;
|
||||||
import com.dispose.pojo.po.MReturnType;
|
import com.dispose.pojo.po.MReturnType;
|
||||||
import com.dispose.service.UserAccountService;
|
import com.dispose.service.UserAccountService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -82,8 +84,44 @@ public class InitTestEnvironment {
|
||||||
return logToken;
|
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.
|
* 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 {
|
public String verifyRep(String data, Long reqTime) throws JSONException {
|
||||||
Long verValue = 2L;
|
Long verValue = 2L;
|
||||||
|
|
|
@ -4,10 +4,13 @@ import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
import com.dispose.common.ErrorCode;
|
import com.dispose.common.ErrorCode;
|
||||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
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.LoginReq;
|
||||||
|
import com.dispose.pojo.vo.auth.LoginRsp;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.FixMethodOrder;
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -45,7 +48,37 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Test
|
@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\":" +
|
String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":" +
|
||||||
"\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
"\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
|
||||||
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
"\\\"userName\\\":\\\"admin\\\"}\"}";
|
||||||
|
@ -53,7 +86,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/auth/login")
|
.post("/auth/login")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content(objectMapper.writeValueAsString(reqData)))
|
.content(reqData))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
||||||
.andReturn()
|
.andReturn()
|
||||||
|
@ -67,9 +100,9 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/auth/login")
|
.post("/auth/login")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.content(objectMapper.writeValueAsString(reqData)))
|
.content(reqData))
|
||||||
.andDo(print()).andExpect(status().isOk())
|
.andDo(print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
|
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode()))
|
||||||
.andReturn()
|
.andReturn()
|
||||||
.getResponse()
|
.getResponse()
|
||||||
.getContentAsString();
|
.getContentAsString();
|
||||||
|
|
Loading…
Reference in New Issue