Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofumpt #427

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion add.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func NewAddRequest(dn string, controls []Control) *AddRequest {
DN: dn,
Controls: controls,
}

}

// Add performs the given AddRequest
Expand Down
7 changes: 3 additions & 4 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func parseParams(str string) (map[string]string, error) {
var state int
for i := 0; i <= len(str); i++ {
switch state {
case 0: //reading key
case 0: // reading key
if i == len(str) {
return nil, fmt.Errorf("syntax error on %d", i)
}
Expand All @@ -270,7 +270,7 @@ func parseParams(str string) (map[string]string, error) {
continue
}
state = 1
case 1: //reading value
case 1: // reading value
if i == len(str) {
m[key] = value
break
Expand All @@ -289,7 +289,7 @@ func parseParams(str string) (map[string]string, error) {
default:
value += string(str[i])
}
case 2: //inside quotes
case 2: // inside quotes
if i == len(str) {
return nil, fmt.Errorf("syntax error on %d", i)
}
Expand Down Expand Up @@ -651,7 +651,6 @@ func (l *Conn) GSSAPIBindRequest(client GSSAPIClient, req *GSSAPIBindRequest) er
}

func (l *Conn) saslBindTokenExchange(reqControls []Control, reqToken []byte) ([]byte, error) {

// Construct LDAP Bind request with GSSAPI SASL mechanism.
envelope := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
envelope.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
Expand Down
3 changes: 2 additions & 1 deletion compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
msgCtx, err := l.doRequest(&CompareRequest{
DN: dn,
Attribute: attribute,
Value: value})
Value: value,
})
if err != nil {
return false, err
}
Expand Down
47 changes: 32 additions & 15 deletions dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,72 @@ func TestSuccessfulDNParsing(t *testing.T) {
"cn=Jim\\2C \\22Hasse Hö\\22 Hansson!,dc=dummy,dc=com": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "Jim, \"Hasse Hö\" Hansson!"}}},
{[]*AttributeTypeAndValue{{"dc", "dummy"}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}},
}},
"UID=jsmith,DC=example,DC=net": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"UID", "jsmith"}}},
{[]*AttributeTypeAndValue{{"DC", "example"}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}},
}},
"OU=Sales+CN=J. Smith,DC=example,DC=net": {[]*RelativeDN{
{[]*AttributeTypeAndValue{
{"OU", "Sales"},
{"CN", "J. Smith"}}},
{"CN", "J. Smith"},
}},
{[]*AttributeTypeAndValue{{"DC", "example"}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}},
}},
"1.3.6.1.4.1.1466.0=#04024869": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"1.3.6.1.4.1.1466.0", "Hi"}}}}},
{[]*AttributeTypeAndValue{{"1.3.6.1.4.1.1466.0", "Hi"}}},
}},
"1.3.6.1.4.1.1466.0=#04024869,DC=net": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"1.3.6.1.4.1.1466.0", "Hi"}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}},
}},
"CN=Lu\\C4\\8Di\\C4\\87": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}}}},
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}},
}},
" CN = Lu\\C4\\8Di\\C4\\87 ": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}}}},
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}},
}},
` A = 1 , B = 2 `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"A", "1"}}},
{[]*AttributeTypeAndValue{{"B", "2"}}}}},
{[]*AttributeTypeAndValue{{"B", "2"}}},
}},
` A = 1 + B = 2 `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{
{"A", "1"},
{"B", "2"}}}}},
{"B", "2"},
}},
}},
` \ \ A\ \ = \ \ 1\ \ , \ \ B\ \ = \ \ 2\ \ `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{" A ", " 1 "}}},
{[]*AttributeTypeAndValue{{" B ", " 2 "}}}}},
{[]*AttributeTypeAndValue{{" B ", " 2 "}}},
}},
` \ \ A\ \ = \ \ 1\ \ + \ \ B\ \ = \ \ 2\ \ `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{
{" A ", " 1 "},
{" B ", " 2 "}}}}},
{" B ", " 2 "},
}},
}},

`cn=john.doe;dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}},
}},

// Escaped `;` should not be treated as RDN
`cn=john.doe\;weird name,dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}},
}},
`cn=ZXhhbXBsZVRleHQ=,dc=dummy,dc=com`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "ZXhhbXBsZVRleHQ="}}},
{[]*AttributeTypeAndValue{{"dc", "dummy"}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}},
}},
}

