|
14 | 14 | ) |
15 | 15 | from dstack._internal.core.models.runs import RunSpec |
16 | 16 | from dstack._internal.server.services.services import ( |
17 | | - _get_service_https, |
18 | 17 | _register_service_in_server, |
| 18 | + _should_configure_service_https_on_gateway, |
| 19 | + _should_show_service_https, |
19 | 20 | ) |
20 | 21 | from dstack._internal.server.testing.common import get_run_spec |
21 | 22 |
|
@@ -54,33 +55,69 @@ def test_accepts_auto(self) -> None: |
54 | 55 | assert conf.https == "auto" |
55 | 56 |
|
56 | 57 |
|
57 | | -class TestGetServiceHttps: |
| 58 | +class TestShouldConfigureServiceHttpsOnGateway: |
58 | 59 | def test_auto_resolves_to_true_with_lets_encrypt_gateway(self) -> None: |
59 | 60 | run_spec = _service_run_spec(https="auto") |
60 | 61 | gw = _gateway_config(certificate=LetsEncryptGatewayCertificate()) |
61 | | - assert _get_service_https(run_spec, gw) is True |
| 62 | + assert _should_configure_service_https_on_gateway(run_spec, gw) is True |
62 | 63 |
|
63 | 64 | def test_auto_resolves_to_false_when_gateway_has_no_certificate(self) -> None: |
64 | 65 | run_spec = _service_run_spec(https="auto") |
65 | 66 | gw = _gateway_config(certificate=None) |
66 | | - assert _get_service_https(run_spec, gw) is False |
| 67 | + assert _should_configure_service_https_on_gateway(run_spec, gw) is False |
67 | 68 |
|
68 | 69 | def test_auto_resolves_to_false_with_acm_gateway(self) -> None: |
69 | 70 | run_spec = _service_run_spec(https="auto") |
70 | 71 | gw = _gateway_config( |
71 | 72 | certificate=ACMGatewayCertificate(arn="arn:aws:acm:us-east-1:123:cert/abc") |
72 | 73 | ) |
73 | | - assert _get_service_https(run_spec, gw) is False |
| 74 | + assert _should_configure_service_https_on_gateway(run_spec, gw) is False |
| 75 | + |
| 76 | + def test_true_enables_https_when_gateway_has_no_certificate(self) -> None: |
| 77 | + run_spec = _service_run_spec(https=True) |
| 78 | + gw = _gateway_config(certificate=None) |
| 79 | + assert _should_configure_service_https_on_gateway(run_spec, gw) is True |
| 80 | + |
| 81 | + def test_false_disables_https_regardless_of_gateway_certificate(self) -> None: |
| 82 | + run_spec = _service_run_spec(https=False) |
| 83 | + gw = _gateway_config(certificate=LetsEncryptGatewayCertificate()) |
| 84 | + assert _should_configure_service_https_on_gateway(run_spec, gw) is False |
| 85 | + |
| 86 | + def test_true_does_not_configure_https_on_acm_gateway(self) -> None: |
| 87 | + run_spec = _service_run_spec(https=True) |
| 88 | + gw = _gateway_config( |
| 89 | + certificate=ACMGatewayCertificate(arn="arn:aws:acm:us-east-1:123:cert/abc") |
| 90 | + ) |
| 91 | + assert _should_configure_service_https_on_gateway(run_spec, gw) is False |
| 92 | + |
| 93 | + |
| 94 | +class TestShouldShowServiceHttps: |
| 95 | + def test_auto_resolves_to_true_with_lets_encrypt_gateway(self) -> None: |
| 96 | + run_spec = _service_run_spec(https="auto") |
| 97 | + gw = _gateway_config(certificate=LetsEncryptGatewayCertificate()) |
| 98 | + assert _should_show_service_https(run_spec, gw) is True |
| 99 | + |
| 100 | + def test_auto_resolves_to_false_when_gateway_has_no_certificate(self) -> None: |
| 101 | + run_spec = _service_run_spec(https="auto") |
| 102 | + gw = _gateway_config(certificate=None) |
| 103 | + assert _should_show_service_https(run_spec, gw) is False |
| 104 | + |
| 105 | + def test_auto_resolves_to_true_with_acm_gateway(self) -> None: |
| 106 | + run_spec = _service_run_spec(https="auto") |
| 107 | + gw = _gateway_config( |
| 108 | + certificate=ACMGatewayCertificate(arn="arn:aws:acm:us-east-1:123:cert/abc") |
| 109 | + ) |
| 110 | + assert _should_show_service_https(run_spec, gw) is True |
74 | 111 |
|
75 | 112 | def test_true_enables_https_regardless_of_gateway_certificate(self) -> None: |
76 | 113 | run_spec = _service_run_spec(https=True) |
77 | 114 | gw = _gateway_config(certificate=None) |
78 | | - assert _get_service_https(run_spec, gw) is True |
| 115 | + assert _should_show_service_https(run_spec, gw) is True |
79 | 116 |
|
80 | 117 | def test_false_disables_https_regardless_of_gateway_certificate(self) -> None: |
81 | 118 | run_spec = _service_run_spec(https=False) |
82 | 119 | gw = _gateway_config(certificate=LetsEncryptGatewayCertificate()) |
83 | | - assert _get_service_https(run_spec, gw) is False |
| 120 | + assert _should_show_service_https(run_spec, gw) is False |
84 | 121 |
|
85 | 122 |
|
86 | 123 | class TestRegisterServiceInServerHttps: |
|
0 commit comments