2015-11-11 01:08:40 +05:30
|
|
|
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",
|
2016-06-22 05:11:04 +05:30
|
|
|
Host: "example.com:636",
|
2015-11-11 01:08:40 +05:30
|
|
|
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",
|
2016-06-22 05:11:04 +05:30
|
|
|
Host: "example.com:636",
|
2015-11-11 01:08:40 +05:30
|
|
|
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",
|
2016-06-22 05:11:04 +05:30
|
|
|
Host: "example.com:636",
|
2015-11-11 01:08:40 +05:30
|
|
|
SearchScope: "one",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLDAPConnectorConfigInvalidSearchScope(t *testing.T) {
|
|
|
|
cc := LDAPConnectorConfig{
|
|
|
|
ID: "ldap",
|
2016-06-22 05:11:04 +05:30
|
|
|
Host: "example.com:636",
|
2015-11-11 01:08:40 +05:30
|
|
|
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",
|
2016-06-22 05:11:04 +05:30
|
|
|
Host: "example.com:636",
|
2015-11-11 01:08:40 +05:30
|
|
|
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",
|
2016-06-22 05:11:04 +05:30
|
|
|
Host: "example.com:636",
|
2015-11-11 01:08:40 +05:30
|
|
|
CertFile: "/tmp/ldap.crt",
|
|
|
|
KeyFile: "/tmp/ldap.key",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := cc.Connector(ns, lf, templates)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|