Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
56540819
Unverified
Commit
56540819
authored
Jan 21, 2019
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle expired tokens
parent
697ddccd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
pkg/services/auth/auth_token.go
+2
-1
pkg/services/auth/auth_token_test.go
+13
-4
No files found.
pkg/services/auth/auth_token.go
View file @
56540819
...
...
@@ -141,9 +141,10 @@ func (s *UserAuthTokenService) CreateToken(userId int64, clientIP, userAgent str
func
(
s
*
UserAuthTokenService
)
LookupToken
(
unhashedToken
string
)
(
*
models
.
UserAuthToken
,
error
)
{
hashedToken
:=
hashToken
(
unhashedToken
)
expireBefore
:=
now
()
.
Add
(
time
.
Duration
(
-
86400
*
setting
.
LogInRememberDays
)
*
time
.
Second
)
.
Unix
()
var
userToken
models
.
UserAuthToken
exists
,
err
:=
s
.
SQLStore
.
NewSession
()
.
Where
(
"
auth_token = ? OR prev_auth_token = ?"
,
hashedToken
,
hashedToken
)
.
Get
(
&
userToken
)
exists
,
err
:=
s
.
SQLStore
.
NewSession
()
.
Where
(
"
(auth_token = ? OR prev_auth_token = ?) AND created_at > ?"
,
hashedToken
,
hashedToken
,
expireBefore
)
.
Get
(
&
userToken
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/services/auth/auth_token_test.go
View file @
56540819
...
...
@@ -4,6 +4,8 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
...
...
@@ -58,9 +60,13 @@ func TestUserAuthToken(t *testing.T) {
token
,
err
=
ctx
.
getAuthTokenByID
(
token
.
Id
)
So
(
err
,
ShouldBeNil
)
// set now (now - 23 hours)
_
,
err
=
userAuthTokenService
.
RefreshToken
(
token
,
"192.168.10.11:1234"
,
"some user agent"
)
now
=
func
()
time
.
Time
{
return
t
.
Add
(
time
.
Hour
)
}
refreshed
,
err
:=
userAuthTokenService
.
RefreshToken
(
token
,
"192.168.10.11:1234"
,
"some user agent"
)
So
(
err
,
ShouldBeNil
)
So
(
refreshed
,
ShouldBeTrue
)
_
,
err
=
userAuthTokenService
.
LookupToken
(
token
.
UnhashedToken
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -69,7 +75,9 @@ func TestUserAuthToken(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
stillGood
,
ShouldNotBeNil
)
// set now (new - 2 hours)
now
=
func
()
time
.
Time
{
return
t
.
Add
(
24
*
7
*
time
.
Hour
)
}
notGood
,
err
:=
userAuthTokenService
.
LookupToken
(
token
.
UnhashedToken
)
So
(
err
,
ShouldEqual
,
ErrAuthTokenNotFound
)
So
(
notGood
,
ShouldBeNil
)
...
...
@@ -93,7 +101,7 @@ func TestUserAuthToken(t *testing.T) {
// ability to auth using an old token
now
=
func
()
time
.
Time
{
return
t
return
t
.
Add
(
time
.
Hour
)
}
refreshed
,
err
=
userAuthTokenService
.
RefreshToken
(
token
,
"192.168.10.12:1234"
,
"a new user agent"
)
...
...
@@ -172,6 +180,7 @@ func createTestContext(t *testing.T) *testContext {
RotateTime
=
10
*
time
.
Minute
UrgentRotateTime
=
time
.
Minute
setting
.
LogInRememberDays
=
7
return
&
testContext
{
sqlstore
:
sqlstore
,
...
...
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