Debian Codegraph @

dirsrvtests/tests/suites/mapping_tree/referral_during_tot_init_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import ldap
10 import pytest
11 import os
12 from test389.topologies import topology_m2
13 from lib389._constants import (DEFAULT_SUFFIX)
14 from lib389.agreement import Agreements
15 from lib389.idm.user import (TEST_USER_PROPERTIES, UserAccounts)
16 from lib389.dbgen import dbgen_users
17 from lib389.utils import ds_is_older
18
19 pytestmark = pytest.mark.tier1
20
21 @pytest.mark.skipif(ds_is_older("1.4.0.0"), reason="Not implemented")
22 def test_referral_during_tot(topology_m2):
23 """Test referrals during total init
24
25 :id: 2a030f15-89ae-4acc-880d-bd2263a6be33
26 :setup: 2 suppliers
27 :steps:
28 1. Create test user on supplier2
29 2. Create a bunch of entries in supplier1
30 3. Recreate the user on supplier1 also, so that if the init finishes first we don't lose the user on supplier2
31 4. Initialize replica on supplier1
32 5. While that's happening try to bind as a user to supplier2
33 :expectedresults:
34 1. Success
35 2. Success
36 3. Success
37 4. Success
38 5. This should trigger the referral code.
39 """
40
41 supplier1 = topology_m2.ms["supplier1"]
42 supplier2 = topology_m2.ms["supplier2"]
43
44 users = UserAccounts(supplier2, DEFAULT_SUFFIX)
45 u = users.create(properties=TEST_USER_PROPERTIES)
46 u.set('userPassword', 'password')
47 binddn = u.dn
48 bindpw = 'password'
49
50 # Create a bunch of entries on supplier1
51 ldif_dir = supplier1.get_ldif_dir()
52 import_ldif = ldif_dir + '/ref_during_tot_import.ldif'
53 dbgen_users(supplier1, 10000, import_ldif, DEFAULT_SUFFIX)
54
55 supplier1.stop()
56 supplier1.ldif2db(bename=None, excludeSuffixes=None, encrypt=False, suffixes=[DEFAULT_SUFFIX], import_file=import_ldif)
57 supplier1.start()
58 # Recreate the user on supplier1 also, so that if the init finishes first we don't lose the user on supplier2
59 users = UserAccounts(supplier1, DEFAULT_SUFFIX)
60 u = users.create(properties=TEST_USER_PROPERTIES)
61 u.set('userPassword', 'password')
62 # Now export them to supplier2
63 agmts = Agreements(supplier1)
64 agmts.list()[0].begin_reinit()
65
66 # While that's happening try to bind as a user to supplier 2
67 # This should trigger the referral code.
68 referred = False
69 ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, os.path.join(supplier2.get_config_dir(), "ca.crt"))
70 for i in range(0, 100):
71 conn = ldap.initialize(supplier2.toLDAPURL())
72 conn.set_option(ldap.OPT_REFERRALS, False)
73 conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
74 try:
75 conn.simple_bind_s(binddn, bindpw)
76 conn.unbind_s()
77 except ldap.REFERRAL:
78 referred = True
79 break
80 # Means we never go a referral, should not happen!
81 assert referred
82
83 # Done.