import pytest
from lib389.utils import *
from lib389._constants import *
from lib389.idm.user import *
from lib389.topologies import topology_st as topo
from lib389.tests.plugins.utils import create_test_user

USER_WITH_ADD_ACI = "cn=user1,ou=people,{}".format(DEFAULT_SUFFIX)

def test_create_dsldapobject_under_non_dm_user(topo):
    topo.standalone.bind_s(DN_DM, PW_DM)

    user1 = create_test_user(topo.standalone, "user1")
    user1.set("userPassword", PW_DM)
    user1.set("description", "test")
    
    ACI_BODY = ensure_bytes(
        '(targattrfilters = "add=description:(description=test), del=description:(description=test)")(version 3.0; aci "test"; allow (add) userdn = "ldap:///{}";)'.format(USER_WITH_ADD_ACI)
    )
    topo.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_ADD, "aci", ACI_BODY)])
    topo.standalone.bind_s(USER_WITH_ADD_ACI, PW_DM)
    #topo.standalone.bind_s(DN_DM, PW_DM)
    user2 = create_test_user(topo.standalone, "user2")


if __name__ == '__main__':
    CURRENT_FILE = os.path.realpath(__file__)
    pytest.main("-s -v %s" % CURRENT_FILE)

