Debian Codegraph @

tests/conftest.py

raw symbols SCIP
1 import configparser
2 import os
3 import time
4 import uuid
5 from contextlib import contextmanager
6
7 import pytest
8
9 from bonsai import LDAPClient
10 from bonsai.active_directory.acl import ACE, ACEFlag, ACEType
11 from bonsai.active_directory.sid import SID
12
13
14 def get_config():
15 """Load config parameters."""
16 curdir = os.path.abspath(os.path.dirname(__file__))
17 cfg = configparser.ConfigParser()
18 cfg.read(os.path.join(curdir, "test.ini"))
19 return cfg
20
21
22 @contextmanager
23 def network_delay(delay):
24 import xmlrpc.client as rpc
25
26 ipaddr = get_config()["SERVER"]["hostip"]
27 proxy = rpc.ServerProxy("http://%s:%d/" % (ipaddr, 8000))
28 proxy.set_delay(delay)
29 time.sleep(2.0)
30 try:
31 yield proxy
32 finally:
33 proxy.remove_delay()
34
35
36 @pytest.fixture(scope="module")
37 def client():
38 """Get an LDAPClient with simple authentication."""
39 cfg = get_config()
40 url = "ldap://%s:%s/%s??%s" % (
41 cfg["SERVER"]["hostip"],
42 cfg["SERVER"]["port"],
43 cfg["SERVER"]["basedn"],
44 cfg["SERVER"]["search_scope"],
45 )
46 cli = LDAPClient(url)
47 cli.set_credentials(
48 "SIMPLE", user=cfg["SIMPLEAUTH"]["user"], password=cfg["SIMPLEAUTH"]["password"]
49 )
50 return cli
51
52
53 @pytest.fixture(scope="module")
54 def basedn():
55 """Get base DN."""
56 cfg = get_config()
57 return cfg["SERVER"]["basedn"]
58
59
60 @pytest.fixture(scope="module")
61 def cfg():
62 """Get config."""
63 return get_config()
64
65
66 @pytest.fixture
67 def test_ace() -> ACE:
68 """Test ACE object"""
69 return ACE(
70 ACEType.ACCESS_ALLOWED,
71 {ACEFlag.INHERITED},
72 0x80000000,
73 SID("S-1-1-0"),
74 None,
75 uuid.UUID("c975c901-6cea-4b6f-8319-d67f45449506"),
76 b"",
77 )