FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
VerificationCodeService/core/code/code_test.go at master · ZeroTechh/VerificationCodeService · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ZeroTechh
/
VerificationCodeService
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
VerificationCodeService
/
core
/
code
/
code_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (35 loc) · 1.31 KB
Breadcrumbs
VerificationCodeService
/
core
/
code
/
code_test.go
Copy path
File metadata and controls
43 lines (35 loc) · 1.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package
code
import
(
"testing"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/stretchr/testify/assert"
)
func
expiredToken
() (
string
,
error
) {
c
:=
claims
(
"test"
)
c
.
ExpirationUTC
=
time
.
Now
().
Unix
()
t
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
c
)
return
t
.
SignedString
(
secret
)
}
func
TestCode
(
t
*
testing.
T
) {
assert
:=
assert
.
New
(
t
)
// Testing creation of a token
token
,
err
:=
Create
(
"Test"
)
assert
.
NoError
(
err
)
assert
.
NotZero
(
token
)
// Testing Validation of a token
valid
,
id
:=
Validate
(
token
)
assert
.
True
(
valid
)
assert
.
Equal
(
"Test"
,
id
)
// Testing if validate can detect invalid token
invalid
:=
"eyJhbGciOiJQUzM4NCIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.MqF1AKsJkijKnfqEI3VA1OnzAL2S4eIpAuievMgD3tEFyFMU67gCbg-fxsc5dLrxNwdZEXs9h0kkicJZ70mp6p5vdv-j2ycDKBWg05Un4OhEl7lYcdIsCsB8QUPmstF-lQWnNqnq3wra1GynJrOXDL27qIaJnnQKlXuayFntBF0j-82jpuVdMaSXvk3OGaOM-7rCRsBcSPmocaAO-uWJEGPw_OWVaC5RRdWDroPi4YL4lTkDEC-KEvVkqCnFm_40C-T_siXquh5FVbpJjb3W2_YvcqfDRj44TsRrpVhk6ohsHMNeUad_cxnFnpolIKnaXq_COv35e9EgeQIPAbgIeg"
valid
,
id
=
Validate
(
invalid
)
assert
.
False
(
valid
)
assert
.
Zero
(
id
)
// Testing if validate can detect expired token
token
,
err
=
expiredToken
()
assert
.
NoError
(
err
)
valid
,
id
=
Validate
(
token
)
assert
.
False
(
valid
)
assert
.
Zero
(
id
)
}
Back
|
FazBrowse Home
|
New Git URL