@@ -399,9 +399,10 @@ def test_vault_client_base_render_template(vault):
399399 assert vault .render_template ("Hello {{ vault('a/b').value }}" ) == "Hello c"
400400
401401
402- def test_vault_client_base_render_template_path_not_found (vault ):
402+ @pytest .mark .parametrize ("template" , ["Hello {{ vault('a/b') }}" , "Hello {{" ])
403+ def test_vault_client_base_render_template_path_not_found (vault , template ):
403404 with pytest .raises (exceptions .VaultRenderTemplateError ):
404- vault .render_template ("Hello {{ vault('a/b') }}" )
405+ vault .render_template (template )
405406
406407
407408@pytest .mark .parametrize (
@@ -499,18 +500,38 @@ def test_vault_client_base_get_secret_missing_key(vault):
499500 vault .get_secret ("a" , key = "username" )
500501
501502
503+ def test_vault_client_base_get_secret_template_error (vault , caplog ):
504+ vault .db = {"a" : {"key" : "!template!{{" }}
505+
506+ with pytest .raises (exceptions .VaultRenderTemplateError ) as exc_info :
507+ vault .get_secret ("a" )
508+
509+ assert str (exc_info .value ) == 'Error while rendering secret at path "a"'
510+ assert (
511+ str (exc_info .value .__cause__ )
512+ == 'Error while rendering secret value for key "key"'
513+ )
514+ assert str (exc_info .value .__cause__ .__cause__ ) == "Jinja2 template syntax error"
515+
516+
502517def test_vault_client_base_lookup_token (vault ):
503518 assert vault .lookup_token () == {"data" : {"expire_time" : "2100-01-01T00:00:00" }}
504519
505520
506- def test_vault_client_base_get_secrets_error (vault ):
521+ def test_vault_client_base_get_secrets_error (vault , caplog ):
507522 vault .db = {"a" : {"value" : "b" }, "c" : {"value" : "d" }}
508523 vault .forbidden_get_paths = {"c" }
509524
510525 assert vault .get_secrets ("" ) == {
511526 "a" : {"value" : "b" },
512- "c" : {"error" : "<error while retrieving secret>" },
527+ "c" : {},
513528 }
529+ assert caplog .record_tuples [0 ] == (
530+ "vault_cli.client" ,
531+ 40 ,
532+ "VaultForbidden: Insufficient access for interacting with the requested "
533+ "secret" ,
534+ )
514535
515536
516537def test_vault_client_base_get_secrets_list_forbidden (vault ):
@@ -571,12 +592,12 @@ def test_vault_client_base_base_path(vault, path, expected):
571592 assert vault .base_path == expected
572593
573594
574- def test_vault_client_base_get_secret_implicit_cache_ends (vault ):
595+ def test_vault_client_base_get_secret_implicit_cache (vault ):
575596 vault .db = {"a" : {"value" : "b" }}
576597 assert vault .get_secret ("a" ) == {"value" : "b" }
577598 vault .db = {"a" : {"value" : "c" }}
578- # Value updated. Cache was just for the duration of the call
579- assert vault .get_secret ("a" ) == {"value" : "c " }
599+ # Value was cached
600+ assert vault .get_secret ("a" ) == {"value" : "b " }
580601
581602
582603class RaceConditionTestVaultClient (testing .TestVaultClient ):
@@ -600,13 +621,16 @@ def test_vault_client_base_get_secret_implicit_cache_no_race_condition():
600621
601622 vault = RaceConditionTestVaultClient ()
602623
603- assert vault .get_secret ("a" ) == {"b" : "b0" , "c" : "c0" }
604- assert vault .get_secret ("a" ) == {"b" : "b1" , "c" : "c1" }
624+ with vault :
625+ assert vault .get_secret ("a" ) == {"b" : "b0" , "c" : "c0" }
626+ with vault :
627+ assert vault .get_secret ("a" ) == {"b" : "b1" , "c" : "c1" }
605628
606629 vault .db = {"d" : {"value" : """!template!{{ vault("a").b }}-{{ vault("a").c }}""" }}
607630
608631 # b2-c3 would be the value if caching didn't work.
609- assert vault .get_secret ("d" ) == {"value" : "b2-c2" }
632+ with vault :
633+ assert vault .get_secret ("d" ) == {"value" : "b2-c2" }
610634
611635
612636def test_vault_client_base_get_secrets_implicit_cache_no_race_condition ():
@@ -628,8 +652,9 @@ def test_vault_client_base_get_secrets_implicit_cache_no_race_condition():
628652
629653def test_vault_client_base_get_secret_explicit_cache (vault ):
630654 vault .db = {"a" : {"value" : "b" }}
631- with vault . caching () :
655+ with vault :
632656 assert vault .get_secret ("a" ) == {"value" : "b" }
633657 vault .db = {"a" : {"value" : "c" }}
634658 # Value not updated
635659 assert vault .get_secret ("a" ) == {"value" : "b" }
660+ assert vault .get_secret ("a" ) == {"value" : "c" }
0 commit comments