Debian Codegraph @

dirsrvtests/tests/suites/acl/default_aci_allows_self_write_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2019 William Brown <[email protected]>
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
10 import pytest
11 from lib389.idm.user import nsUserAccounts, UserAccounts
12 from test389.topologies import topology_st as topology
13 from lib389.paths import Paths
14 from lib389.utils import ds_is_older
15 from lib389._constants import *
16
17 default_paths = Paths()
18
19 pytestmark = pytest.mark.tier1
20
21 USER_PASSWORD = "some test password"
22 NEW_USER_PASSWORD = "some new password"
23
24 @pytest.mark.skipif(ds_is_older('1.4.2.0'), reason="Default aci's in older versions do not support this functionality")
25 def test_acl_default_allow_self_write_nsuser(topology):
26 """
27 Testing nsusers can self write and self read. This it a sanity test
28 so that our default entries have their aci's checked.
29
30 :id: 4f0fb01a-36a6-430c-a2ee-ebeb036bd951
31
32 :setup: Standalone instance
33
34 :steps:
35 1. Testing comparison of two different users.
36
37 :expectedresults:
38 1. Should fail to compare
39 """
40 topology.standalone.enable_tls()
41 nsusers = nsUserAccounts(topology.standalone, DEFAULT_SUFFIX)
42 # Create a user as dm.
43 user = nsusers.create(properties={
44 'uid': 'test_nsuser',
45 'cn': 'test_nsuser',
46 'displayName': 'testNsuser',
47 'legalName': 'testNsuser',
48 'uidNumber': '1001',
49 'gidNumber': '1001',
50 'homeDirectory': '/home/testnsuser',
51 'userPassword': USER_PASSWORD,
52 })
53 # Create a new con and bind as the user.
54 user_conn = user.bind(USER_PASSWORD)
55
56 user_nsusers = nsUserAccounts(user_conn, DEFAULT_SUFFIX)
57 self_ent = user_nsusers.get(dn=user.dn)
58
59 # Can we self read x,y,z
60 check = self_ent.get_attrs_vals_utf8([
61 'uid',
62 'cn',
63 'displayName',
64 'legalName',
65 'uidNumber',
66 'gidNumber',
67 'homeDirectory',
68 ])
69 for k in check.values():
70 # Could we read the values?
71 assert(isinstance(k, list))
72 assert(len(k) > 0)
73 # Can we self change a,b,c
74 self_ent.ensure_attr_state({
75 'legalName': ['testNsuser_update'],
76 'displayName': ['testNsuser_update'],
77 'nsSshPublicKey': ['testkey'],
78 })
79 # self change pw
80 self_ent.change_password(USER_PASSWORD, NEW_USER_PASSWORD)
81
82
83 @pytest.mark.skipif(ds_is_older('1.4.2.0'), reason="Default aci's in older versions do not support this functionality")
84 def test_acl_default_allow_self_write_user(topology):
85 """
86 Testing users can self write and self read. This it a sanity test
87 so that our default entries have their aci's checked.
88
89 :id: 4c52321b-f473-4c32-a1d5-489b138cd199
90
91 :setup: Standalone instance
92
93 :steps:
94 1. Testing comparison of two different users.
95
96 :expectedresults:
97 1. Should fail to compare
98 """
99 topology.standalone.enable_tls()
100 users = UserAccounts(topology.standalone, DEFAULT_SUFFIX)
101 # Create a user as dm.
102 user = users.create(properties={
103 'uid': 'test_user',
104 'cn': 'test_user',
105 'sn': 'User',
106 'uidNumber': '1002',
107 'gidNumber': '1002',
108 'homeDirectory': '/home/testuser',
109 'userPassword': USER_PASSWORD,
110 })
111 # Create a new con and bind as the user.
112 user_conn = user.bind(USER_PASSWORD)
113
114 user_users = UserAccounts(user_conn, DEFAULT_SUFFIX)
115 self_ent = user_users.get(dn=user.dn)
116 # Can we self read x,y,z
117 check = self_ent.get_attrs_vals_utf8([
118 'uid',
119 'cn',
120 'sn',
121 'uidNumber',
122 'gidNumber',
123 'homeDirectory',
124 ])
125 for (a, k) in check.items():
126 print(a)
127 # Could we read the values?
128 assert(isinstance(k, list))
129 assert(len(k) > 0)
130 # Self change pw
131 self_ent.change_password(USER_PASSWORD, NEW_USER_PASSWORD)
132
133