Skip to content

Commit

Permalink
Tests: convert multihost/alltests/test_cache_testing to system/memory…
Browse files Browse the repository at this point in the history
…_cache
  • Loading branch information
patriki01 committed Dec 21, 2023
1 parent 5fb0a9d commit d4f0d2c
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/tests/multihost/alltests/test_cache_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TestCacheTesting():
Test for correct cache presence in case of variety of SSSD Configurations.
Test for correct cache presence in case of modification & deletion of user entries.
"""
@pytest.mark.converted('test_memory_cache.py', 'test_memory_cache__verify_timestamp_cache')
@staticmethod
def test_0001_Verify_Timestamp_Cache_Exists(multihost):
"""
Expand All @@ -64,6 +65,7 @@ def test_0001_Verify_Timestamp_Cache_Exists(multihost):
cmd = multihost.client[0].run_command(list_cmd, raiseonerr=False)
assert cmd.returncode == 0, f"Could not find timestamp cache file {file}"

@pytest.mark.converted('test_memory_cache.py', 'test_memory_cache__verify_timestamp_cache')
@staticmethod
def test_0002_Verify_Cache_on_User_Lookup(multihost):
"""
Expand All @@ -85,6 +87,7 @@ def test_0002_Verify_Cache_on_User_Lookup(multihost):
assert cmd.returncode == 0, f'{ldb_cmd} did not execute successfully'
assert cmd2.returncode == 0, f'{ldb_cmd2} did not execute successfully'

@pytest.mark.converted('test_memory_cache.py', 'test_memory_cache__expire_cache_verify_updates')
@staticmethod
def test_0003_Expire_User_Entries_and_Verify_Updates(multihost):
"""
Expand Down Expand Up @@ -115,6 +118,7 @@ def test_0003_Expire_User_Entries_and_Verify_Updates(multihost):
assert cmd2.returncode == 0, f'{ldb_cmd2} did not execute successfully'
assert "dataExpireTimestamp: 1\n" in cmd2_output, "dataExpireTimestamp not found in /tmp/file_ldb2"

@pytest.mark.converted('test_memory_cache.py', 'test_memory_cache__refresh_user_entries')
@staticmethod
def test_0004_Refresh_User_Entries_After_Expiry(multihost):
"""
Expand Down Expand Up @@ -145,6 +149,7 @@ def test_0004_Refresh_User_Entries_After_Expiry(multihost):
assert cmd2.returncode == 0, f'{ldb_cmd2} did not execute successfully'
assert "dataExpireTimestamp: 1\n" not in cmd2_output, "dataExpireTimestamp found in /tmp/file_ldb2"

@pytest.mark.converted('test_memory_cache.py', 'test_memory_cache__user_auth_after_cache_expiration')
@staticmethod
def test_0005_Expire_User_Entries_ans_Run_User_Auth(multihost):
"""
Expand Down
141 changes: 141 additions & 0 deletions src/tests/system/tests/test_memory_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

from __future__ import annotations

import time

import pytest
from pytest_mh.ssh import SSHAuthenticationError
from sssd_test_framework.roles.client import Client
from sssd_test_framework.roles.generic import GenericProvider
from sssd_test_framework.roles.ldap import LDAP
Expand Down Expand Up @@ -1656,3 +1659,141 @@ def test_memory_cache__truncate__nosigbus(client: Client, ldap: LDAP):
result = client.tools.id("user-1")
assert result is not None, "User was not found"
assert result.user.name == "user-1"


@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_memory_cache__verify_timestamp_cache(client: Client, provider: GenericProvider):
"""
:title: Verify the existence of timestamp cache and use lsbsearch on those files
:setup:
1. Add user
2. Start SSSD
:steps:
1. Execute getent passwd to fetch user details
2. Check if timestamps cache file exists
3. Get user information using ldbsearch on cache_test.ldb
4. Get user timestamp information using ldbsearch on timestamps_test.ldb
:expectedresults:
1. User details should be successfully fetched
2. Cache file should be present
3. User information were successfully fetched
4. User information were successfully fetched
:customerscenario: False
"""
provider.user("user1").add()
client.sssd.start()

client.tools.getent.passwd("user1")
cache = "/var/lib/sss/db/cache_test.ldb"
timestamps = "/var/lib/sss/db/timestamps_test.ldb"
assert client.fs.exists(timestamps), f"Timestamp file '{timestamps}' does not exist"

