21 lines
1.1 KiB
Python
21 lines
1.1 KiB
Python
import pathlib,runpy,tempfile,unittest
|
|
|
|
promoter=runpy.run_path(str(pathlib.Path(__file__).with_name('dunerealms-promote-safe-v2.py')))
|
|
|
|
class ServingPortTests(unittest.TestCase):
|
|
def config(self,name,text):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path=pathlib.Path(directory)/name;path.write_text(text)
|
|
return promoter['config_port'](path)
|
|
|
|
def test_world_status_proxy_cannot_impersonate_cp_backend(self):
|
|
self.assertEqual(self.config('cp.dunerealms.com.conf','location = /api/worlds { proxy_pass http://127.0.0.1:3200/api/worlds; }\nlocation / { proxy_pass http://127.0.0.1:3203; }'),3203)
|
|
|
|
def test_duplicate_same_upstream_is_valid(self):
|
|
self.assertEqual(self.config('dunerealms.com.conf','proxy_pass http://127.0.0.1:3100/git;\nproxy_pass http://127.0.0.1:3100/;'),3100)
|
|
|
|
def test_conflicting_or_unknown_backends_are_rejected(self):
|
|
for text in ['proxy_pass http://127.0.0.1:3103; proxy_pass http://127.0.0.1:3203;','proxy_pass http://127.0.0.1:18081;']:
|
|
with self.assertRaises(RuntimeError):self.config('cp.dunerealms.com.conf',text)
|
|
|
|
if __name__=='__main__':unittest.main()
|

Staff