test_token.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import base64
  2. import json
  3. from setup import get_config_from_file, persist_origin_cert
  4. from util import start_cloudflared
  5. class TestToken:
  6. def test_get_token(self, tmp_path, component_tests_config):
  7. config = component_tests_config()
  8. tunnel_id = config.get_tunnel_id()
  9. token_args = ["--origincert", cert_path(), "token", tunnel_id]
  10. output = start_cloudflared(tmp_path, config, token_args)
  11. assert parse_token(config.get_token()) == parse_token(output.stdout)
  12. def test_get_credentials_file(self, tmp_path, component_tests_config):
  13. config = component_tests_config()
  14. tunnel_id = config.get_tunnel_id()
  15. cred_file = tmp_path / "test_get_credentials_file.json"
  16. token_args = ["--origincert", cert_path(), "token", "--cred-file", cred_file, tunnel_id]
  17. start_cloudflared(tmp_path, config, token_args)
  18. with open(cred_file) as json_file:
  19. assert config.get_credentials_json() == json.load(json_file)
  20. def cert_path():
  21. return get_config_from_file()["origincert"]
  22. def parse_token(token):
  23. return json.loads(base64.b64decode(token))