當前位置: 首頁>>代碼示例>>Golang>>正文


Golang slapd.Slapd類代碼示例

本文整理匯總了Golang中github.com/bytemine/ldap-crud/slapd.Slapd的典型用法代碼示例。如果您正苦於以下問題:Golang Slapd類的具體用法?Golang Slapd怎麽用?Golang Slapd使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Slapd類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestReadAllSubtree

func TestReadAllSubtree(t *testing.T) {
	var s = new(slapd.Slapd)

	s.Config = &slapd.DefaultConfig
	err := s.StartAndInitialize()
	if err != nil {
		t.Error(err)
	}
	defer s.Stop()

	testReadAllSubtree(t)
}
開發者ID:bytemine,項目名稱:ldap-crud,代碼行數:12,代碼來源:crud_test.go

示例2: TestCreate

func TestCreate(t *testing.T) {
	var s = new(slapd.Slapd)

	s.Config = &slapd.DefaultConfig
	err := s.StartAndInitialize()
	defer s.Stop()
	if err != nil {
		t.Error(err)
	}

	testCreate(t)
}
開發者ID:bytemine,項目名稱:ldap-crud,代碼行數:12,代碼來源:crud_test.go

示例3: TestDeleteSubtree

func TestDeleteSubtree(t *testing.T) {
	var s = new(slapd.Slapd)
	s.Config = &slapd.DefaultConfig
	err := s.StartAndInitialize()
	defer s.Stop()
	if err != nil {
		t.Error(err)
	}

	lc := ldap.NewConnection("localhost:9999")
	err = lc.Connect()
	if err != nil {
		t.Error(err)
	}

	err = lc.Bind(slapd.DefaultConfig.Rootdn.Dn, slapd.DefaultConfig.Rootdn.Password)
	if err != nil {
		t.Error(err)
	}

	c := New(lc, "dc=example,dc=com")

	err = c.Create(&fritzFoobarPerson)
	if err != nil {
		t.Error(err)
	}

	var fritzSubPerson = fritzFoobarPerson
	fritzSubPerson.dn = fmt.Sprintf("sn=%v,%v", fritzSubPerson.sn, fritzFoobarPerson.Dn())

	err = c.Create(&fritzSubPerson)
	if err != nil {
		t.Error(err)
	}

	err = c.DeleteSubtree(&fritzFoobarPerson)
	if err != nil {
		t.Error(err)
	}

	err = c.Read(&fritzSubPerson)
	if err == nil {
		t.Error("object wasn't deleted from ldap")
	}

	err = c.Read(&fritzFoobarPerson)
	if err == nil {
		t.Error("object wasn't deleted from ldap")
	}
}
開發者ID:bytemine,項目名稱:ldap-crud,代碼行數:50,代碼來源:crud_test.go

示例4: TestPasswd

func TestPasswd(t *testing.T) {
	var s = new(slapd.Slapd)
	s.Config = &slapd.DefaultConfig
	err := s.StartAndInitialize()
	defer s.Stop()
	if err != nil {
		t.Error(err)
	}

	lc := ldap.NewConnection("localhost:9999")
	err = lc.Connect()
	if err != nil {
		t.Error(err)
	}

	err = lc.Bind(slapd.DefaultConfig.Rootdn.Dn, slapd.DefaultConfig.Rootdn.Password)
	if err != nil {
		t.Error(err)
	}

	c := New(lc, "dc=example,dc=com")

	// create test person
	err = c.Create(&fritzFoobarPerson)
	if err != nil {
		t.Error(err)
	}

	// set password of test person to "foobaz"
	err = c.Passwd(&fritzFoobarPerson, "foobaz")
	if err != nil {
		t.Error(err)
	}

	c.Close()

	lc = ldap.NewConnection("localhost:9999")
	err = lc.Connect()
	if err != nil {
		t.Error(err)
	}

	// try to login as the test person with password "foobaz"
	err = lc.Bind(fritzFoobarPerson.Dn()+","+slapd.DefaultConfig.Suffix.Dn, "foobaz")
	if err != nil {
		t.Error(err)
	}

	c = New(lc, "dc=example,dc=com")

	// let the test person change its own password to "foobar"
	// this needs these acls set in slapd.conf:
	// access to attrs=userPassword
	//	by self write
	//	by anonymous auth
	//	by users none
	// access to * by * read

	err = c.Passwd(nil, "foobar")
	if err != nil {
		t.Error(err)
	}

	c.Close()

	lc = ldap.NewConnection("localhost:9999")
	err = lc.Connect()
	if err != nil {
		t.Error(err)
	}

	// try to login as the test person with password "foobar"
	err = lc.Bind(fritzFoobarPerson.Dn()+","+slapd.DefaultConfig.Suffix.Dn, "foobar")
	if err != nil {
		t.Error(err)
	}

}
開發者ID:bytemine,項目名稱:ldap-crud,代碼行數:78,代碼來源:crud_test.go


注:本文中的github.com/bytemine/ldap-crud/slapd.Slapd類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。