Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

110 lines
3.9 KiB
Python

"""Tests for messaging bot config model extensions (identity_policy field)."""
from __future__ import annotations
import pytest
from pydantic import ValidationError
from integrations.config_models import (
DiscordBotConfig,
SlackBotConfig,
TelegramBotConfig,
)
from integrations.messaging_security import MessagingIdentityPolicy
class TestTelegramBotConfigBackCompat:
"""Ensure TelegramBotConfig remains backward-compatible."""
def test_minimal_config_still_works(self) -> None:
cfg = TelegramBotConfig(bot_token="123:ABC")
assert cfg.bot_token == "123:ABC"
assert cfg.default_chat_id is None
assert cfg.identity_policy is None
def test_config_with_identity_policy(self) -> None:
policy_data = {
"allowed_user_ids": ["111", "222"],
"inbound_enabled": True,
"require_dm_pairing": False,
}
cfg = TelegramBotConfig(
bot_token="123:ABC",
default_chat_id="-100123",
identity_policy=policy_data,
)
assert cfg.identity_policy is not None
# Validate the policy can be parsed
policy = MessagingIdentityPolicy.model_validate(cfg.identity_policy)
assert policy.allowed_user_ids == ["111", "222"]
assert policy.inbound_enabled is True
def test_config_serialization_roundtrip(self) -> None:
cfg = TelegramBotConfig(
bot_token="123:ABC",
identity_policy={"allowed_user_ids": ["u1"], "inbound_enabled": True},
)
data = cfg.model_dump(mode="json")
restored = TelegramBotConfig.model_validate(data)
assert restored.identity_policy == cfg.identity_policy
class TestDiscordBotConfigBackCompat:
"""Ensure DiscordBotConfig remains backward-compatible."""
def test_minimal_config_still_works(self) -> None:
cfg = DiscordBotConfig(bot_token="discord-token")
assert cfg.bot_token == "discord-token"
assert cfg.application_id == ""
assert cfg.public_key == ""
assert cfg.default_channel_id is None
assert cfg.identity_policy is None
def test_config_with_identity_policy(self) -> None:
cfg = DiscordBotConfig(
bot_token="discord-token",
application_id="app-123",
public_key="abcdef0123456789",
identity_policy={
"allowed_user_ids": ["discord_user_1"],
"rejection_behavior": "drop",
"inbound_enabled": True,
},
)
policy = MessagingIdentityPolicy.model_validate(cfg.identity_policy)
assert policy.allowed_user_ids == ["discord_user_1"]
assert policy.rejection_behavior.value == "drop"
class TestSlackBotConfig:
"""Tests for the new SlackBotConfig model."""
def test_minimal_config(self) -> None:
cfg = SlackBotConfig(bot_token="xoxb-test-token")
assert cfg.bot_token == "xoxb-test-token"
assert cfg.signing_secret == ""
assert cfg.app_id == ""
assert cfg.identity_policy is None
def test_full_config(self) -> None:
cfg = SlackBotConfig(
bot_token="xoxb-test-token",
signing_secret="secret123",
app_id="A01234",
identity_policy={
"allowed_user_ids": ["U001", "U002"],
"inbound_enabled": True,
},
)
assert cfg.signing_secret == "secret123"
policy = MessagingIdentityPolicy.model_validate(cfg.identity_policy)
assert "U001" in policy.allowed_user_ids
def test_empty_bot_token_rejected(self) -> None:
with pytest.raises(ValidationError, match="bot_token cannot be empty"):
SlackBotConfig(bot_token="")
def test_whitespace_bot_token_rejected(self) -> None:
with pytest.raises(ValidationError, match="bot_token cannot be empty"):
SlackBotConfig(bot_token=" ")