Repository navigation
Expand file tree
/
Copy pathtest_admin.py
More file actions
185 lines (159 loc) · 7.23 KB
/
Copy pathtest_admin.py
File metadata and controls
185 lines (159 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from __future__ import absolute_import
import unittest
from . import util
import duo_client.admin
class TestAdmin(unittest.TestCase):
def setUp(self):
self.client = duo_client.admin.Admin(
'test_ikey', 'test_akey', 'example.com')
self.client.account_id = 'DA012345678901234567'
# monkeypatch client's _connect()
self.client._connect = lambda: util.MockHTTPConnection()
# if you are wanting to simulate getting lists of objects
# rather than a single object
self.client_list = duo_client.admin.Admin(
'test_ikey', 'test_akey', 'example.com')
self.client_list.account_id = 'DA012345678901234567'
self.client_list._connect = \
lambda: util.MockHTTPConnection(data_response_should_be_list=True)
# GET with no params
def test_get_users(self):
response = self.client.get_users()
self.assertEqual(response['method'], 'GET')
self.assertEqual(
response['uri'],
'/admin/v1/users?account_id=%s' % self.client.account_id)
self.assertEqual(response['body'], None)
# GET with params
def test_get_users_by_name(self):
response = self.client.get_users_by_name('foo')
(uri, args) = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/users')
self.assertEqual(
util.params_to_dict(args),
{'username':['foo'],
'account_id':[self.client.account_id]})
self.assertEqual(response['body'], None)
response = self.client.get_users_by_name('foo')
(uri, args) = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/users')
self.assertEqual(
util.params_to_dict(args),
{'username':['foo'],
'account_id':[self.client.account_id]})
self.assertEqual(response['body'], None)
# POST with params
def test_add_user(self):
# all params given
response = self.client.add_user('foo', 'bar', 'active', 'notes')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/users')
self.assertEqual(
util.params_to_dict(response['body']),
{'realname':['bar'],
'notes':['notes'],
'username':['foo'],
'status':['active'],
'account_id':[self.client.account_id]})
# defaults
response = self.client.add_user('bar')
self.assertEqual(response['method'], 'POST')
self.assertEqual(response['uri'], '/admin/v1/users')
self.assertEqual(
util.params_to_dict(response['body']),
{'username':['bar'], 'account_id':[self.client.account_id]})
# POST with no params
def test_update_user(self):
response = self.client.update_user('DU012345678901234567')
self.assertEqual(response['method'], 'POST')
self.assertEqual(
response['uri'], '/admin/v1/users/DU012345678901234567')
self.assertEqual(
util.params_to_dict(response['body']),
{'account_id':[self.client.account_id]})
def test_get_endpoints(self):
response = self.client.get_endpoints()
self.assertEqual(response['method'], 'GET')
(uri, args) = response['uri'].split('?')
self.assertEqual(uri, '/admin/v1/endpoints')
self.assertEqual(
util.params_to_dict(args),
{'account_id': [self.client.account_id]})
def test_get_user_u2ftokens(self):
""" Test to get u2ftokens by user id.
"""
response = self.client.get_user_u2ftokens('DU012345678901234567')
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/users/DU012345678901234567/u2ftokens')
self.assertEqual(util.params_to_dict(args),
{'account_id':[self.client.account_id]})
def test_get_u2ftokens_with_params(self):
""" Test to get u2ftokens with params.
"""
response = list(self.client_list.get_u2ftokens())[0]
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/u2ftokens')
self.assertEqual(util.params_to_dict(args),
{'account_id':[self.client_list.account_id]})
def test_get_u2ftokens_without_params(self):
""" Test to get u2ftokens without params.
"""
response = list(self.client_list.get_u2ftokens())[0]
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/u2ftokens')
self.assertEqual(util.params_to_dict(args),
{'account_id':[self.client_list.account_id]})
def test_get_u2ftoken_by_id(self):
""" Test to get u2ftoken by registration id.
"""
response = self.client.get_u2ftoken_by_id('DU012345678901234567')
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/u2ftokens/DU012345678901234567')
self.assertEqual(util.params_to_dict(args),
{'account_id':[self.client.account_id]})
def test_delete_u2ftoken(self):
""" Test to delete u2ftoken by registration id.
"""
response = self.client.delete_u2ftoken('DU012345678901234567')
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'DELETE')
self.assertEqual(uri, '/admin/v1/u2ftokens/DU012345678901234567')
self.assertEqual(util.params_to_dict(args),
{'account_id':[self.client.account_id]})
def test_get_user_bypass_codes(self):
""" Test to get bypass codes by user id.
"""
response = self.client.get_user_bypass_codes('DU012345678901234567')
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(
uri,
'/admin/v1/users/DU012345678901234567/bypass_codes')
self.assertEqual(util.params_to_dict(args),
{'account_id': [self.client.account_id]})
def test_get_bypass_codes(self):
""" Test to get bypass codes.
"""
response = list(self.client_list.get_bypass_codes())[0]
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'GET')
self.assertEqual(uri, '/admin/v1/bypass_codes')
self.assertEqual(util.params_to_dict(args),
{'account_id': [self.client_list.account_id]})
def test_delete_bypass_code_by_id(self):
""" Test to delete a bypass code by id.
"""
response = self.client.delete_bypass_code_by_id('DU012345678901234567')
uri, args = response['uri'].split('?')
self.assertEqual(response['method'], 'DELETE')
self.assertEqual(uri, '/admin/v1/bypass_codes/DU012345678901234567')
self.assertEqual(util.params_to_dict(args),
{'account_id': [self.client.account_id]})
if __name__ == '__main__':
unittest.main()