Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
cb7fd9c5
Commit
cb7fd9c5
authored
Feb 06, 2018
by
贷前—徐菲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单元测试
parent
2e676c4e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
7 deletions
+84
-7
IQuantgroupCaptchaService.java
...group/xyqb/service/captcha/IQuantgroupCaptchaService.java
+3
-3
QuantgroupCaptchaServiceImpl.java
...qb/service/captcha/impl/QuantgroupCaptchaServiceImpl.java
+4
-4
GeetestCaptchaServiceTest.java
src/test/java/demo/GeetestCaptchaServiceTest.java
+40
-0
QuantgroupCaptchaServiceTest.java
src/test/java/demo/QuantgroupCaptchaServiceTest.java
+37
-0
No files found.
src/main/java/cn/quantgroup/xyqb/service/captcha/IQuantgroupCaptchaService.java
View file @
cb7fd9c5
...
@@ -17,9 +17,9 @@ public interface IQuantgroupCaptchaService {
...
@@ -17,9 +17,9 @@ public interface IQuantgroupCaptchaService {
/**
/**
* 校验QG验证码
* 校验QG验证码
* @param
key
* @param
captchaId
* @param c
od
e
* @param c
aptchaValu
e
* @return
* @return
*/
*/
boolean
validQuantgroupCaptcha
(
String
key
,
String
cod
e
);
boolean
validQuantgroupCaptcha
(
String
captchaId
,
String
captchaValu
e
);
}
}
src/main/java/cn/quantgroup/xyqb/service/captcha/impl/QuantgroupCaptchaServiceImpl.java
View file @
cb7fd9c5
...
@@ -53,14 +53,14 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
...
@@ -53,14 +53,14 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
}
}
@Override
@Override
public
boolean
validQuantgroupCaptcha
(
String
key
,
String
cod
e
)
{
public
boolean
validQuantgroupCaptcha
(
String
captchaId
,
String
captchaValu
e
)
{
boolean
validCaptcha
=
false
;
boolean
validCaptcha
=
false
;
if
(
StringUtils
.
isNotBlank
(
key
)
&&
StringUtils
.
isNotBlank
(
cod
e
))
{
if
(
StringUtils
.
isNotBlank
(
captchaId
)
&&
StringUtils
.
isNotBlank
(
captchaValu
e
))
{
// 验证码校验(忽略用户输入的大小写)
// 验证码校验(忽略用户输入的大小写)
try
{
try
{
validCaptcha
=
Boolean
.
valueOf
(
imageCaptchaService
.
validateResponseForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
key
,
code
.
toLowerCase
()
));
validCaptcha
=
imageCaptchaService
.
validateResponseForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
captchaId
,
captchaValue
.
toLowerCase
(
));
}
catch
(
CaptchaServiceException
e
)
{
}
catch
(
CaptchaServiceException
e
)
{
log
.
error
(
"校验QG图形验证码:key:{}, code:{}"
,
key
,
cod
e
,
e
);
log
.
error
(
"校验QG图形验证码:key:{}, code:{}"
,
captchaId
,
captchaValu
e
,
e
);
}
}
}
}
return
validCaptcha
;
return
validCaptcha
;
...
...
src/test/java/demo/GeetestCaptchaServiceTest.java
0 → 100644
View file @
cb7fd9c5
package
demo
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.model.ClientType
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
javax.annotation.Resource
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
public
class
GeetestCaptchaServiceTest
{
@Resource
private
IGeetestCaptchaService
geetestCaptchaService
;
@Test
public
void
testFetchGeetestCaptcha
(){
Assert
.
assertNotEquals
(
null
,
geetestCaptchaService
.
fetchGeetestCaptcha
(
PasswordUtil
.
MD5
(
"18010043006"
),
"127.0.0.1"
,
ClientType
.
APP
));
}
@Test
public
void
testValidGeetestCaptcha
(){
String
challenge
=
"d6e965e06b187c0a01276834d2ff00e6"
;
String
validate
=
"validate"
;
String
seccode
=
"seccode"
;
Assert
.
assertEquals
(
true
,
geetestCaptchaService
.
validGeetestCaptcha
(
ClientType
.
APP
,
"127.0.0.1"
,
PasswordUtil
.
MD5
(
"18010043006"
),
challenge
,
validate
,
seccode
));
}
}
src/test/java/demo/QuantgroupCaptchaServiceTest.java
0 → 100644
View file @
cb7fd9c5
package
demo
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService
;
import
com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
javax.annotation.Resource
;
import
java.util.Locale
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
public
class
QuantgroupCaptchaServiceTest
{
@Resource
private
IQuantgroupCaptchaService
quantgroupCaptchaService
;
@Test
public
void
testFetchQuantgroupCaptcha
(){
Locale
locale
=
Locale
.
US
;
Assert
.
assertEquals
(
null
,
quantgroupCaptchaService
.
fetchQuantgroupCaptcha
(
locale
));
}
@Test
public
void
testValidQuantgroupCaptcha
(){
String
captchaId
=
"captchaId"
;
String
captchaValue
=
"captchaValue"
;
Assert
.
assertEquals
(
true
,
quantgroupCaptchaService
.
validQuantgroupCaptcha
(
captchaId
,
captchaValue
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment