Commit 03c58bf5 authored by 技术部-任文超's avatar 技术部-任文超

验证码jUnit测试类框架,待完善

parent 9783b968
...@@ -79,7 +79,7 @@ public class CaptchaNewValidateAdvisor { ...@@ -79,7 +79,7 @@ public class CaptchaNewValidateAdvisor {
String phoneNo = request.getParameter("phoneNo"); String phoneNo = request.getParameter("phoneNo");
String clientType = request.getParameter("clientType"); String clientType = request.getParameter("clientType");
log.info("使用极验二次验证,phoneNo:{}", phoneNo); log.info("使用极验二次验证,phoneNo:{}", phoneNo);
return geetestCaptchaService.validGeetestCaptcha(ClientType.valueByName(clientType), PasswordUtil.MD5(phoneNo), IPUtil.getRemoteIP(request), challenge, validate, seccode); return geetestCaptchaService.validGeetestCaptcha(PasswordUtil.MD5(phoneNo), IPUtil.getRemoteIP(request), ClientType.valueByName(clientType), challenge, validate, seccode);
} }
/** /**
......
...@@ -12,25 +12,25 @@ public interface IGeetestCaptchaService { ...@@ -12,25 +12,25 @@ public interface IGeetestCaptchaService {
/** /**
* 获取极验验证码 * 获取极验验证码
* *
* @param markStr 标示 * @param markId 用户标识
* @param remoteIp * @param remoteIp 请求终端真实IP
* @param clientType * @param clientType 请求终端类型
* @return 获取失败返回null * @return 获取失败返回null
*/ */
Map<String, String> fetchGeetestCaptcha(String markStr, String remoteIp, ClientType clientType); Map<String, String> fetchGeetestCaptcha(String markId, String remoteIp, ClientType clientType);
/** /**
* 二次验证 * 二次验证
* *
* @param clientType * @param markId 用户标识
* @param phoneNo * @param remoteIp 请求终端真实IP
* @param remoteIp * @param clientType 请求终端类型
* @param challenge * @param challenge
* @param validate * @param validate
* @param seccode * @param seccode
* @return * @return
*/ */
boolean validGeetestCaptcha(ClientType clientType, String phoneNo, String remoteIp, String challenge, String validate, String seccode); boolean validGeetestCaptcha(String markId, String remoteIp, ClientType clientType, String challenge, String validate, String seccode);
} }
...@@ -40,15 +40,15 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService { ...@@ -40,15 +40,15 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
private String apiUrl; private String apiUrl;
@Override @Override
public Map<String, String> fetchGeetestCaptcha(String markStr, String remoteIp, ClientType clientType) { public Map<String, String> fetchGeetestCaptcha(String markId, String remoteIp, ClientType clientType) {
GeetestLib gtSdk = new GeetestLib(captchaId, privateKey, newFailback, apiUrl); GeetestLib gtSdk = new GeetestLib(captchaId, privateKey, newFailback, apiUrl);
HashMap<String, String> param = getParam(markStr, remoteIp, clientType); HashMap<String, String> param = getParam(markId, remoteIp, clientType);
return gtSdk.getResponseStr(param); return gtSdk.getResponseStr(param);
} }
@Override @Override
public boolean validGeetestCaptcha(ClientType clientType, String markStr, String remoteIp, String challenge, String validate, String seccode) { public boolean validGeetestCaptcha(String markId, String remoteIp, ClientType clientType, String challenge, String validate, String seccode) {
HashMap<String, String> param = getParam(markStr, remoteIp, clientType); HashMap<String, String> param = getParam(markId, remoteIp, clientType);
return Constants.GT_CAPTCHA_VALIDATE_SUCCESS==getGeetestSdk().enhencedValidateRequest(challenge, validate, seccode, param); return Constants.GT_CAPTCHA_VALIDATE_SUCCESS==getGeetestSdk().enhencedValidateRequest(challenge, validate, seccode, param);
} }
...@@ -56,9 +56,9 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService { ...@@ -56,9 +56,9 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
return new GeetestLib(captchaId, privateKey, newFailback, apiUrl); return new GeetestLib(captchaId, privateKey, newFailback, apiUrl);
} }
private HashMap<String, String> getParam(String markStr, String remoteIp, ClientType clientType) { private HashMap<String, String> getParam(String markId, String remoteIp, ClientType clientType) {
HashMap<String, String> param = new HashMap<>(); HashMap<String, String> param = new HashMap<>();
param.put("user_id", markStr); param.put("user_id", markId);
if (Objects.isNull(clientType)) { if (Objects.isNull(clientType)) {
param.put("client_type", ClientType.APP.name()); param.put("client_type", ClientType.APP.name());
}else{ }else{
......
import service.GeetestCaptchaServiceTest;
import service.QuantgroupCaptchaServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({GeetestCaptchaServiceTest.class, QuantgroupCaptchaServiceTest.class})
public class CaptchaVerifyTests {}
\ No newline at end of file
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class CommonTests {
@Test
public void compileBooleanAndNull() {
Assert.assertFalse(null instanceof Boolean);
Assert.assertNotEquals(null, Boolean.TRUE);
Assert.assertNotEquals(null, Boolean.FALSE);
}
@Test
public void print() {
System.out.println(null instanceof Boolean);
System.out.println(Boolean.TRUE.equals(null));
System.out.println(Boolean.FALSE.equals(null));
}
}
import demo.*;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({DynamicTests.class, GeetestCaptchaServiceTest.class, MockMvcTests.class, MvcTests.class,
ParametersJunit4Tests.class, ParametersJunit5Tests.class, QuantgroupCaptchaServiceTest.class,
RepsitoryJpaTests.class, RepsitoryTests.class, ServiceTests.class, WebTests.class})
public class DemoTests {}
\ No newline at end of file
import repsitory.UserAuthorizedRepsitoryTests;
import service.UserAuthorizedServiceTests;
import web.UserAuthorizedControllerTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({UserAuthorizedRepsitoryTests.class, UserAuthorizedServiceTests.class, UserAuthorizedControllerTests.class})
public class UserAuthorizedTests {}
\ No newline at end of file
...@@ -13,6 +13,7 @@ import org.springframework.test.context.ContextConfiguration; ...@@ -13,6 +13,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Map;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Bootstrap.class) @SpringBootTest(classes = Bootstrap.class)
...@@ -22,9 +23,15 @@ public class GeetestCaptchaServiceTest { ...@@ -22,9 +23,15 @@ public class GeetestCaptchaServiceTest {
@Resource @Resource
private IGeetestCaptchaService geetestCaptchaService; private IGeetestCaptchaService geetestCaptchaService;
private String phoneNo = "18010043006";
private String remoteIp = "127.0.0.1";
private ClientType clientType = ClientType.H5;
private Map<String, String> data = null;
@Test @Test
public void testFetchGeetestCaptcha(){ public void testFetchGeetestCaptcha(){
Assert.assertNotNull(geetestCaptchaService.fetchGeetestCaptcha(PasswordUtil.MD5("18010043006"),"127.0.0.1", ClientType.APP)); data = geetestCaptchaService.fetchGeetestCaptcha(PasswordUtil.MD5(phoneNo), remoteIp, clientType);
Assert.assertNotNull(data);
} }
...@@ -33,6 +40,6 @@ public class GeetestCaptchaServiceTest { ...@@ -33,6 +40,6 @@ public class GeetestCaptchaServiceTest {
String challenge = "d6e965e06b187c0a01276834d2ff00e6"; String challenge = "d6e965e06b187c0a01276834d2ff00e6";
String validate = "validate"; String validate = "validate";
String seccode = "seccode"; String seccode = "seccode";
Assert.assertTrue(geetestCaptchaService.validGeetestCaptcha(ClientType.APP,"127.0.0.1", PasswordUtil.MD5("18010043006"),challenge,validate,seccode)); Assert.assertTrue(geetestCaptchaService.validGeetestCaptcha(PasswordUtil.MD5(phoneNo), remoteIp, clientType, challenge, validate, seccode));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment