feat(editorial): wire serialized Stage runtime install and PMO proposal client
This commit is contained in:
1 parent
8869ce2583
commit
f7cf2c8f5d
8 files changed
+387
-4
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT=Path(__file__).resolve().parent
|
||||
BUNDLE = ROOT/'hermes-editorial' if (ROOT/'hermes-editorial').exists() else ROOT.parent/'infra/hermes-editorial'
|
||||
|
||||
def load(name, path):
|
||||
spec=importlib.util.spec_from_file_location(name,path)
|
||||
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);return m
|
||||
|
||||
class ProvisionTests(unittest.TestCase):
|
||||
def test_runtime_install_and_credential_are_idempotent_and_private(self):
|
||||
self.assertTrue((ROOT/'provision-editorial-runtime.py').exists(), 'CI editorial wiring missing')
|
||||
m=load('editorial',ROOT/'provision-editorial-runtime.py')
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
home=Path(t); sentinel=home/'config.yaml';sentinel.write_text('unchanged')
|
||||
payload=m.package(BUNDLE,'a'*40)
|
||||
a=m.install(home,payload);b=m.install(home,payload)
|
||||
self.assertEqual(a,b);self.assertEqual(sentinel.read_text(),'unchanged')
|
||||
self.assertEqual((home/'credentials/editorial-pmo-token').stat().st_mode & 0o777,0o400)
|
||||
self.assertEqual(a['files'],19)
|
||||
grants={'grants':[{'id':'ci','role':'STAGE_CI','credentialSha256':'c'*64},{'id':'worker','role':'WORKFLOW_WORKER','credentialSha256':'d'*64}], 'workerIds':['worker'],'stageCiIds':['ci'],'artifactBaseUrl':'https://stageapi.canina.ir/api/internal/prepare-worker/artifacts'}
|
||||
updated=m.add_grant(grants,a['credentialSha256'])
|
||||
self.assertEqual(updated['grants'][:2],grants['grants']);self.assertEqual(len(updated['grants']),3)
|
||||
self.assertEqual(m.add_grant(updated,a['credentialSha256']),updated)
|
||||
with self.assertRaises(ValueError):m.add_grant(updated,'e'*64)
|
||||
self.assertEqual(grants['workerIds'],['worker'])
|
||||
(home/'credentials/editorial-pmo-token').chmod(0o644)
|
||||
with self.assertRaises(ValueError):m.install(home,payload)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user