REM:
1. 将协议字段类型由基本类型改为包装类型,测试字段为null情况
2. 协议请求验证关键字段是否为空
3. 增加登录认证冒烟测试用例
This commit is contained in:
HuangXin 2020-05-08 14:44:21 +08:00
parent 04328f9b3b
commit 964c63d360
3 changed files with 286 additions and 17 deletions

View File

@ -22,7 +22,7 @@ public abstract class ProtocolDTO {
* The Ver. * The Ver.
*/ */
@ApiModelProperty(value = "协议版本号", required = true, example = "1") @ApiModelProperty(value = "协议版本号", required = true, example = "1")
private int ver; private Integer ver;
/** /**
* The Crypto type. * The Crypto type.
@ -33,7 +33,7 @@ public abstract class ProtocolDTO {
"2采用AES加密后的base64编码格式\n", required = true, "2采用AES加密后的base64编码格式\n", required = true,
allowableValues = "0, 1, 2", allowableValues = "0, 1, 2",
example = "0") example = "0")
private int cryptoType; private Integer cryptoType;
/** /**
* The Time stamp. * The Time stamp.

View File

@ -89,6 +89,11 @@ public class ProtocolReqDTO extends ProtocolDTO {
* @return the error code * @return the error code
*/ */
public ErrorCode verifyRequest() { public ErrorCode verifyRequest() {
if(this.getVer() == null || this.getCryptoType() == null || this.getTimeStamp() == null) {
return ErrorCode.ERR_PARAMEXCEPTION;
}
// 校验版本 // 校验版本
if (this.getVer() < ConstValue.Protocol.VERSION) { if (this.getVer() < ConstValue.Protocol.VERSION) {
return ErrorCode.ERR_VERSION; return ErrorCode.ERR_VERSION;

View File

@ -5,6 +5,7 @@ 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.dto.ProtocolRespDTO;
import com.dispose.pojo.po.ReturnStatus;
import com.dispose.pojo.vo.auth.LoginReq; import com.dispose.pojo.vo.auth.LoginReq;
import com.dispose.pojo.vo.auth.LoginRsp; import com.dispose.pojo.vo.auth.LoginRsp;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -29,6 +30,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* The type Auth controller exception smoke test.
*/
@AutoConfigureMockMvc @AutoConfigureMockMvc
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ -47,8 +51,13 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
@Resource @Resource
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
/**
* A 1 normal auth test.
*
* @throws Exception the exception
*/
@Test @Test
public void t1_NormalAuthTest() throws Exception { public void a1_normalAuthTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"password\\\"" + "\"msgContent\":\"{\\\"password\\\"" +
":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + ":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
@ -64,26 +73,31 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
LoginRsp logRsp = objectMapper.readValue(verifyResp(ret), LoginRsp.class) ; LoginRsp rspInfo = objectMapper.readValue(verifyResp(ret), LoginRsp.class) ;
Assert.assertNotNull(logRsp); Assert.assertNotNull(rspInfo);
Assert.assertNotNull(logRsp.getUserName()); Assert.assertNotNull(rspInfo.getUserName());
Assert.assertNotNull(logRsp.getLogTime()); Assert.assertNotNull(rspInfo.getLogTime());
Assert.assertNotNull(logRsp.getToken()); Assert.assertNotNull(rspInfo.getToken());
Assert.assertNotNull(logRsp.getExpireTime()); Assert.assertNotNull(rspInfo.getExpireTime());
Assert.assertNotNull(logRsp.getMessage()); Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(logRsp.getStatus()); Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(logRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
} }
/**
* A 2 ver json exception test.
*
* @throws Exception the exception
*/
@Test @Test
public void t2_VerExceptionTest() throws Exception { public void a2_verJsonExceptionTest() 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\\\"}\"}";
mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login") .post("/auth/login")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(reqData)) .content(reqData))
@ -93,18 +107,268 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment {
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 3 ver null exception test.
*
* @throws Exception the exception
*/
@Test
public void a3_verNullExceptionTest() throws Exception {
String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":\\\"admin\\\"}\"}"; "\\\"userName\\\":\\\"admin\\\"}\"}";
mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login") .post("/auth/login")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.content(reqData)) .content(reqData))
.andDo(print()).andExpect(status().isOk()) .andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode())) .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn() .andReturn()
.getResponse() .getResponse()
.getContentAsString(); .getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 4 crypto json exception test.
*
* @throws Exception the exception
*/
@Test
public void a4_cryptoJsonExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":\"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_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 5 crypto null exception test.
*
* @throws Exception the exception
*/
@Test
public void a5_cryptoNullExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":null,\"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_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 6 username not exist exception test.
*
* @throws Exception the exception
*/
@Test
public void a6_usernameNotExistExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":\\\"123456\\\"}\"}";
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_USERNOTFOUND.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
}
/**
* A 7 username empty exception test.
*
* @throws Exception the exception
*/
@Test
public void a7_usernameEmptyExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":\\\"\\\"}\"}";
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_USERNOTFOUND.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
}
/**
* A 8 username null exception test.
*
* @throws Exception the exception
*/
@Test
public void a8_usernameNullExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":null}\"}";
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_USERNOTFOUND.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
}
/**
* A 9 password empty exception test.
*
* @throws Exception the exception
*/
@Test
public void a9_passwordEmptyExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"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_PASSWORD.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
}
/**
* B 1 password null exception test.
*
* @throws Exception the exception
*/
@Test
public void b1_passwordNullExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"password\\\":null,\\\"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_PASSWORD.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
}
/**
* B 2 password error exception test.
*
* @throws Exception the exception
*/
@Test
public void b2_passwordErrorExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"password\\\":\\\"123456\\\",\\\"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_PASSWORD.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
} }
} }