summaryrefslogtreecommitdiff
path: root/python/samba/tests/dcerpc/integer.py
blob: 69a6a09a3810dc3153da3685a84d90308d984ab6 (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# Unix SMB/CIFS implementation.
# Copyright (C) Andrew Bartlett <abartlet@samba.org> 2015
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""Tests for integer handling in PIDL generated bindings samba.dcerpc.*"""

from samba.dcerpc import server_id, misc, srvsvc, samr
import samba.tests


class IntegerTests(samba.tests.TestCase):

    def test_uint32_into_hyper(self):
        s = server_id.server_id()
        s.unique_id = server_id.NONCLUSTER_VNN
        self.assertEqual(s.unique_id, 0xFFFFFFFF)

    def test_int_into_hyper(self):
        s = server_id.server_id()
        s.unique_id = 1
        self.assertEqual(s.unique_id, 1)

    def test_negative_int_into_hyper(self):
        s = server_id.server_id()

        def assign():
            s.unique_id = -1
        self.assertRaises(OverflowError, assign)

    def test_hyper_into_uint32(self):
        s = server_id.server_id()

        def assign():
            s.vnn = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
        self.assertRaises(OverflowError, assign)

    def test_hyper_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()

        def assign():
            s.timezone = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
        self.assertRaises(OverflowError, assign)

    def test_int_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()
        s.timezone = 5
        self.assertEqual(s.timezone, 5)

    def test_uint32_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()

        def assign():
            s.timezone = server_id.NONCLUSTER_VNN
        self.assertRaises(OverflowError, assign)

    def test_long_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()
        # here we force python2 to convert its 32/64 bit python int into
        # an arbitrarily long python long, then reduce the number back
        # down to something that would fit in an int anyway. In a pure
        # python2 world, you could achieve the same thing by writing
        #    s.timezone = 5L
        # but that is a syntax error in py3.
        s.timezone = (5 << 65) >> 65
        self.assertEqual(s.timezone, 5)

    def test_larger_long_int_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()

        def assign():
            s.timezone = 2147483648
        self.assertRaises(OverflowError, assign)

    def test_larger_int_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()
        s.timezone = 2147483647
        self.assertEqual(s.timezone, 2147483647)

    def test_float_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()

        def assign():
            s.timezone = 2.5
        self.assertRaises(TypeError, assign)

    def test_int_float_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()

        def assign():
            s.timezone = 2.0
        self.assertRaises(TypeError, assign)

    def test_negative_int_into_int32(self):
        s = srvsvc.NetRemoteTODInfo()
        s.timezone = -2147483648
        self.assertEqual(s.timezone, -2147483648)

    def test_negative_into_uint32(self):
        s = server_id.server_id()

        def assign():
            s.vnn = -1
        self.assertRaises(OverflowError, assign)

    def test_hyper_into_uint16(self):
        g = misc.GUID()

        def assign():
            g.time_mid = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
        self.assertRaises(OverflowError, assign)

    def test_int_into_uint16(self):
        g = misc.GUID()

        def assign():
            g.time_mid = 200000
        self.assertRaises(OverflowError, assign)

    def test_negative_int_into_uint16(self):
        g = misc.GUID()

        def assign():
            g.time_mid = -2
        self.assertRaises(OverflowError, assign)

    def test_enum_into_uint16(self):
        g = misc.GUID()
        g.time_mid = misc.SEC_CHAN_DOMAIN
        self.assertEqual(g.time_mid, misc.SEC_CHAN_DOMAIN)

    def test_bitmap_into_uint16(self):
        g = misc.GUID()
        g.time_mid = misc.SV_TYPE_WFW
        self.assertEqual(g.time_mid, misc.SV_TYPE_WFW)

    def test_overflow_bitmap_into_uint16(self):
        g = misc.GUID()

        def assign():
            g.time_mid = misc.SV_TYPE_LOCAL_LIST_ONLY
        self.assertRaises(OverflowError, assign)

    def test_overflow_bitmap_into_uint16_2(self):
        g = misc.GUID()

        def assign():
            g.time_mid = misc.SV_TYPE_DOMAIN_ENUM
        self.assertRaises(OverflowError, assign)

    def test_hyper_into_int64(self):
        s = samr.DomInfo1()

        def assign():
            s.max_password_age = server_id.SERVERID_UNIQUE_ID_NOT_TO_VERIFY
        self.assertRaises(OverflowError, assign)

    def test_int_into_int64(self):
        s = samr.DomInfo1()
        s.max_password_age = 5
        self.assertEqual(s.max_password_age, 5)

    def test_negative_int_into_int64(self):
        s = samr.DomInfo1()
        s.max_password_age = -5
        self.assertEqual(s.max_password_age, -5)

    def test_larger_int_into_int64(self):
        s = samr.DomInfo1()
        s.max_password_age = server_id.NONCLUSTER_VNN
        self.assertEqual(s.max_password_age, 0xFFFFFFFF)

    def test_larger_negative_int_into_int64(self):
        s = samr.DomInfo1()
        s.max_password_age = -2147483649
        self.assertEqual(s.max_password_age, -2147483649)

    def test_int_list_over_list(self):
        g = misc.GUID()
        g.node = [5, 0, 5, 0, 7, 4]
        self.assertEqual(g.node[0], 5)

    def test_long_int_list_over_uint8_list(self):
        g = misc.GUID()
        g.node = [5, 0, 5, 0, 7, 4]
        self.assertEqual(g.node[0], 5)

    def test_negative_list_over_uint8_list(self):
        g = misc.GUID()

        def assign():
            g.node = [-1, 0, 5, 0, 7, 4]
        self.assertRaises(OverflowError, assign)

    def test_overflow_list_over_uint8_list(self):
        g = misc.GUID()

        def assign():
            g.node = [256, 0, 5, 0, 7, 4]
        self.assertRaises(OverflowError, assign)

    def test_short_list_over_uint8_list(self):
        g = misc.GUID()

        def assign():
            g.node = [5, 0, 5]
        self.assertRaises(TypeError, assign)

    def test_long_list_over_uint8_list(self):
        g = misc.GUID()

        def assign():
            g.node = [5, 0, 5, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
        self.assertRaises(TypeError, assign)

    # Due to our PIDL bindings generating a python List, modifications
    # to a list of non-objects are not reflected in the C list
    # (modifications objects in lists of objects work because the
    # objects are modified), so changes essentially vanish and are not
    # type checked either.
    def test_assign_into_uint8_list(self):
        g = misc.GUID()
        g.node[1] = 5
        self.assertEqual(g.node[1], 5)

    def test_negative_into_uint8_list(self):
        g = misc.GUID()

        def assign():
            g.node[1] = -1
        self.assertRaises(OverflowError, assign)

    def test_overflow_into_uint8_list(self):
        g = misc.GUID()

        def assign():
            g.node[1] = 256
        self.assertRaises(OverflowError, assign)