forked from longtao.wu/droboticflow
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""Credential requirements are checked without contacting the POC environment."""
|
|
import importlib.util
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
PASSWORD_VARS = (
|
|
"DROBOTICFLOW_ACCEPTANCE_PASSWORD",
|
|
"FANYU_ANNOTATOR_PASSWORD",
|
|
"FANYU_QUALITY_PASSWORD",
|
|
"FANYU_ACCEPTANCE_PASSWORD",
|
|
)
|
|
|
|
|
|
def load_remote_script():
|
|
spec = importlib.util.spec_from_file_location("remote_poc", ROOT / "scripts/execute_remote_poc_test.py")
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def test_remote_poc_requires_passwords_before_network(monkeypatch):
|
|
module = load_remote_script()
|
|
for key in PASSWORD_VARS:
|
|
monkeypatch.delenv(key, raising=False)
|
|
monkeypatch.setattr(module.RemoteSession, "login", lambda *args: pytest.fail("login attempted without credentials"))
|
|
with pytest.raises(ValueError, match="DROBOTICFLOW_ACCEPTANCE_PASSWORD"):
|
|
module.main()
|
|
|
|
|
|
def test_remote_poc_uses_supplied_admin_password(monkeypatch):
|
|
module = load_remote_script()
|
|
for key in PASSWORD_VARS:
|
|
monkeypatch.setenv(key, "fixture-value")
|
|
calls = []
|
|
|
|
class StopBeforeNetwork(Exception):
|
|
pass
|
|
|
|
def login(session, email, password):
|
|
calls.append((email, password))
|
|
raise StopBeforeNetwork
|
|
|
|
monkeypatch.setattr(module.RemoteSession, "login", login)
|
|
with pytest.raises(StopBeforeNetwork):
|
|
module.main()
|
|
assert calls == [("poc-acceptance-admin@droboticflow.local", "fixture-value")]
|
|
|
|
|
|
@pytest.mark.parametrize("script", [
|
|
"holobrain-full-training-workflow-acceptance.sh",
|
|
"poc-operator-workflow-acceptance.sh",
|
|
"wilor-operator-workflow-acceptance.sh",
|
|
])
|
|
def test_shell_acceptance_requires_password_before_external_commands(script, tmp_path):
|
|
env = {**os.environ, "PATH": str(tmp_path)}
|
|
env.pop("DROBOTICFLOW_ACCEPTANCE_PASSWORD", None)
|
|
result = subprocess.run(["/bin/bash", str(ROOT / "scripts" / script)], env=env, capture_output=True, text=True)
|
|
assert result.returncode != 0
|
|
assert "DROBOTICFLOW_ACCEPTANCE_PASSWORD" in result.stderr
|