1919
2020import splunklib .client as client
2121
22+
2223class Tests (testlib .SDKTestCase ):
2324 def setUp (self ):
2425 self .service = client .connect (** self .opts .kwargs )
@@ -47,18 +48,18 @@ def test_create(self):
4748
4849 def test_create_with_slashes (self ):
4950 start_count = len (self .storage_passwords )
50- realm = testlib .tmpname ()
51- username = testlib .tmpname ()
51+ realm = " \\ " + testlib .tmpname ()
52+ username = " \\ " + testlib .tmpname ()
5253
5354 # Prepends one escaped slash
54- p = self .storage_passwords .create ("changeme" , " \\ " + username , realm )
55+ p = self .storage_passwords .create ("changeme" , username , realm )
5556 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
5657 self .assertEqual (p .realm , realm )
5758 # Prepends one escaped slash
58- self .assertEqual (p .username , " \\ " + username )
59+ self .assertEqual (p .username , username )
5960 self .assertEqual (p .clear_password , "changeme" )
6061 # Checks for 2 escaped slashes (Splunk encodes the single slash)
61- self .assertEqual (p .name , realm + ":\\ \\ " + username + ":" )
62+ self .assertEqual (p .name , " \\ " + realm + ":\\ " + username + ":" )
6263
6364 p .delete ()
6465 self .assertEqual (start_count , len (self .storage_passwords ))
@@ -82,12 +83,14 @@ def test_create_with_colons(self):
8283 username = testlib .tmpname ()
8384 realm = testlib .tmpname ()
8485
85- p = self .storage_passwords .create ("changeme" , username + ":end" , ":start" + realm )
86+ p = self .storage_passwords .create ("changeme" , username + ":end" ,
87+ ":start" + realm )
8688 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
8789 self .assertEqual (p .realm , ":start" + realm )
8890 self .assertEqual (p .username , username + ":end" )
8991 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:" )
9194
9295 p .delete ()
9396 self .assertEqual (start_count , len (self .storage_passwords ))
@@ -100,7 +103,8 @@ def test_create_with_colons(self):
100103 self .assertEqual (p .realm , realm )
101104 self .assertEqual (p .username , user )
102105 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\\ ::" )
104108
105109 p .delete ()
106110 self .assertEqual (start_count , len (self .storage_passwords ))
@@ -110,12 +114,15 @@ def test_create_crazy(self):
110114 username = testlib .tmpname ()
111115 realm = testlib .tmpname ()
112116
113- p = self .storage_passwords .create ("changeme" , username + ":end!@#$%^&*()_+{}:|<>?" , ":start::!@#$%^&*()_+{}:|<>?" + realm )
117+ p = self .storage_passwords .create ("changeme" ,
118+ username + ":end!@#$%^&*()_+{}:|<>?" ,
119+ ":start::!@#$%^&*()_+{}:|<>?" + realm )
114120 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
115121 self .assertEqual (p .realm , ":start::!@#$%^&*()_+{}:|<>?" + realm )
116122 self .assertEqual (p .username , username + ":end!@#$%^&*()_+{}:|<>?" )
117123 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!@#$%^&*()_+{}\\ :|<>?:" )
119126
120127 p .delete ()
121128 self .assertEqual (start_count , len (self .storage_passwords ))
@@ -165,7 +172,6 @@ def test_delete(self):
165172 start_count = len (self .storage_passwords )
166173 username = testlib .tmpname ()
167174
168- # Testing named parameters
169175 p = self .storage_passwords .create ("changeme" , username , "myrealm" )
170176 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
171177 self .assertEqual (p .realm , "myrealm" )
@@ -182,12 +188,15 @@ def test_delete(self):
182188 self .storage_passwords .delete ("myrealm:" + username + ":" )
183189 self .assertEqual (start_count , len (self .storage_passwords ))
184190
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" )
186194 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
187195
188196 self .storage_passwords .delete (username , "myrealm" )
189197 self .assertEqual (start_count , len (self .storage_passwords ))
190198
199+
191200if __name__ == "__main__" :
192201 try :
193202 import unittest2 as unittest
0 commit comments