@@ -267,13 +267,50 @@ def test_invalid_token(self, mock_redis):
267
267
instance .get .assert_called_once_with ('testhost' )
268
268
self .assertIsNone (result )
269
269
270
+ @patch ('redis.Redis' )
271
+ def test_token_without_namespace (self , mock_redis ):
272
+ plugin = TokenRedis ('127.0.0.1:1234' )
273
+ token = 'testhost'
274
+
275
+ def mock_redis_get (key ):
276
+ self .assertEqual (key , token )
277
+ return b'remote_host:remote_port'
278
+
279
+ instance = mock_redis .return_value
280
+ instance .get = mock_redis_get
281
+
282
+ result = plugin .lookup (token )
283
+
284
+ self .assertIsNotNone (result )
285
+ self .assertEqual (result [0 ], 'remote_host' )
286
+ self .assertEqual (result [1 ], 'remote_port' )
287
+
288
+ @patch ('redis.Redis' )
289
+ def test_token_with_namespace (self , mock_redis ):
290
+ plugin = TokenRedis ('127.0.0.1:1234:::namespace' )
291
+ token = 'testhost'
292
+
293
+ def mock_redis_get (key ):
294
+ self .assertEqual (key , "namespace:" + token )
295
+ return b'remote_host:remote_port'
296
+
297
+ instance = mock_redis .return_value
298
+ instance .get = mock_redis_get
299
+
300
+ result = plugin .lookup (token )
301
+
302
+ self .assertIsNotNone (result )
303
+ self .assertEqual (result [0 ], 'remote_host' )
304
+ self .assertEqual (result [1 ], 'remote_port' )
305
+
270
306
def test_src_only_host (self ):
271
307
plugin = TokenRedis ('127.0.0.1' )
272
308
273
309
self .assertEqual (plugin ._server , '127.0.0.1' )
274
310
self .assertEqual (plugin ._port , 6379 )
275
311
self .assertEqual (plugin ._db , 0 )
276
312
self .assertEqual (plugin ._password , None )
313
+ self .assertEqual (plugin ._namespace , "" )
277
314
278
315
def test_src_with_host_port (self ):
279
316
plugin = TokenRedis ('127.0.0.1:1234' )
@@ -282,6 +319,7 @@ def test_src_with_host_port(self):
282
319
self .assertEqual (plugin ._port , 1234 )
283
320
self .assertEqual (plugin ._db , 0 )
284
321
self .assertEqual (plugin ._password , None )
322
+ self .assertEqual (plugin ._namespace , "" )
285
323
286
324
def test_src_with_host_port_db (self ):
287
325
plugin = TokenRedis ('127.0.0.1:1234:2' )
@@ -290,6 +328,7 @@ def test_src_with_host_port_db(self):
290
328
self .assertEqual (plugin ._port , 1234 )
291
329
self .assertEqual (plugin ._db , 2 )
292
330
self .assertEqual (plugin ._password , None )
331
+ self .assertEqual (plugin ._namespace , "" )
293
332
294
333
def test_src_with_host_port_db_pass (self ):
295
334
plugin = TokenRedis ('127.0.0.1:1234:2:verysecret' )
@@ -298,67 +337,103 @@ def test_src_with_host_port_db_pass(self):
298
337
self .assertEqual (plugin ._port , 1234 )
299
338
self .assertEqual (plugin ._db , 2 )
300
339
self .assertEqual (plugin ._password , 'verysecret' )
340
+ self .assertEqual (plugin ._namespace , "" )
341
+
342
+ def test_src_with_host_port_db_pass_namespace (self ):
343
+ plugin = TokenRedis ('127.0.0.1:1234:2:verysecret:namespace' )
344
+
345
+ self .assertEqual (plugin ._server , '127.0.0.1' )
346
+ self .assertEqual (plugin ._port , 1234 )
347
+ self .assertEqual (plugin ._db , 2 )
348
+ self .assertEqual (plugin ._password , 'verysecret' )
349
+ self .assertEqual (plugin ._namespace , "namespace:" )
301
350
302
- def test_src_with_host_empty_port_empty_db_pass (self ):
351
+ def test_src_with_host_empty_port_empty_db_pass_no_namespace (self ):
303
352
plugin = TokenRedis ('127.0.0.1:::verysecret' )
304
353
305
354
self .assertEqual (plugin ._server , '127.0.0.1' )
306
355
self .assertEqual (plugin ._port , 6379 )
307
356
self .assertEqual (plugin ._db , 0 )
308
357
self .assertEqual (plugin ._password , 'verysecret' )
358
+ self .assertEqual (plugin ._namespace , "" )
359
+
360
+ def test_src_with_host_empty_port_empty_db_empty_pass_empty_namespace (self ):
361
+ plugin = TokenRedis ('127.0.0.1::::' )
309
362
310
- def test_src_with_host_empty_port_empty_db_empty_pass (self ):
363
+ self .assertEqual (plugin ._server , '127.0.0.1' )
364
+ self .assertEqual (plugin ._port , 6379 )
365
+ self .assertEqual (plugin ._db , 0 )
366
+ self .assertEqual (plugin ._password , None )
367
+ self .assertEqual (plugin ._namespace , "" )
368
+
369
+ def test_src_with_host_empty_port_empty_db_empty_pass_no_namespace (self ):
311
370
plugin = TokenRedis ('127.0.0.1:::' )
312
371
313
372
self .assertEqual (plugin ._server , '127.0.0.1' )
314
373
self .assertEqual (plugin ._port , 6379 )
315
374
self .assertEqual (plugin ._db , 0 )
316
375
self .assertEqual (plugin ._password , None )
376
+ self .assertEqual (plugin ._namespace , "" )
317
377
318
- def test_src_with_host_empty_port_empty_db_no_pass (self ):
378
+ def test_src_with_host_empty_port_empty_db_no_pass_no_namespace (self ):
319
379
plugin = TokenRedis ('127.0.0.1::' )
320
380
321
381
self .assertEqual (plugin ._server , '127.0.0.1' )
322
382
self .assertEqual (plugin ._port , 6379 )
323
383
self .assertEqual (plugin ._db , 0 )
324
384
self .assertEqual (plugin ._password , None )
385
+ self .assertEqual (plugin ._namespace , "" )
325
386
326
- def test_src_with_host_empty_port_no_db_no_pass (self ):
387
+ def test_src_with_host_empty_port_no_db_no_pass_no_namespace (self ):
327
388
plugin = TokenRedis ('127.0.0.1:' )
328
389
329
390
self .assertEqual (plugin ._server , '127.0.0.1' )
330
391
self .assertEqual (plugin ._port , 6379 )
331
392
self .assertEqual (plugin ._db , 0 )
332
393
self .assertEqual (plugin ._password , None )
394
+ self .assertEqual (plugin ._namespace , "" )
395
+
396
+ def test_src_with_host_empty_port_empty_db_empty_pass_namespace (self ):
397
+ plugin = TokenRedis ('127.0.0.1::::namespace' )
398
+
399
+ self .assertEqual (plugin ._server , '127.0.0.1' )
400
+ self .assertEqual (plugin ._port , 6379 )
401
+ self .assertEqual (plugin ._db , 0 )
402
+ self .assertEqual (plugin ._password , None )
403
+ self .assertEqual (plugin ._namespace , "namespace:" )
333
404
334
- def test_src_with_host_empty_port_db_no_pass (self ):
405
+ def test_src_with_host_empty_port_db_no_pass_no_namespace (self ):
335
406
plugin = TokenRedis ('127.0.0.1::2' )
336
407
337
408
self .assertEqual (plugin ._server , '127.0.0.1' )
338
409
self .assertEqual (plugin ._port , 6379 )
339
410
self .assertEqual (plugin ._db , 2 )
340
411
self .assertEqual (plugin ._password , None )
412
+ self .assertEqual (plugin ._namespace , "" )
341
413
342
- def test_src_with_host_port_empty_db_pass (self ):
414
+ def test_src_with_host_port_empty_db_pass_no_namespace (self ):
343
415
plugin = TokenRedis ('127.0.0.1:1234::verysecret' )
344
416
345
417
self .assertEqual (plugin ._server , '127.0.0.1' )
346
418
self .assertEqual (plugin ._port , 1234 )
347
419
self .assertEqual (plugin ._db , 0 )
348
420
self .assertEqual (plugin ._password , 'verysecret' )
421
+ self .assertEqual (plugin ._namespace , "" )
349
422
350
- def test_src_with_host_empty_port_db_pass (self ):
423
+ def test_src_with_host_empty_port_db_pass_no_namespace (self ):
351
424
plugin = TokenRedis ('127.0.0.1::2:verysecret' )
352
425
353
426
self .assertEqual (plugin ._server , '127.0.0.1' )
354
427
self .assertEqual (plugin ._port , 6379 )
355
428
self .assertEqual (plugin ._db , 2 )
356
429
self .assertEqual (plugin ._password , 'verysecret' )
430
+ self .assertEqual (plugin ._namespace , "" )
357
431
358
- def test_src_with_host_empty_port_db_empty_pass (self ):
432
+ def test_src_with_host_empty_port_db_empty_pass_no_namespace (self ):
359
433
plugin = TokenRedis ('127.0.0.1::2:' )
360
434
361
435
self .assertEqual (plugin ._server , '127.0.0.1' )
362
436
self .assertEqual (plugin ._port , 6379 )
363
437
self .assertEqual (plugin ._db , 2 )
364
438
self .assertEqual (plugin ._password , None )
439
+ self .assertEqual (plugin ._namespace , "" )
0 commit comments