mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-13 11:22:14 +02:00
fix: scope workflow run to org rather than user
This commit is contained in:
parent
4989bab1e9
commit
43737c67dc
29 changed files with 218 additions and 158 deletions
|
|
@ -94,7 +94,6 @@ async def test_agent_stream_reads_call_metadata_from_start_message():
|
|||
websocket,
|
||||
organization_id=44,
|
||||
workflow_id=101,
|
||||
user_id=202,
|
||||
workflow_run_id=303,
|
||||
params={},
|
||||
)
|
||||
|
|
@ -267,7 +266,6 @@ async def test_agent_stream_handshake_timeout_closes_socket(monkeypatch):
|
|||
websocket,
|
||||
organization_id=1,
|
||||
workflow_id=2,
|
||||
user_id=3,
|
||||
workflow_run_id=4,
|
||||
params={},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ async def test_plivo_xml_route_accepts_valid_signature_with_extra_query_param():
|
|||
provider = _provider()
|
||||
query = {
|
||||
"workflow_id": 7,
|
||||
"user_id": 8,
|
||||
"workflow_run_id": 123,
|
||||
"campaign_id": 42,
|
||||
"organization_id": 11,
|
||||
|
|
@ -138,14 +137,13 @@ async def test_plivo_xml_route_accepts_valid_signature_with_extra_query_param():
|
|||
|
||||
response = await handle_plivo_xml_webhook(
|
||||
workflow_id=7,
|
||||
user_id=8,
|
||||
workflow_run_id=123,
|
||||
organization_id=11,
|
||||
request=request,
|
||||
)
|
||||
|
||||
assert response.body == b"<Response/>"
|
||||
get_webhook_response.assert_awaited_once_with(7, 8, 123)
|
||||
get_webhook_response.assert_awaited_once_with(7, 11, 123)
|
||||
db_client.update_workflow_run.assert_awaited_once()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,6 @@ async def test_twiml_route_accepts_valid_signature_with_extra_query_param():
|
|||
provider = _provider()
|
||||
query = {
|
||||
"workflow_id": 7,
|
||||
"user_id": 8,
|
||||
"workflow_run_id": 123,
|
||||
"campaign_id": 42,
|
||||
"organization_id": 11,
|
||||
|
|
@ -149,14 +148,13 @@ async def test_twiml_route_accepts_valid_signature_with_extra_query_param():
|
|||
|
||||
response = await handle_twiml_webhook(
|
||||
workflow_id=7,
|
||||
user_id=8,
|
||||
workflow_run_id=123,
|
||||
organization_id=11,
|
||||
request=request,
|
||||
)
|
||||
|
||||
assert response.body == b"<Response/>"
|
||||
get_webhook_response.assert_awaited_once_with(7, 8, 123)
|
||||
get_webhook_response.assert_awaited_once_with(7, 11, 123)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -166,7 +164,6 @@ async def test_twiml_route_rejects_missing_signature():
|
|||
path="/api/v1/telephony/twiml",
|
||||
query={
|
||||
"workflow_id": 7,
|
||||
"user_id": 8,
|
||||
"workflow_run_id": 123,
|
||||
"organization_id": 11,
|
||||
},
|
||||
|
|
@ -188,7 +185,6 @@ async def test_twiml_route_rejects_missing_signature():
|
|||
with pytest.raises(HTTPException) as exc_info:
|
||||
await handle_twiml_webhook(
|
||||
workflow_id=7,
|
||||
user_id=8,
|
||||
workflow_run_id=123,
|
||||
organization_id=11,
|
||||
request=request,
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ async def test_telephony_entrypoint_counts_call_during_setup(monkeypatch):
|
|||
provider_name="twilio",
|
||||
workflow_id=1,
|
||||
workflow_run_id=44,
|
||||
user_id=7,
|
||||
organization_id=7,
|
||||
call_id="call-1",
|
||||
transport_kwargs={},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ def test_trigger_route_executes_as_workflow_owner():
|
|||
|
||||
initiate_kwargs = provider.initiate_call.await_args.kwargs
|
||||
assert initiate_kwargs["workflow_id"] == workflow.id
|
||||
assert initiate_kwargs["user_id"] == workflow.user_id
|
||||
# The media websocket URL is keyed on the org, not the workflow owner.
|
||||
assert initiate_kwargs["organization_id"] == workflow.organization_id
|
||||
|
||||
|
||||
def test_workflow_uuid_route_uses_scoped_lookup_and_shared_execution():
|
||||
|
|
|
|||
|
|
@ -123,8 +123,12 @@ def test_initiate_call_executes_as_workflow_owner_for_shared_org_workflow():
|
|||
|
||||
initiate_kwargs = provider.initiate_call.await_args.kwargs
|
||||
assert initiate_kwargs["workflow_id"] == workflow.id
|
||||
assert initiate_kwargs["user_id"] == workflow.user_id
|
||||
assert "user_id=99" in initiate_kwargs["webhook_url"]
|
||||
# The media websocket URL is keyed on the org, not the workflow owner.
|
||||
assert initiate_kwargs["organization_id"] == workflow.organization_id
|
||||
webhook_url = initiate_kwargs["webhook_url"]
|
||||
assert f"organization_id={workflow.organization_id}" in webhook_url
|
||||
# The answer URL carries no workflow owner: nothing downstream scopes on it.
|
||||
assert "user_id=" not in webhook_url
|
||||
mock_db.get_user_configurations.assert_not_called()
|
||||
|
||||
|
||||
|
|
@ -380,11 +384,13 @@ async def test_smallwebrtc_run_reaching_telephony_websocket_closes_without_runni
|
|||
):
|
||||
mock_concurrency.unregister_active_call = AsyncMock()
|
||||
mock_db.get_workflow_run = AsyncMock(return_value=workflow_run)
|
||||
mock_db.get_workflow_by_id = AsyncMock(return_value=workflow)
|
||||
mock_db.get_workflow = AsyncMock(return_value=workflow)
|
||||
mock_db.update_workflow_run = AsyncMock()
|
||||
|
||||
await _handle_telephony_websocket(websocket, 33, 99, 501)
|
||||
await _handle_telephony_websocket(websocket, 33, 11, 501)
|
||||
|
||||
mock_db.get_workflow_run.assert_awaited_once_with(501, organization_id=11)
|
||||
mock_db.get_workflow.assert_awaited_once_with(33, organization_id=11)
|
||||
websocket.close.assert_awaited_once_with(
|
||||
code=4400,
|
||||
reason=(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue