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
03c58bf5
Commit
03c58bf5
authored
Feb 06, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
验证码jUnit测试类框架,待完善
parent
9783b968
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
39 deletions
+50
-39
CaptchaNewValidateAdvisor.java
...tgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
+1
-1
IGeetestCaptchaService.java
...antgroup/xyqb/service/captcha/IGeetestCaptchaService.java
+8
-8
GeetestCaptchaServiceImpl.java
.../xyqb/service/captcha/impl/GeetestCaptchaServiceImpl.java
+6
-6
CaptchaVerifyTests.java
src/test/java/CaptchaVerifyTests.java
+8
-0
CommonTests.java
src/test/java/CommonTests.java
+0
-22
DemoTests.java
src/test/java/DemoTests.java
+9
-0
UserAuthorizedTests.java
src/test/java/UserAuthorizedTests.java
+9
-0
GeetestCaptchaServiceTest.java
src/test/java/service/GeetestCaptchaServiceTest.java
+9
-2
No files found.
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
View file @
03c58bf5
...
@@ -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
);
}
}
/**
/**
...
...
src/main/java/cn/quantgroup/xyqb/service/captcha/IGeetestCaptchaService.java
View file @
03c58bf5
...
@@ -12,25 +12,25 @@ public interface IGeetestCaptchaService {
...
@@ -12,25 +12,25 @@ public interface IGeetestCaptchaService {
/**
/**
* 获取极验验证码
* 获取极验验证码
*
*
* @param mark
Str 标示
* @param mark
Id 用户标识
* @param remoteIp
* @param remoteIp
请求终端真实IP
* @param clientType
* @param clientType
请求终端类型
* @return 获取失败返回null
* @return 获取失败返回null
*/
*/
Map
<
String
,
String
>
fetchGeetestCaptcha
(
String
mark
Str
,
String
remoteIp
,
ClientType
clientType
);
Map
<
String
,
String
>
fetchGeetestCaptcha
(
String
mark
Id
,
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
);
}
}
src/main/java/cn/quantgroup/xyqb/service/captcha/impl/GeetestCaptchaServiceImpl.java
View file @
03c58bf5
...
@@ -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
mark
Str
,
String
remoteIp
,
ClientType
clientType
)
{
public
Map
<
String
,
String
>
fetchGeetestCaptcha
(
String
mark
Id
,
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
(
mark
Str
,
remoteIp
,
clientType
);
HashMap
<
String
,
String
>
param
=
getParam
(
mark
Id
,
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
(
mark
Str
,
remoteIp
,
clientType
);
HashMap
<
String
,
String
>
param
=
getParam
(
mark
Id
,
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
mark
Str
,
String
remoteIp
,
ClientType
clientType
)
{
private
HashMap
<
String
,
String
>
getParam
(
String
mark
Id
,
String
remoteIp
,
ClientType
clientType
)
{
HashMap
<
String
,
String
>
param
=
new
HashMap
<>();
HashMap
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"user_id"
,
mark
Str
);
param
.
put
(
"user_id"
,
mark
Id
);
if
(
Objects
.
isNull
(
clientType
))
{
if
(
Objects
.
isNull
(
clientType
))
{
param
.
put
(
"client_type"
,
ClientType
.
APP
.
name
());
param
.
put
(
"client_type"
,
ClientType
.
APP
.
name
());
}
else
{
}
else
{
...
...
src/test/java/CaptchaVerifyTests.java
0 → 100644
View file @
03c58bf5
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
src/test/java/CommonTests.java
deleted
100644 → 0
View file @
9783b968
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
));
}
}
src/test/java/DemoTests.java
0 → 100644
View file @
03c58bf5
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
src/test/java/UserAuthorizedTests.java
0 → 100644
View file @
03c58bf5
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
src/test/java/service/GeetestCaptchaServiceTest.java
View file @
03c58bf5
...
@@ -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
));
}
}
}
}
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