for test, answer := range testcases {
Expand Down
6 changes: 3 additions & 3 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ func ExampleControlPaging_manualPaging() {

// This example demonstrates how to use EXTERNAL SASL with TLS client certificates.
func ExampleConn_ExternalBind() {
var ldapCert = "/path/to/cert.pem"
var ldapKey = "/path/to/key.pem"
var ldapCAchain = "/path/to/ca_chain.pem"
ldapCert := "/path/to/cert.pem"
ldapKey := "/path/to/key.pem"
ldapCAchain := "/path/to/ca_chain.pem"

// Load client cert and key
cert, err := tls.LoadX509KeyPair(ldapCert, ldapKey)
Expand Down
1 change: 0 additions & 1 deletion examples_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// This example demonstrates passwordless bind using the current process' user
// credentials on Windows (SASL GSSAPI mechanism bind with SSPI client).
func ExampleConn_SSPIClient_GSSAPIBind() {

// Windows only: Create a GSSAPIClient using Windows built-in SSPI lib
// (secur32.dll).
// This will use the credentials of the current process' user.
Expand Down
1 change: 0 additions & 1 deletion gssapi/sspi.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func (c *SSPIClient) InitSecContext(target string, token []byte) ([]byte, bool,
// NegotiateSaslAuth performs the last step of the SASL handshake.
// See RFC 4752 section 3.1.
func (c *SSPIClient) NegotiateSaslAuth(token []byte, authzid string) ([]byte, error) {

// Using SSPI rather than of GSSAPI, relevant documentation of differences here:
// https://learn.microsoft.com/en-us/windows/win32/secauthn/sspi-kerberos-interoperability-with-gssapi

Expand Down
6 changes: 2 additions & 4 deletions search_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ldap

import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

// TestNewEntry tests that repeated calls to NewEntry return the same value with the same input
Expand Down Expand Up @@ -51,7 +52,6 @@ func TestGetAttributeValue(t *testing.T) {
}

func TestEntry_Unmarshal(t *testing.T) {

t.Run("passing a struct should fail", func(t *testing.T) {
entry := &Entry{}

Expand Down Expand Up @@ -131,7 +131,6 @@ func TestEntry_Unmarshal(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, expect, result)

})

t.Run("group struct be decoded", func(t *testing.T) {
Expand Down Expand Up @@ -169,5 +168,4 @@ func TestEntry_Unmarshal(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expect, result)
})

}
1 change: 0 additions & 1 deletion v3/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func NewAddRequest(dn string, controls []Control) *AddRequest {
DN: dn,
Controls: controls,
}

}

// Add performs the given AddRequest
Expand Down
7 changes: 3 additions & 4 deletions v3/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func parseParams(str string) (map[string]string, error) {
var state int
for i := 0; i <= len(str); i++ {
switch state {
case 0: //reading key
case 0: // reading key
if i == len(str) {
return nil, fmt.Errorf("syntax error on %d", i)
}
Expand All @@ -270,7 +270,7 @@ func parseParams(str string) (map[string]string, error) {
continue
}
state = 1
case 1: //reading value
case 1: // reading value
if i == len(str) {
m[key] = value
break
Expand All @@ -289,7 +289,7 @@ func parseParams(str string) (map[string]string, error) {
default:
value += string(str[i])
}
case 2: //inside quotes
case 2: // inside quotes
if i == len(str) {
return nil, fmt.Errorf("syntax error on %d", i)
}
Expand Down Expand Up @@ -651,7 +651,6 @@ func (l *Conn) GSSAPIBindRequest(client GSSAPIClient, req *GSSAPIBindRequest) er
}

func (l *Conn) saslBindTokenExchange(reqControls []Control, reqToken []byte) ([]byte, error) {

// Construct LDAP Bind request with GSSAPI SASL mechanism.
envelope := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request")
envelope.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, l.nextMessageID(), "MessageID"))
Expand Down
3 changes: 2 additions & 1 deletion v3/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
msgCtx, err := l.doRequest(&CompareRequest{
DN: dn,
Attribute: attribute,
Value: value})
Value: value,
})
if err != nil {
return false, err
}
Expand Down
1 change: 1 addition & 0 deletions v3/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ type ControlServerSideSortingResult struct {
func (control *ControlServerSideSortingResult) GetControlType() string {
return ControlTypeServerSideSortingResult
}

func (c *ControlServerSideSortingResult) Encode() *ber.Packet {
packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "SortResult sequence")
sortResult := ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, int64(c.Result), "SortResult")
Expand Down
47 changes: 32 additions & 15 deletions v3/dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,72 @@ func TestSuccessfulDNParsing(t *testing.T) {
"cn=Jim\\2C \\22Hasse Hö\\22 Hansson!,dc=dummy,dc=com": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "Jim, \"Hasse Hö\" Hansson!"}}},
{[]*AttributeTypeAndValue{{"dc", "dummy"}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}},
}},
"UID=jsmith,DC=example,DC=net": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"UID", "jsmith"}}},
{[]*AttributeTypeAndValue{{"DC", "example"}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}},
}},
"OU=Sales+CN=J. Smith,DC=example,DC=net": {[]*RelativeDN{
{[]*AttributeTypeAndValue{
{"OU", "Sales"},
{"CN", "J. Smith"}}},
{"CN", "J. Smith"},
}},
{[]*AttributeTypeAndValue{{"DC", "example"}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}},
}},
"1.3.6.1.4.1.1466.0=#04024869": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"1.3.6.1.4.1.1466.0", "Hi"}}}}},
{[]*AttributeTypeAndValue{{"1.3.6.1.4.1.1466.0", "Hi"}}},
}},
"1.3.6.1.4.1.1466.0=#04024869,DC=net": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"1.3.6.1.4.1.1466.0", "Hi"}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}}}},
{[]*AttributeTypeAndValue{{"DC", "net"}}},
}},
"CN=Lu\\C4\\8Di\\C4\\87": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}}}},
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}},
}},
" CN = Lu\\C4\\8Di\\C4\\87 ": {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}}}},
{[]*AttributeTypeAndValue{{"CN", "Lučić"}}},
}},
` A = 1 , B = 2 `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"A", "1"}}},
{[]*AttributeTypeAndValue{{"B", "2"}}}}},
{[]*AttributeTypeAndValue{{"B", "2"}}},
}},
` A = 1 + B = 2 `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{
{"A", "1"},
{"B", "2"}}}}},
{"B", "2"},
}},
}},
` \ \ A\ \ = \ \ 1\ \ , \ \ B\ \ = \ \ 2\ \ `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{" A ", " 1 "}}},
{[]*AttributeTypeAndValue{{" B ", " 2 "}}}}},
{[]*AttributeTypeAndValue{{" B ", " 2 "}}},
}},
` \ \ A\ \ = \ \ 1\ \ + \ \ B\ \ = \ \ 2\ \ `: {[]*RelativeDN{
{[]*AttributeTypeAndValue{
{" A ", " 1 "},
{" B ", " 2 "}}}}},
{" B ", " 2 "},
}},
}},

