MC/website/ops/test_lobby_account_config.py

28 lines
1.6 KiB
Python

import importlib.util
from pathlib import Path
import unittest
import tempfile
import json
import hashlib
s=importlib.util.spec_from_file_location('lobby_config',Path(__file__).with_name('configure-lobby-account.py'))
m=importlib.util.module_from_spec(s);s.loader.exec_module(m)
class ConfigTests(unittest.TestCase):
def test_only_three_settings_change_and_replay_is_stable(self):
old='# private config\nDB_PASSWORD=untouched\nLOBBY_ACCOUNT_ENABLED=false\nexport LOBBY_ACCOUNT_TOKEN=old\nOTHER=true\n'
result=m.configured(old,'a'*43,'b'*64)
self.assertIn('DB_PASSWORD=untouched',result);self.assertIn('OTHER=true',result)
self.assertNotIn('=old',result);self.assertEqual(result,m.configured(result,'a'*43,'b'*64))
self.assertEqual(result.count('LOBBY_ACCOUNT_TOKEN='),1)
def test_invalid_material_cannot_enter_environment(self):
with self.assertRaises(ValueError):m.configured('',"x\nBAD=true",'b'*64)
def test_artifact_source_and_helper_bytes_must_match(self):
with tempfile.TemporaryDirectory() as folder:
p=Path(folder)/'configure-lobby-account.py';p.write_bytes(b'verified')
manifest={'sourceRepository':'https://www.dunerealms.com/git/unimatrix/web.git','sourceCommit':'a'*40,'files':{p.name:{'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'bytes':8}}}
(p.parent/'manifest.json').write_text(json.dumps(manifest))
self.assertTrue(m.reviewed_source(p,'a'*40));self.assertFalse(m.reviewed_source(p,'b'*40))
p.write_bytes(b'changed!');self.assertFalse(m.reviewed_source(p,'a'*40))
if __name__=='__main__':unittest.main()