Tests for Service create method.

This commit is contained in:
sfigato 2019-07-18 18:15:43 +02:00
parent ce4c085e3f
commit d9e8eb23e3
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F

View File

@ -56,6 +56,14 @@ MISSING_AUTH_USER = [
"uid": ["existing_user"], "uid": ["existing_user"],
} }
] ]
EXISTING_SERVICE = [
{
"dn": f"uid=existing_service,ou=Services,{BASE_DN}>",
"objectClass": ["account", "simpleSecurityObject", "top"],
"uid": ["existing_service"],
"userPassword": ["{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g="],
}
]
class MockClient: class MockClient:
@ -83,8 +91,12 @@ class MockClient:
return USER_LIST return USER_LIST
elif f"uid=existing_user,ou=Hackers,{BASE_DN}" in args: elif f"uid=existing_user,ou=Hackers,{BASE_DN}" in args:
return EXISTING_USER return EXISTING_USER
elif f"uid=existing_service,ou=Services,{BASE_DN}" in args:
return EXISTING_SERVICE
elif f"uid=not_existing,ou=Hackers,{BASE_DN}" in args: elif f"uid=not_existing,ou=Hackers,{BASE_DN}" in args:
return [] return []
elif f"uid=not_existing,ou=Services,{BASE_DN}" in args:
return []
elif f"uid=missing_auth_user,ou=Hackers,{BASE_DN}" in args: elif f"uid=missing_auth_user,ou=Hackers,{BASE_DN}" in args:
return MISSING_AUTH_USER return MISSING_AUTH_USER
@ -700,26 +712,23 @@ def test_Service_singleton(client_fixture):
assert c4 is not c1 assert c4 is not c1
@pytest.mark.xfail
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_Service_create_existing(client_fixture): async def test_Service_create_existing(client_fixture):
s = Service("existing_user", client_fixture) s = Service("existing_service", client_fixture)
with pytest.raises(PhiEntryExists) as e: with pytest.raises(PhiEntryExists) as e:
await s.create("existing@mail.org", sn="exists", cn="Existing Service") await s.create("password")
assert s.dn in str(e.value) assert s.dn in str(e.value)
@pytest.mark.xfail
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_Service_create_not_existing(client_fixture): async def test_Service_create_not_existing(client_fixture):
s = Service("not_existing", client_fixture) s = Service("not_existing", client_fixture)
await s.create("not@existing.org") await s.create("password")
assert client_fixture.called_with_args["search"]["args"] == (s.dn, 0) assert client_fixture.called_with_args["search"]["args"] == (s.dn, 0)
assert s._entry["mail"][0] == "not@existing.org"
def test_Group(client_fixture): def test_Group(client_fixture):