4d970d5fc4
Authentication is performed by binding to the configured LDAP server using the user supplied credentials. Successfull bind equals authenticated user. Optionally the connector can be configured to search before authentication. The entryDN found will be used to bind to the LDAP server. This feature must be enabled to get supplementary information from the directory (ID, Name, Email). This feature can also be used to limit access to the service. Example use case: Allow your users to log in with e-mail address instead of the identification string in your DNs (typically username). To make re-use of HTTP form handling code from the Local connector possible: - Implemented IdentityProvider interface - Moved the re-used functions to login_local.go Fixes #119
94 lines
1.8 KiB
Go
94 lines
1.8 KiB
Go
package connector
|
|
|
|
import (
|
|
"html/template"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/coreos/go-oidc/oidc"
|
|
)
|
|
|
|
var (
|
|
ns url.URL
|
|
lf oidc.LoginFunc
|
|
templates *template.Template
|
|
)
|
|
|
|
func init() {
|
|
templates = template.New(LDAPLoginPageTemplateName)
|
|
}
|
|
|
|
func TestLDAPConnectorConfigValidTLS(t *testing.T) {
|
|
cc := LDAPConnectorConfig{
|
|
ID: "ldap",
|
|
UseTLS: true,
|
|
UseSSL: false,
|
|
}
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestLDAPConnectorConfigInvalidSSLandTLS(t *testing.T) {
|
|
cc := LDAPConnectorConfig{
|
|
ID: "ldap",
|
|
UseTLS: true,
|
|
UseSSL: true,
|
|
}
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
if err == nil {
|
|
t.Fatal("Expected LDAPConnector initialization to fail when both TLS and SSL enabled.")
|
|
}
|
|
}
|
|
|
|
func TestLDAPConnectorConfigValidSearchScope(t *testing.T) {
|
|
cc := LDAPConnectorConfig{
|
|
ID: "ldap",
|
|
SearchScope: "one",
|
|
}
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestLDAPConnectorConfigInvalidSearchScope(t *testing.T) {
|
|
cc := LDAPConnectorConfig{
|
|
ID: "ldap",
|
|
SearchScope: "three",
|
|
}
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
if err == nil {
|
|
t.Fatal("Expected LDAPConnector initialization to fail when invalid value provided for SearchScope.")
|
|
}
|
|
}
|
|
|
|
func TestLDAPConnectorConfigInvalidCertFileNoKeyFile(t *testing.T) {
|
|
cc := LDAPConnectorConfig{
|
|
ID: "ldap",
|
|
CertFile: "/tmp/ldap.crt",
|
|
}
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
if err == nil {
|
|
t.Fatal("Expected LDAPConnector initialization to fail when CertFile specified without KeyFile.")
|
|
}
|
|
}
|
|
|
|
func TestLDAPConnectorConfigValidCertFileAndKeyFile(t *testing.T) {
|
|
cc := LDAPConnectorConfig{
|
|
ID: "ldap",
|
|
CertFile: "/tmp/ldap.crt",
|
|
KeyFile: "/tmp/ldap.key",
|
|
}
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|