@@ -204,6 +204,60 @@ def test_simple(self, mock_redis):
204
204
self .assertEqual (result [0 ], 'remote_host' )
205
205
self .assertEqual (result [1 ], 'remote_port' )
206
206
207
+ @patch ('redis.Redis' )
208
+ def test_json_token_with_spaces (self , mock_redis ):
209
+ plugin = TokenRedis ('127.0.0.1:1234' )
210
+
211
+ instance = mock_redis .return_value
212
+ instance .get .return_value = b' {"host": "remote_host:remote_port"} '
213
+
214
+ result = plugin .lookup ('testhost' )
215
+
216
+ instance .get .assert_called_once_with ('testhost' )
217
+ self .assertIsNotNone (result )
218
+ self .assertEqual (result [0 ], 'remote_host' )
219
+ self .assertEqual (result [1 ], 'remote_port' )
220
+
221
+ @patch ('redis.Redis' )
222
+ def test_text_token (self , mock_redis ):
223
+ plugin = TokenRedis ('127.0.0.1:1234' )
224
+
225
+ instance = mock_redis .return_value
226
+ instance .get .return_value = b'remote_host:remote_port'
227
+
228
+ result = plugin .lookup ('testhost' )
229
+
230
+ instance .get .assert_called_once_with ('testhost' )
231
+ self .assertIsNotNone (result )
232
+ self .assertEqual (result [0 ], 'remote_host' )
233
+ self .assertEqual (result [1 ], 'remote_port' )
234
+
235
+ @patch ('redis.Redis' )
236
+ def test_text_token_with_spaces (self , mock_redis ):
237
+ plugin = TokenRedis ('127.0.0.1:1234' )
238
+
239
+ instance = mock_redis .return_value
240
+ instance .get .return_value = b' remote_host:remote_port '
241
+
242
+ result = plugin .lookup ('testhost' )
243
+
244
+ instance .get .assert_called_once_with ('testhost' )
245
+ self .assertIsNotNone (result )
246
+ self .assertEqual (result [0 ], 'remote_host' )
247
+ self .assertEqual (result [1 ], 'remote_port' )
248
+
249
+ @patch ('redis.Redis' )
250
+ def test_invalid_token (self , mock_redis ):
251
+ plugin = TokenRedis ('127.0.0.1:1234' )
252
+
253
+ instance = mock_redis .return_value
254
+ instance .get .return_value = b'{"host": "remote_host:remote_port" '
255
+
256
+ result = plugin .lookup ('testhost' )
257
+
258
+ instance .get .assert_called_once_with ('testhost' )
259
+ self .assertIsNone (result )
260
+
207
261
def test_src_only_host (self ):
208
262
plugin = TokenRedis ('127.0.0.1' )
209
263
0 commit comments