cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
98736a03e136a27383d0902c88fdc664f4778a3d

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

component-tests/test_token.py

35lines · modecode

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