1919
2020import splunklib .client as client
2121
22- class TestCreate (testlib .SDKTestCase ):
22+ class Tests (testlib .SDKTestCase ):
2323 def setUp (self ):
2424 self .service = client .connect (** self .opts .kwargs )
2525 self .storage_passwords = self .service .storage_passwords
@@ -35,7 +35,7 @@ def test_create(self):
3535 realm = testlib .tmpname ()
3636 username = testlib .tmpname ()
3737
38- p = self .storage_passwords .create (realm , username , "changeme" )
38+ p = self .storage_passwords .create ("changeme" , username , realm )
3939 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
4040 self .assertEqual (p .realm , realm )
4141 self .assertEqual (p .username , username )
@@ -49,7 +49,7 @@ def test_create_norealm(self):
4949 start_count = len (self .storage_passwords )
5050 username = testlib .tmpname ()
5151
52- p = self .storage_passwords .create ("" , username , "changeme " )
52+ p = self .storage_passwords .create ("changeme " , username , "" )
5353 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
5454 self .assertEqual (p .realm , None )
5555 self .assertEqual (p .username , username )
@@ -64,7 +64,7 @@ def test_create_with_colons(self):
6464 username = testlib .tmpname ()
6565 realm = testlib .tmpname ()
6666
67- p = self .storage_passwords .create (":start" + realm , username + ":end" , "changeme" )
67+ p = self .storage_passwords .create ("changeme" , username + ":end" , ":start" + realm )
6868 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
6969 self .assertEqual (p .realm , ":start" + realm )
7070 self .assertEqual (p .username , username + ":end" )
@@ -74,25 +74,56 @@ def test_create_with_colons(self):
7474 p .delete ()
7575 self .assertEqual (start_count , len (self .storage_passwords ))
7676
77- realm = ":r:e:a:l:m:"
77+ prefix = testlib .tmpname ()
78+ realm = prefix + ":r:e:a:l:m:"
7879 user = ":u:s:e:r:"
79- p = self .storage_passwords .create (realm , user , "changeme" )
80+ p = self .storage_passwords .create ("changeme" , user , realm )
8081 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
8182 self .assertEqual (p .realm , realm )
8283 self .assertEqual (p .username , user )
8384 self .assertEqual (p .clear_password , "changeme" )
84- self .assertEqual (p .name , "\\ :r\\ :e\\ :a\\ :l\\ :m\\ ::\\ :u\\ :s\\ :e\\ :r\\ ::" )
85-
85+ self .assertEqual (p .name , prefix + "\\ :r\\ :e\\ :a\\ :l\\ :m\\ ::\\ :u\\ :s\\ :e\\ :r\\ ::" )
86+
87+ p .delete ()
88+ self .assertEqual (start_count , len (self .storage_passwords ))
89+
90+ def test_create_crazy (self ):
91+ start_count = len (self .storage_passwords )
92+ username = testlib .tmpname ()
93+ realm = testlib .tmpname ()
94+
95+ p = self .storage_passwords .create ("changeme" , username + ":end!@#$%^&*()_+{}:|<>?" , ":start::!@#$%^&*()_+{}:|<>?" + realm )
96+ self .assertEqual (start_count + 1 , len (self .storage_passwords ))
97+ self .assertEqual (p .realm , ":start::!@#$%^&*()_+{}:|<>?" + realm )
98+ self .assertEqual (p .username , username + ":end!@#$%^&*()_+{}:|<>?" )
99+ self .assertEqual (p .clear_password , "changeme" )
100+ self .assertEqual (p .name , "\\ :start\\ :\\ :!@#$%^&*()_+{}\\ :|<>?" + realm + ":" + username + "\\ :end!@#$%^&*()_+{}\\ :|<>?:" )
101+
86102 p .delete ()
87103 self .assertEqual (start_count , len (self .storage_passwords ))
88104
105+ def test_read (self ):
106+ start_count = len (self .storage_passwords )
107+ username = testlib .tmpname ()
108+
109+ p = self .storage_passwords .create ("changeme" , username , "" )
110+ self .assertEqual (start_count + 1 , len (self .storage_passwords ))
111+
112+ for sp in self .storage_passwords :
113+ self .assertTrue (p .name in self .storage_passwords )
114+ # Name works with or without a trailing colon
115+ self .assertTrue ((":" + username + ":" ) in self .storage_passwords )
116+ self .assertTrue ((":" + username ) in self .storage_passwords )
117+
118+ p .delete ()
119+ self .assertEqual (start_count , len (self .storage_passwords ))
89120
90121 def test_update (self ):
91122 start_count = len (self .storage_passwords )
92123 realm = testlib .tmpname ()
93124 username = testlib .tmpname ()
94125
95- p = self .storage_passwords .create (realm , username , "changeme" )
126+ p = self .storage_passwords .create ("changeme" , username , realm )
96127 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
97128 self .assertEqual (p .realm , realm )
98129 self .assertEqual (p .username , username )
@@ -113,29 +144,30 @@ def test_update(self):
113144 self .assertEqual (start_count , len (self .storage_passwords ))
114145
115146 def test_delete (self ):
116- # TODO: make a bunch of tests for different ways of deleting
117147 start_count = len (self .storage_passwords )
148+ username = testlib .tmpname ()
118149
119- p = self .storage_passwords .create ("myfoo" , "yourbar2" , "changeme" )
150+ # Testing named parameters
151+ p = self .storage_passwords .create ("changeme" , username , "myrealm" )
120152 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
121- self .assertEqual (p .realm , "myfoo " )
122- self .assertEqual (p .username , "yourbar2" )
153+ self .assertEqual (p .realm , "myrealm " )
154+ self .assertEqual (p .username , username )
123155 self .assertEqual (p .clear_password , "changeme" )
124- self .assertEqual (p .name , "myfoo:yourbar2 :" )
156+ self .assertEqual (p .name , "myrealm:" + username + " :" )
125157
126- # TODO: move these tests out
127- for sp in self .storage_passwords :
128- self . assertTrue ( "myfoo:yourbar2" in self . storage_passwords )
129- # Name works with or without a trailing colon
130- self .assertTrue ( "myfoo:yourbar2:" in self .storage_passwords )
158+ self . storage_passwords . delete ( username , "myrealm" )
159+ self . assertEqual ( start_count , len ( self .storage_passwords ))
160+
161+ self . storage_passwords . create ( "changeme" , username , "myrealm" )
162+ self .assertEqual ( start_count + 1 , len ( self .storage_passwords ) )
131163
132- self .storage_passwords .delete ("myfoo:yourbar2 " )
164+ self .storage_passwords .delete ("myrealm:" + username + ": " )
133165 self .assertEqual (start_count , len (self .storage_passwords ))
134166
135- self .storage_passwords .create ("myfoo " , "yourbar2" , "changeme " )
167+ self .storage_passwords .create ("changeme " , username , realm = "myrealm " )
136168 self .assertEqual (start_count + 1 , len (self .storage_passwords ))
137169
138- self .storage_passwords .delete ("myfoo:yourbar2: " )
170+ self .storage_passwords .delete (username , "myrealm " )
139171 self .assertEqual (start_count , len (self .storage_passwords ))
140172
141173if __name__ == "__main__" :
0 commit comments