19
19
20
20
import splunklib .client as client
21
21
22
+
22
23
class Tests (testlib .SDKTestCase ):
23
24
def setUp (self ):
24
25
self .service = client .connect (** self .opts .kwargs )
@@ -47,18 +48,18 @@ def test_create(self):
47
48
48
49
def test_create_with_slashes (self ):
49
50
start_count = len (self .storage_passwords )
50
- realm = testlib .tmpname ()
51
- username = testlib .tmpname ()
51
+ realm = " \\ " + testlib .tmpname ()
52
+ username = " \\ " + testlib .tmpname ()
52
53
53
54
# Prepends one escaped slash
54
- p = self .storage_passwords .create ("changeme" , " \\ " + username , realm )
55
+ p = self .storage_passwords .create ("changeme" , username , realm )
55
56
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
56
57
self .assertEqual (p .realm , realm )
57
58
# Prepends one escaped slash
58
- self .assertEqual (p .username , " \\ " + username )
59
+ self .assertEqual (p .username , username )
59
60
self .assertEqual (p .clear_password , "changeme" )
60
61
# Checks for 2 escaped slashes (Splunk encodes the single slash)
61
- self .assertEqual (p .name , realm + ":\\ \\ " + username + ":" )
62
+ self .assertEqual (p .name , " \\ " + realm + ":\\ " + username + ":" )
62
63
63
64
p .delete ()
64
65
self .assertEqual (start_count , len (self .storage_passwords ))
@@ -82,12 +83,14 @@ def test_create_with_colons(self):
82
83
username = testlib .tmpname ()
83
84
realm = testlib .tmpname ()
84
85
85
- p = self .storage_passwords .create ("changeme" , username + ":end" , ":start" + realm )
86
+ p = self .storage_passwords .create ("changeme" , username + ":end" ,
87
+ ":start" + realm )
86
88
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
87
89
self .assertEqual (p .realm , ":start" + realm )
88
90
self .assertEqual (p .username , username + ":end" )
89
91
self .assertEqual (p .clear_password , "changeme" )
90
- self .assertEqual (p .name , "\\ :start" + realm + ":" + username + "\\ :end:" )
92
+ self .assertEqual (p .name ,
93
+ "\\ :start" + realm + ":" + username + "\\ :end:" )
91
94
92
95
p .delete ()
93
96
self .assertEqual (start_count , len (self .storage_passwords ))
@@ -100,7 +103,8 @@ def test_create_with_colons(self):
100
103
self .assertEqual (p .realm , realm )
101
104
self .assertEqual (p .username , user )
102
105
self .assertEqual (p .clear_password , "changeme" )
103
- self .assertEqual (p .name , prefix + "\\ :r\\ :e\\ :a\\ :l\\ :m\\ ::\\ :u\\ :s\\ :e\\ :r\\ ::" )
106
+ self .assertEqual (p .name ,
107
+ prefix + "\\ :r\\ :e\\ :a\\ :l\\ :m\\ ::\\ :u\\ :s\\ :e\\ :r\\ ::" )
104
108
105
109
p .delete ()
106
110
self .assertEqual (start_count , len (self .storage_passwords ))
@@ -110,12 +114,15 @@ def test_create_crazy(self):
110
114
username = testlib .tmpname ()
111
115
realm = testlib .tmpname ()
112
116
113
- p = self .storage_passwords .create ("changeme" , username + ":end!@#$%^&*()_+{}:|<>?" , ":start::!@#$%^&*()_+{}:|<>?" + realm )
117
+ p = self .storage_passwords .create ("changeme" ,
118
+ username + ":end!@#$%^&*()_+{}:|<>?" ,
119
+ ":start::!@#$%^&*()_+{}:|<>?" + realm )
114
120
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
115
121
self .assertEqual (p .realm , ":start::!@#$%^&*()_+{}:|<>?" + realm )
116
122
self .assertEqual (p .username , username + ":end!@#$%^&*()_+{}:|<>?" )
117
123
self .assertEqual (p .clear_password , "changeme" )
118
- self .assertEqual (p .name , "\\ :start\\ :\\ :!@#$%^&*()_+{}\\ :|<>?" + realm + ":" + username + "\\ :end!@#$%^&*()_+{}\\ :|<>?:" )
124
+ self .assertEqual (p .name ,
125
+ "\\ :start\\ :\\ :!@#$%^&*()_+{}\\ :|<>?" + realm + ":" + username + "\\ :end!@#$%^&*()_+{}\\ :|<>?:" )
119
126
120
127
p .delete ()
121
128
self .assertEqual (start_count , len (self .storage_passwords ))
@@ -165,7 +172,6 @@ def test_delete(self):
165
172
start_count = len (self .storage_passwords )
166
173
username = testlib .tmpname ()
167
174
168
- # Testing named parameters
169
175
p = self .storage_passwords .create ("changeme" , username , "myrealm" )
170
176
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
171
177
self .assertEqual (p .realm , "myrealm" )
@@ -182,12 +188,15 @@ def test_delete(self):
182
188
self .storage_passwords .delete ("myrealm:" + username + ":" )
183
189
self .assertEqual (start_count , len (self .storage_passwords ))
184
190
185
- self .storage_passwords .create ("changeme" , username , realm = "myrealm" )
191
+ # Test named parameters
192
+ self .storage_passwords .create (password = "changeme" , username = username ,
193
+ realm = "myrealm" )
186
194
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
187
195
188
196
self .storage_passwords .delete (username , "myrealm" )
189
197
self .assertEqual (start_count , len (self .storage_passwords ))
190
198
199
+
191
200
if __name__ == "__main__" :
192
201
try :
193
202
import unittest2 as unittest
0 commit comments