func TestLocalAddAndDelete(t *testing.T) { fmt.Printf("TestLocalAddAndDelete: starting...\n") l := ldap.NewLDAPConnection(server, port) err := l.Connect() if err != nil { t.Error(err) return } defer l.Close() err = l.Bind(binddn, passwd) if err != nil { t.Error(err) return } addReq := ldap.NewAddRequest(addDNs[0]) for _, attr := range addAttrs { addReq.AddAttribute(&attr) } fmt.Printf("Adding: %s\n", addDNs[0]) err = l.Add(addReq) if err != nil { t.Errorf("Add : %s : %s\n", addDNs[0], err) return } fmt.Printf("Deleting: %s\n", addDNs[0]) delRequest := ldap.NewDeleteRequest(addDNs[0]) err = l.Delete(delRequest) if err != nil { t.Errorf("Delete : %s : %s\n", addDNs[0], err) return } }
func (e *DisallowAppExecutor) Execute(t *Task) error { if !TeamExists(e.arg.Team, &e.arg.ManagerAuthArg) { return errors.New("Team Does Not Exist") } conn, err := InitConnection(&e.arg.ManagerAuthArg) if err != nil { return err } delReq := ldap.NewDeleteRequest(aldap.AllowedAppAttr + "=" + e.arg.App + "," + aldap.TeamCommonName + "=" + e.arg.Team + "," + aldap.TeamOu) if err := conn.Delete(delReq); err != nil { return err } return nil }
func TestLocalControlPermissiveModifyRequest(t *testing.T) { fmt.Printf("ControlPermissiveModifyRequest: starting...\n") l := ldap.NewLDAPConnection(server, port) err := l.Connect() if err != nil { t.Error(err) return } defer l.Close() err = l.Bind(binddn, passwd) if err != nil { t.Error(err) return } addReq := ldap.NewAddRequest(addDNs[0]) for _, attr := range addAttrs { addReq.AddAttribute(&attr) } fmt.Printf("Adding: %s\n", addDNs[0]) err = l.Add(addReq) if err != nil { t.Errorf("Add : %s : %s\n", addDNs[0], err) return } modreq := ldap.NewModifyRequest(addDNs[0]) mod := ldap.NewMod(ldap.ModAdd, "description", []string{"aaa"}) modreq.AddMod(mod) fmt.Println(modreq) err = l.Modify(modreq) if err != nil { t.Errorf("Modify : %s : %s\n", addDNs[0], err) return } mod = ldap.NewMod(ldap.ModAdd, "description", []string{"aaa", "bbb", "ccc"}) modreq = ldap.NewModifyRequest(addDNs[0]) modreq.AddMod(mod) control := ldap.NewControlString(ldap.ControlTypePermissiveModifyRequest, true, "") fmt.Println(control.String()) modreq.AddControl(control) fmt.Println(modreq) err = l.Modify(modreq) if err != nil { t.Errorf("Modify (Permissive): %s : %s\n", addDNs[0], err) return } mod = ldap.NewMod(ldap.ModAdd, "description", []string{"aaa", "bbb", "ccc", "ddd"}) modreq = ldap.NewModifyRequest(addDNs[0]) modreq.AddMod(mod) control = ldap.NewControlPermissiveModifyRequest(false) fmt.Println(control.String()) modreq.AddControl(control) fmt.Println(modreq) err = l.Modify(modreq) if err != nil { t.Errorf("Modify (Permissive): %s : %s\n", addDNs[0], err) return } fmt.Printf("Deleting: %s\n", addDNs[0]) delRequest := ldap.NewDeleteRequest(addDNs[0]) err = l.Delete(delRequest) if err != nil { t.Errorf("Delete : %s : %s\n", addDNs[0], err) return } }
func TestLocalControlMatchedValuesRequest(t *testing.T) { fmt.Printf("LocalControlMatchedValuesRequest: starting...\n") l := ldap.NewLDAPConnection(server, port) err := l.Connect() if err != nil { t.Error(err) return } defer l.Close() err = l.Bind(binddn, passwd) if err != nil { t.Error(err) return } addReq := ldap.NewAddRequest(addDNs[0]) for _, attr := range addAttrs { addReq.AddAttribute(&attr) } fmt.Printf("Adding: %s\n", addDNs[0]) err = l.Add(addReq) if err != nil { t.Errorf("Add : %s : %s\n", addDNs[0], err) return } fmt.Printf("Modify: %s = {aaa, bbb, ccc}\n", "description") mod := ldap.NewMod(ldap.ModAdd, "description", []string{"aaa", "bbb", "ccc", "aabb"}) modreq := ldap.NewModifyRequest(addDNs[0]) modreq.AddMod(mod) err = l.Modify(modreq) if err != nil { t.Errorf("Modify: %s : %s\n", addDNs[0], err) return } control := ldap.NewControlMatchedValuesRequest(true, "(description=aaa)") fmt.Println(control.String()) fmt.Printf("Search: (objectclass=*), (description=aaa) via MatchedValuesRequest\n") search_request := ldap.NewSimpleSearchRequest( addDNs[0], ldap.ScopeBaseObject, "(objectclass=*)", []string{"description"}, ) search_request.AddControl(control) //l.Debug = true sr, err := l.Search(search_request) if err != nil { t.Errorf("Search: %s : %s\n", addDNs[0], err) return } //l.Debug = false fmt.Println("Search Result:") fmt.Print(sr) control = ldap.NewControlMatchedValuesRequest(true, "(description=a*)") fmt.Println(control.String()) fmt.Printf("Search: (objectclass=*), (description=a*) via MatchedValuesRequest\n") search_request = ldap.NewSimpleSearchRequest( addDNs[0], ldap.ScopeBaseObject, "(objectclass=*)", []string{"description"}, ) search_request.AddControl(control) //l.Debug = true sr, err = l.Search(search_request) if err != nil { t.Errorf("Search: %s : %s\n", addDNs[0], err) return } //l.Debug = false fmt.Println("Search Result:") fmt.Print(sr) fmt.Printf("Deleting: %s\n", addDNs[0]) delRequest := ldap.NewDeleteRequest(addDNs[0]) err = l.Delete(delRequest) if err != nil { t.Errorf("Delete : %s : %s\n", addDNs[0], err) return } }
func TestLocalCompare(t *testing.T) { fmt.Printf("TestLocalCompare: starting...\n") l := ldap.NewLDAPConnection(server, port) err := l.Connect() if err != nil { t.Error(err) return } defer l.Close() err = l.Bind(binddn, passwd) if err != nil { t.Error(err) return } addReq := ldap.NewAddRequest(addDNs[0]) for _, attr := range addAttrs { addReq.AddAttribute(&attr) } fmt.Printf("Adding: %s\n", addDNs[0]) err = l.Add(addReq) if err != nil { t.Errorf("Add : %s : %s\n", addDNs[0], err) return } fmt.Printf("Comparing: %s : sn=Boy which is True\n", addDNs[0]) compareReq := ldap.NewCompareRequest(addDNs[0], "sn", "Boy") result, cerr := l.Compare(compareReq) if cerr != nil { t.Error(err) return } if result != true { t.Error("Compare Result should have been true") return } fmt.Printf("Compare Result : %v\n", result) fmt.Printf("Comparing: %s : sn=BoyIsThisWrong which is False\n", addDNs[0]) compareReq = ldap.NewCompareRequest(addDNs[0], "sn", "BoyIsThisWrong") result, cerr = l.Compare(compareReq) if cerr != nil { t.Error(cerr) return } if result == true { t.Error("Compare Result should have been false") return } fmt.Printf("Compare Result : %v\n", result) fmt.Printf("Deleting: %s\n", addDNs[0]) delRequest := ldap.NewDeleteRequest(addDNs[0]) err = l.Delete(delRequest) if err != nil { t.Errorf("Delete : %s : %s\n", addDNs[0], err) return } }