`cn=john.doe;dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}},
}},

// Escaped `;` should not be treated as RDN
`cn=john.doe\;weird name,dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}},
}},
`cn=ZXhhbXBsZVRleHQ=,dc=dummy,dc=com`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "ZXhhbXBsZVRleHQ="}}},
{[]*AttributeTypeAndValue{{"dc", "dummy"}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}}}},
{[]*AttributeTypeAndValue{{"dc", "com"}}},
}},
}

for test, answer := range testcases {
Expand Down
6 changes: 3 additions & 3 deletions v3/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ func ExampleControlPaging_manualPaging() {

// This example demonstrates how to use EXTERNAL SASL with TLS client certificates.
func ExampleConn_ExternalBind() {
var ldapCert = "/path/to/cert.pem"
var ldapKey = "/path/to/key.pem"
var ldapCAchain = "/path/to/ca_chain.pem"
ldapCert := "/path/to/cert.pem"
ldapKey := "/path/to/key.pem"
ldapCAchain := "/path/to/ca_chain.pem"

// Load client cert and key
cert, err := tls.LoadX509KeyPair(ldapCert, ldapKey)
Expand Down
1 change: 0 additions & 1 deletion v3/examples_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// This example demonstrates passwordless bind using the current process' user
// credentials on Windows (SASL GSSAPI mechanism bind with SSPI client).
func ExampleConn_SSPIClient_GSSAPIBind() {

// Windows only: Create a GSSAPIClient using Windows built-in SSPI lib
// (secur32.dll).
// This will use the credentials of the current process' user.
Expand Down
1 change: 0 additions & 1 deletion v3/gssapi/sspi.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ func (c *SSPIClient) InitSecContext(target string, token []byte) ([]byte, bool,
// NegotiateSaslAuth performs the last step of the SASL handshake.
// See RFC 4752 section 3.1.
func (c *SSPIClient) NegotiateSaslAuth(token []byte, authzid string) ([]byte, error) {

// Using SSPI rather than of GSSAPI, relevant documentation of differences here:
// https://learn.microsoft.com/en-us/windows/win32/secauthn/sspi-kerberos-interoperability-with-gssapi

Expand Down
Loading