ldb1 = client.ldb.search(cache, "name=user1@test,cn=users,cn=test,cn=sysdb")
ldb2 = client.ldb.search(timestamps, "name=user1@test,cn=users,cn=test,cn=sysdb")
assert ldb1 != {}, f"ldbsearch failed to search user1 in {cache}"
assert ldb2 != {}, f"ldbsearch failed to search user1 in {timestamps}"


@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_memory_cache__expire_cache_verify_updates(client: Client, provider: GenericProvider):
"""
:title: Expire user entries in cache and verify the updates
:setup:
1. Add user
2. Start SSSD
3. Execute getent passwd to fetch user details
4. Expire whole cache
:steps:
1. Get user information using ldbsearch on cache_test.ldb
2. Get user timestamp information using ldbsearch on timestamps_test.ldb
:expectedresults:
1. 'dataExpireTimestamp' were found in output
2. 'dataExpireTimestamp' were found in output
:customerscenario: False
"""
provider.user("user1").add()
client.sssd.start()
client.tools.getent.passwd("user1")
client.sssctl.cache_expire(everything=True)

cache = "/var/lib/sss/db/cache_test.ldb"
timestamps = "/var/lib/sss/db/timestamps_test.ldb"
user_basedn = "name=user1@test,cn=users,cn=test,cn=sysdb"
ldb1 = client.ldb.search(cache, user_basedn)
ldb2 = client.ldb.search(timestamps, user_basedn)

assert ldb1[user_basedn]["dataExpireTimestamp"] == ["1"], f"did not find 'dataExpireTimestamp' in {cache}"
assert ldb2[user_basedn]["dataExpireTimestamp"] == ["1"], f"did not find 'dataExpireTimestamp' in {timestamps}"
input("after")


@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_memory_cache__refresh_user_entries(client: Client, provider: GenericProvider):
"""
:title: Refresh user entries after expiry and verify the cache updates
:setup:
1. Add user
2. Start SSSD
3. Execute getent passwd to fetch user details
4. Expire cache
5. Execute getent passwd again
:steps:
1. Get user information using ldbsearch on cache_test.ldb
2. Get user timestamp information using ldbsearch on timestamps_test.ldb
:expectedresults:
1. 'dataExpireTimestamp' were found in output
2. 'dataExpireTimestamp' were not found in timestamps output
:customerscenario: False
"""
provider.user("user1").add()
client.sssd.start()
client.tools.getent.passwd("user1")
client.sssctl.cache_expire(everything=True)
client.tools.getent.passwd("user1")

cache = "/var/lib/sss/db/cache_test.ldb"
timestamps = "/var/lib/sss/db/timestamps_test.ldb"
user_basedn = "name=user1@test,cn=users,cn=test,cn=sysdb"
ldb1 = client.ldb.search(cache, user_basedn)
ldb2 = client.ldb.search(timestamps, user_basedn)

assert ldb1[user_basedn]["dataExpireTimestamp"] == ["1"], f"did not find 'dataExpireTimestamp' in {cache}"
assert ldb2[user_basedn]["dataExpireTimestamp"] != ["1"], f"did not find 'dataExpireTimestamp' in {timestamps}"


@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_memory_cache__user_auth_after_cache_expiration(client: Client, provider: GenericProvider):
"""
:title: Refresh user entries after expiry and verify the cache updates
:setup:
1. Add user
2. Start SSSD
3. Execute getent passwd to fetch user details
4. Expire cache
5. Execute getent passwd again
:steps:
1. Get user information using ldbsearch on cache_test.ldb
2. Get user timestamp information using ldbsearch on timestamps_test.ldb
:expectedresults:
1. 'dataExpireTimestamp' were found in output
2. 'dataExpireTimestamp' were not found in timestamps output
:customerscenario: False
"""
provider.user("user1").add()
client.sssd.start()
client.tools.getent.passwd("user1")
client.sssctl.cache_expire(everything=True)

try:
client.ssh("user1", password="Secret123").connect()
except SSHAuthenticationError:
assert False, "user1 was unable to authenticate"

cache = "/var/lib/sss/db/cache_test.ldb"
timestamps = "/var/lib/sss/db/timestamps_test.ldb"
user_basedn = "name=user1@test,cn=users,cn=test,cn=sysdb"
ldb1 = client.ldb.search(cache, user_basedn)
ldb2 = client.ldb.search(timestamps, user_basedn)

assert ldb1[user_basedn]["dataExpireTimestamp"] == ["1"], f"did not find 'dataExpireTimestamp' in {cache}"
assert ldb2[user_basedn]["dataExpireTimestamp"] != ["1"], f"did not find 'dataExpireTimestamp' in {timestamps}"

0 comments on commit d4f0d2c

Please sign in to comment.