github.com/infraboard/keyauth@v0.8.1/apps/provider/auth/ldap/ldap_test.go (about)

     1  package ldap_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/infraboard/mcube/logger/zap"
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/infraboard/keyauth/apps/provider/auth/ldap"
    10  )
    11  
    12  func TestConn(t *testing.T) {
    13  	should := assert.New(t)
    14  
    15  	conf := ldap.NewDefaultConfig()
    16  	conf.URL = "ldap://127.0.0.1:389"
    17  	conf.User = "cn=admin,dc=example,dc=org"
    18  	conf.Password = "admin"
    19  	conf.BaseDN = "dc=example,dc=org"
    20  	conf.UsersFilter = "(uid={input})"
    21  
    22  	p := ldap.NewProvider(conf)
    23  	ok, err := p.CheckUserPassword("yumaojun", "123456")
    24  	should.NoError(err)
    25  	should.True(ok)
    26  }
    27  
    28  func TestUserDetail(t *testing.T) {
    29  	should := assert.New(t)
    30  
    31  	conf := ldap.NewDefaultConfig()
    32  	conf.URL = "ldap://127.0.0.1:389"
    33  	conf.User = "cn=admin,dc=example,dc=org"
    34  	conf.Password = "admin"
    35  	conf.BaseDN = "dc=example,dc=org"
    36  
    37  	p := ldap.NewProvider(conf)
    38  	ud, err := p.GetDetails("yumaojun")
    39  	should.NoError(err)
    40  	should.Equal("", ud)
    41  }
    42  
    43  func TestGetBaseDNFromUser(t *testing.T) {
    44  	should := assert.New(t)
    45  
    46  	conf := ldap.NewDefaultConfig()
    47  	conf.User = "cn=admin,dc=example,dc=org"
    48  	baseDN := conf.GetBaseDNFromUser()
    49  
    50  	should.Equal("dc=example,dc=org", baseDN)
    51  }
    52  
    53  func init() {
    54  	zap.DevelopmentSetup()
    55  }