19
19
20
20
import splunklib .client as client
21
21
22
- class TestCreate (testlib .SDKTestCase ):
22
+ class Tests (testlib .SDKTestCase ):
23
23
def setUp (self ):
24
24
self .service = client .connect (** self .opts .kwargs )
25
25
self .storage_passwords = self .service .storage_passwords
@@ -35,7 +35,7 @@ def test_create(self):
35
35
realm = testlib .tmpname ()
36
36
username = testlib .tmpname ()
37
37
38
- p = self .storage_passwords .create (realm , username , "changeme" )
38
+ p = self .storage_passwords .create ("changeme" , username , realm )
39
39
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
40
40
self .assertEqual (p .realm , realm )
41
41
self .assertEqual (p .username , username )
@@ -49,7 +49,7 @@ def test_create_norealm(self):
49
49
start_count = len (self .storage_passwords )
50
50
username = testlib .tmpname ()
51
51
52
- p = self .storage_passwords .create ("" , username , "changeme " )
52
+ p = self .storage_passwords .create ("changeme " , username , "" )
53
53
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
54
54
self .assertEqual (p .realm , None )
55
55
self .assertEqual (p .username , username )
@@ -64,7 +64,7 @@ def test_create_with_colons(self):
64
64
username = testlib .tmpname ()
65
65
realm = testlib .tmpname ()
66
66
67
- p = self .storage_passwords .create (":start" + realm , username + ":end" , "changeme" )
67
+ p = self .storage_passwords .create ("changeme" , username + ":end" , ":start" + realm )
68
68
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
69
69
self .assertEqual (p .realm , ":start" + realm )
70
70
self .assertEqual (p .username , username + ":end" )
@@ -74,25 +74,56 @@ def test_create_with_colons(self):
74
74
p .delete ()
75
75
self .assertEqual (start_count , len (self .storage_passwords ))
76
76
77
- realm = ":r:e:a:l:m:"
77
+ prefix = testlib .tmpname ()
78
+ realm = prefix + ":r:e:a:l:m:"
78
79
user = ":u:s:e:r:"
79
- p = self .storage_passwords .create (realm , user , "changeme" )
80
+ p = self .storage_passwords .create ("changeme" , user , realm )
80
81
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
81
82
self .assertEqual (p .realm , realm )
82
83
self .assertEqual (p .username , user )
83
84
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
+
86
102
p .delete ()
87
103
self .assertEqual (start_count , len (self .storage_passwords ))
88
104
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 ))
89
120
90
121
def test_update (self ):
91
122
start_count = len (self .storage_passwords )
92
123
realm = testlib .tmpname ()
93
124
username = testlib .tmpname ()
94
125
95
- p = self .storage_passwords .create (realm , username , "changeme" )
126
+ p = self .storage_passwords .create ("changeme" , username , realm )
96
127
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
97
128
self .assertEqual (p .realm , realm )
98
129
self .assertEqual (p .username , username )
@@ -113,29 +144,30 @@ def test_update(self):
113
144
self .assertEqual (start_count , len (self .storage_passwords ))
114
145
115
146
def test_delete (self ):
116
- # TODO: make a bunch of tests for different ways of deleting
117
147
start_count = len (self .storage_passwords )
148
+ username = testlib .tmpname ()
118
149
119
- p = self .storage_passwords .create ("myfoo" , "yourbar2" , "changeme" )
150
+ # Testing named parameters
151
+ p = self .storage_passwords .create ("changeme" , username , "myrealm" )
120
152
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 )
123
155
self .assertEqual (p .clear_password , "changeme" )
124
- self .assertEqual (p .name , "myfoo:yourbar2 :" )
156
+ self .assertEqual (p .name , "myrealm:" + username + " :" )
125
157
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 ) )
131
163
132
- self .storage_passwords .delete ("myfoo:yourbar2 " )
164
+ self .storage_passwords .delete ("myrealm:" + username + ": " )
133
165
self .assertEqual (start_count , len (self .storage_passwords ))
134
166
135
- self .storage_passwords .create ("myfoo " , "yourbar2" , "changeme " )
167
+ self .storage_passwords .create ("changeme " , username , realm = "myrealm " )
136
168
self .assertEqual (start_count + 1 , len (self .storage_passwords ))
137
169
138
- self .storage_passwords .delete ("myfoo:yourbar2: " )
170
+ self .storage_passwords .delete (username , "myrealm " )
139
171
self .assertEqual (start_count , len (self .storage_passwords ))
140
172
141
173
if __name__ == "__main__" :
0 commit comments