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
a0f5923b
Unverified
Commit
a0f5923b
authored
May 20, 2019
by
Oleg Gaidarenko
Committed by
GitHub
May 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LDAP: add tests for initialBind (#17132)
* LDAP: add tests for initialBind * LDAP: clarify comment for Login()
parent
db48ec1f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
5 deletions
+70
-5
pkg/services/ldap/ldap.go
+5
-5
pkg/services/ldap/ldap_helpers_test.go
+65
-0
No files found.
pkg/services/ldap/ldap.go
View file @
a0f5923b
...
@@ -122,13 +122,13 @@ func (server *Server) Close() {
...
@@ -122,13 +122,13 @@ func (server *Server) Close() {
server
.
connection
.
Close
()
server
.
connection
.
Close
()
}
}
// Log
in intialBinds the user, search it and then serialize
it
// Log
in user by searching and serializing
it
func
(
server
*
Server
)
Login
(
query
*
models
.
LoginUserQuery
)
(
func
(
server
*
Server
)
Login
(
query
*
models
.
LoginUserQuery
)
(
*
models
.
ExternalUserInfo
,
error
,
*
models
.
ExternalUserInfo
,
error
,
)
{
)
{
// Perform initial authentication
// Perform initial authentication
err
:=
server
.
intialBind
(
query
.
Username
,
query
.
Password
)
err
:=
server
.
in
i
tialBind
(
query
.
Username
,
query
.
Password
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -159,7 +159,7 @@ func (server *Server) Login(query *models.LoginUserQuery) (
...
@@ -159,7 +159,7 @@ func (server *Server) Login(query *models.LoginUserQuery) (
// Add adds stuff to LDAP
// Add adds stuff to LDAP
func
(
server
*
Server
)
Add
(
dn
string
,
values
map
[
string
][]
string
)
error
{
func
(
server
*
Server
)
Add
(
dn
string
,
values
map
[
string
][]
string
)
error
{
err
:=
server
.
intialBind
(
err
:=
server
.
in
i
tialBind
(
server
.
config
.
BindDN
,
server
.
config
.
BindDN
,
server
.
config
.
BindPassword
,
server
.
config
.
BindPassword
,
)
)
...
@@ -190,7 +190,7 @@ func (server *Server) Add(dn string, values map[string][]string) error {
...
@@ -190,7 +190,7 @@ func (server *Server) Add(dn string, values map[string][]string) error {
// Remove removes stuff from LDAP
// Remove removes stuff from LDAP
func
(
server
*
Server
)
Remove
(
dn
string
)
error
{
func
(
server
*
Server
)
Remove
(
dn
string
)
error
{
err
:=
server
.
intialBind
(
err
:=
server
.
in
i
tialBind
(
server
.
config
.
BindDN
,
server
.
config
.
BindDN
,
server
.
config
.
BindPassword
,
server
.
config
.
BindPassword
,
)
)
...
@@ -381,7 +381,7 @@ func (server *Server) secondBind(
...
@@ -381,7 +381,7 @@ func (server *Server) secondBind(
return
nil
return
nil
}
}
func
(
server
*
Server
)
intialBind
(
username
,
userPassword
string
)
error
{
func
(
server
*
Server
)
in
i
tialBind
(
username
,
userPassword
string
)
error
{
if
server
.
config
.
BindPassword
!=
""
||
server
.
config
.
BindDN
==
""
{
if
server
.
config
.
BindPassword
!=
""
||
server
.
config
.
BindDN
==
""
{
userPassword
=
server
.
config
.
BindPassword
userPassword
=
server
.
config
.
BindPassword
server
.
requireSecondBind
=
true
server
.
requireSecondBind
=
true
...
...
pkg/services/ldap/ldap_helpers_test.go
View file @
a0f5923b
...
@@ -75,6 +75,71 @@ func TestLDAPHelpers(t *testing.T) {
...
@@ -75,6 +75,71 @@ func TestLDAPHelpers(t *testing.T) {
})
})
})
})
Convey
(
"initialBind"
,
t
,
func
()
{
Convey
(
"Given bind dn and password configured"
,
func
()
{
connection
:=
&
mockConnection
{}
var
actualUsername
,
actualPassword
string
connection
.
bindProvider
=
func
(
username
,
password
string
)
error
{
actualUsername
=
username
actualPassword
=
password
return
nil
}
server
:=
&
Server
{
connection
:
connection
,
config
:
&
ServerConfig
{
BindDN
:
"cn=%s,o=users,dc=grafana,dc=org"
,
BindPassword
:
"bindpwd"
,
},
}
err
:=
server
.
initialBind
(
"user"
,
"pwd"
)
So
(
err
,
ShouldBeNil
)
So
(
server
.
requireSecondBind
,
ShouldBeTrue
)
So
(
actualUsername
,
ShouldEqual
,
"cn=user,o=users,dc=grafana,dc=org"
)
So
(
actualPassword
,
ShouldEqual
,
"bindpwd"
)
})
Convey
(
"Given bind dn configured"
,
func
()
{
connection
:=
&
mockConnection
{}
var
actualUsername
,
actualPassword
string
connection
.
bindProvider
=
func
(
username
,
password
string
)
error
{
actualUsername
=
username
actualPassword
=
password
return
nil
}
server
:=
&
Server
{
connection
:
connection
,
config
:
&
ServerConfig
{
BindDN
:
"cn=%s,o=users,dc=grafana,dc=org"
,
},
}
err
:=
server
.
initialBind
(
"user"
,
"pwd"
)
So
(
err
,
ShouldBeNil
)
So
(
server
.
requireSecondBind
,
ShouldBeFalse
)
So
(
actualUsername
,
ShouldEqual
,
"cn=user,o=users,dc=grafana,dc=org"
)
So
(
actualPassword
,
ShouldEqual
,
"pwd"
)
})
Convey
(
"Given empty bind dn and password"
,
func
()
{
connection
:=
&
mockConnection
{}
unauthenticatedBindWasCalled
:=
false
var
actualUsername
string
connection
.
unauthenticatedBindProvider
=
func
(
username
string
)
error
{
unauthenticatedBindWasCalled
=
true
actualUsername
=
username
return
nil
}
server
:=
&
Server
{
connection
:
connection
,
config
:
&
ServerConfig
{},
}
err
:=
server
.
initialBind
(
"user"
,
"pwd"
)
So
(
err
,
ShouldBeNil
)
So
(
server
.
requireSecondBind
,
ShouldBeTrue
)
So
(
unauthenticatedBindWasCalled
,
ShouldBeTrue
)
So
(
actualUsername
,
ShouldBeEmpty
)
})
})
Convey
(
"serverBind()"
,
t
,
func
()
{
Convey
(
"serverBind()"
,
t
,
func
()
{
Convey
(
"Given bind dn and password configured"
,
func
()
{
Convey
(
"Given bind dn and password configured"
,
func
()
{
connection
:=
&
mockConnection
{}
connection
:=
&
mockConnection
{}
...
...
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