mirror of
https://github.com/netauth/ldap.git
synced 2026-11-03 11:43:44 -06:00
internal/ldap: Stop reporting success for unmatched bind requests
This commit is contained in:
parent
e88df02eff
commit
ca0e2434c7
|
|
@ -55,19 +55,10 @@ func (s *server) ServeTLS(bind, keypath, certpath string) error {
|
|||
}
|
||||
|
||||
func (s *server) handleNotFound(w ldap.ResponseWriter, r *ldap.Message) {
|
||||
switch r.ProtocolOpType() {
|
||||
case ldap.ApplicationBindRequest:
|
||||
res := ldap.NewBindResponse(ldap.LDAPResultSuccess)
|
||||
res.SetDiagnosticMessage("Default binding behavior set to return Success")
|
||||
|
||||
w.Write(res)
|
||||
|
||||
default:
|
||||
res := ldap.NewResponse(ldap.LDAPResultUnwillingToPerform)
|
||||
res.SetDiagnosticMessage("Operation not implemented by server")
|
||||
w.Write(res)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *server) handleAbandon(w ldap.ResponseWriter, m *ldap.Message) {
|
||||
var req = m.GetAbandonRequest()
|
||||
|
|
|
|||
26
internal/ldap/ldap_test.go
Normal file
26
internal/ldap/ldap_test.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package ldap
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ldap "github.com/ps78674/ldapserver"
|
||||
)
|
||||
|
||||
// The router has a catch-all NotFound handler. Even if a bind somehow
|
||||
// reaches it (for example if a future routing change lets an
|
||||
// authentication choice slip past handleBind), it must fail closed
|
||||
// rather than reporting success.
|
||||
func TestNotFoundRefusesBind(t *testing.T) {
|
||||
s := &server{l: testLogger()}
|
||||
s.nc = []string{"dc=netauth", "dc=example", "dc=com"}
|
||||
|
||||
w := &recordingWriter{}
|
||||
s.handleNotFound(w, mustDecode(t, berBindRequest("", "")))
|
||||
|
||||
if len(w.responses) != 1 {
|
||||
t.Fatalf("got %d responses, want exactly 1", len(w.responses))
|
||||
}
|
||||
if code := resultCode(t, w.responses[0]); code != ldap.LDAPResultUnwillingToPerform {
|
||||
t.Errorf("result code is %d, want %d", code, ldap.LDAPResultUnwillingToPerform)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue