def test_write_cache_standard(cache_single): """ Test write cache with standard single use token """ function_response = vault.write_cache(copy(cache_single)) assert vault.__context__["vault_token"] == copy(cache_single) assert function_response is True
def test_write_cache_unlimited_token(self): """ Test write cache with unlimited use token """ write_data = { "url": "http://127.0.0.1:8200", "token": "test", "verify": None, "uses": 0, "lease_duration": 100, "issued": 3000, } expected_write = { "url": "http://127.0.0.1:8200", "token": "test", "verify": None, "uses": 0, "lease_duration": 100, "issued": 3000, "unlimited_use_token": True, } with patch("salt.utils.files.fpopen", mock_open()) as mock_fpopen: function_response = vault.write_cache(write_data) assert mock_fpopen.call_count == 1 self.assertListEqual( list(mock_fpopen.filehandles), [os.path.join("somepath", "salt_vault_token")], ) opens = mock_fpopen.filehandles[ os.path.join("somepath", "salt_vault_token") ] write_calls_output = json.loads(opens[0].write_calls[0]) self.assertEqual(write_calls_output, expected_write) self.assertTrue(function_response)
def test_write_cache_unlimited_token(cache_uses, tmp_cache): """ Test write cache with unlimited use token """ write_data = { "url": "http://127.0.0.1:8200", "token": "test", "verify": None, "namespace": None, "uses": 0, "lease_duration": 100, "issued": 3000, } expected_write = { "url": "http://127.0.0.1:8200", "token": "test", "verify": None, "namespace": None, "uses": 0, "lease_duration": 100, "issued": 3000, "unlimited_use_token": True, } function_response = vault.write_cache(write_data) with salt.utils.files.fopen(os.path.join(tmp_cache, "salt_vault_token"), "r") as fp: token_data = json.loads(fp.read()) assert token_data == expected_write
def test_write_cache_standard(self): """ Test write cache with standard single use token """ function_response = vault.write_cache(copy(self.cache_single)) self.assertEqual(vault.__context__["vault_token"], copy(self.cache_single)) self.assertTrue(function_response)
def target(evt, cache_uses): evt.wait() function_response = vault.write_cache(cache_uses)