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
daeba40b
Unverified
Commit
daeba40b
authored
Apr 05, 2018
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for user auth module
parent
59f83ca5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
131 additions
and
0 deletions
+131
-0
pkg/services/sqlstore/user_auth_test.go
+131
-0
No files found.
pkg/services/sqlstore/user_auth_test.go
0 → 100644
View file @
daeba40b
package
sqlstore
import
(
"fmt"
"testing"
.
"github.com/smartystreets/goconvey/convey"
m
"github.com/grafana/grafana/pkg/models"
)
func
TestUserAuth
(
t
*
testing
.
T
)
{
InitTestDB
(
t
)
Convey
(
"Given 5 users"
,
t
,
func
()
{
var
err
error
var
cmd
*
m
.
CreateUserCommand
users
:=
[]
m
.
User
{}
for
i
:=
0
;
i
<
5
;
i
++
{
cmd
=
&
m
.
CreateUserCommand
{
Email
:
fmt
.
Sprint
(
"user"
,
i
,
"@test.com"
),
Name
:
fmt
.
Sprint
(
"user"
,
i
),
Login
:
fmt
.
Sprint
(
"loginuser"
,
i
),
}
err
=
CreateUser
(
cmd
)
So
(
err
,
ShouldBeNil
)
users
=
append
(
users
,
cmd
.
Result
)
}
Reset
(
func
()
{
_
,
err
:=
x
.
Exec
(
"DELETE FROM org_user WHERE 1=1"
)
So
(
err
,
ShouldBeNil
)
_
,
err
=
x
.
Exec
(
"DELETE FROM org WHERE 1=1"
)
So
(
err
,
ShouldBeNil
)
_
,
err
=
x
.
Exec
(
"DELETE FROM user WHERE 1=1"
)
So
(
err
,
ShouldBeNil
)
_
,
err
=
x
.
Exec
(
"DELETE FROM user_auth WHERE 1=1"
)
So
(
err
,
ShouldBeNil
)
})
Convey
(
"Can find existing user"
,
func
()
{
// By Login
login
:=
"loginuser0"
query
:=
&
m
.
GetUserByAuthInfoQuery
{
Login
:
login
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Login
,
ShouldEqual
,
login
)
// By ID
id
:=
query
.
Result
.
Id
query
=
&
m
.
GetUserByAuthInfoQuery
{
UserId
:
id
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Id
,
ShouldEqual
,
id
)
// By Email
email
:=
"user1@test.com"
query
=
&
m
.
GetUserByAuthInfoQuery
{
Email
:
email
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Email
,
ShouldEqual
,
email
)
// Don't find nonexistent user
email
=
"nonexistent@test.com"
query
=
&
m
.
GetUserByAuthInfoQuery
{
Email
:
email
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldEqual
,
m
.
ErrUserNotFound
)
So
(
query
.
Result
,
ShouldBeNil
)
})
Convey
(
"Can set & locate by AuthModule and AuthId"
,
func
()
{
// get nonexistent user_auth entry
query
:=
&
m
.
GetUserByAuthInfoQuery
{
AuthModule
:
"test"
,
AuthId
:
"test"
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldEqual
,
m
.
ErrUserNotFound
)
So
(
query
.
Result
,
ShouldBeNil
)
// create user_auth entry
login
:=
"loginuser0"
query
.
Login
=
login
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Login
,
ShouldEqual
,
login
)
// get via user_auth
query
=
&
m
.
GetUserByAuthInfoQuery
{
AuthModule
:
"test"
,
AuthId
:
"test"
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Login
,
ShouldEqual
,
login
)
// get with non-matching id
id
:=
query
.
Result
.
Id
query
.
UserId
=
id
+
1
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Login
,
ShouldEqual
,
"loginuser1"
)
// get via user_auth
query
=
&
m
.
GetUserByAuthInfoQuery
{
AuthModule
:
"test"
,
AuthId
:
"test"
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
query
.
Result
.
Login
,
ShouldEqual
,
"loginuser1"
)
// remove user
_
,
err
=
x
.
Exec
(
"DELETE FROM user WHERE id=?"
,
query
.
Result
.
Id
)
So
(
err
,
ShouldBeNil
)
// get via user_auth for deleted user
query
=
&
m
.
GetUserByAuthInfoQuery
{
AuthModule
:
"test"
,
AuthId
:
"test"
}
err
=
GetUserByAuthInfo
(
query
)
So
(
err
,
ShouldEqual
,
m
.
ErrUserNotFound
)
So
(
query
.
Result
,
ShouldBeNil
)
})
})
}
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