543
544
545
class TestConnectedAccountsAcl:
546
- """Tests for ``account_type`` + per-user ACL surfacing on ``link()``
547
- and ``update_acl()``."""
546
+ """Tests for SHARED accounts surface on ``link()`` and
547
+ ``composio.experimental.update_acl()``."""
548
549
@pytest.fixture
550
def mock_client(self):
573
def connected_accounts(self, mock_client):
574
return ConnectedAccounts(client=mock_client)
575
576
- # -- link() with accountType + ACL forwarding ---------------------------
576
+ @pytest.fixture
577
+ def experimental(self, mock_client):
578
+ from composio.core.models.custom_tool import ExperimentalAPI
579
578
- def test_link_forwards_account_type_and_nested_acl(
579
- self, connected_accounts, mock_client
580
- ):
581
- connected_accounts.link(
582
- user_id="user_creator",
583
- auth_config_id="auth_config_123",
584
- account_type="SHARED",
585
- acl_config_for_shared={
586
- "allow_all_users": True,
587
- "not_allowed_user_ids": ["user_bob"],
588
- },
589
- )
580
+ return ExperimentalAPI(client=mock_client)
581
591
- call_kwargs = mock_client.link.create.call_args.kwargs
592
- assert call_kwargs["account_type"] == "SHARED"
593
- assert call_kwargs["acl_config_for_shared"] == {
594
- "allow_all_users": True,
595
- "not_allowed_user_ids": ["user_bob"],
596
- }
582
+ # -- link() forwards the experimental block -----------------------------
583
598
- def test_link_omits_acl_when_not_provided(self, connected_accounts, mock_client):
584
+ def test_link_forwards_experimental_block(self, connected_accounts, mock_client):
585
connected_accounts.link(
586
user_id="user_creator",
587
auth_config_id="auth_config_123",
602
- account_type="SHARED",
588
+ experimental={
589
+ "account_type": "SHARED",
590
+ "acl_config_for_shared": {
591
+ "allow_all_users": True,
592
+ "not_allowed_user_ids": ["user_bob"],
593
+ },
594
+ },
595
)
596
597
call_kwargs = mock_client.link.create.call_args.kwargs
606
- assert call_kwargs["account_type"] == "SHARED"
607
- assert call_kwargs["acl_config_for_shared"] is omit
598
+ assert call_kwargs["experimental"] == {
599
+ "account_type": "SHARED",
600
+ "acl_config_for_shared": {
601
+ "allow_all_users": True,
602
+ "not_allowed_user_ids": ["user_bob"],
603
+ },
604
+ }
605
609
- def test_link_forwards_only_provided_acl_fields(
606
+ def test_link_omits_experimental_when_not_provided(
607
self, connected_accounts, mock_client
608
):
609
connected_accounts.link(
610
user_id="user_creator",
611
auth_config_id="auth_config_123",
615
- account_type="SHARED",
616
- acl_config_for_shared={"allowed_user_ids": ["user_alice"]},
612
)
613
614
call_kwargs = mock_client.link.create.call_args.kwargs
620
- assert call_kwargs["acl_config_for_shared"] == {
621
- "allowed_user_ids": ["user_alice"]
622
- }
615
+ assert call_kwargs["experimental"] is omit
616
617
def test_link_preserves_explicit_empty_lists(self, connected_accounts, mock_client):
618
"""An empty list is meaningful (clear the allow/deny list)."""
619
connected_accounts.link(
620
user_id="user_creator",
621
auth_config_id="auth_config_123",
629
- account_type="SHARED",
630
- acl_config_for_shared={
631
- "allowed_user_ids": [],
632
- "not_allowed_user_ids": [],
622
+ experimental={
623
+ "account_type": "SHARED",
624
+ "acl_config_for_shared": {
625
+ "allowed_user_ids": [],
626
+ "not_allowed_user_ids": [],
627
+ },
628
},
629
)
630
631
call_kwargs = mock_client.link.create.call_args.kwargs
637
- assert call_kwargs["acl_config_for_shared"] == {
632
+ assert call_kwargs["experimental"]["acl_config_for_shared"] == {
633
"allowed_user_ids": [],
634
"not_allowed_user_ids": [],
635
}
645
connected_accounts.link(
646
user_id="user_creator",
647
auth_config_id="auth_config_123",
653
- account_type="PRIVATE",
654
- acl_config_for_shared={"allow_all_users": True},
648
+ experimental={
649
+ "account_type": "PRIVATE",
650
+ "acl_config_for_shared": {"allow_all_users": True},
651
+ },
652
)
653
654
def test_link_rethrows_non_acl_bad_request_errors(
664
user_id="user_creator", auth_config_id="auth_config_123"
665
)
666
670
- # -- update_acl() body construction + mapper ----------------------------
667
+ # -- experimental.update_acl() body construction + mapper ---------------
668
672
- def test_update_acl_serializes_nested_body(self, connected_accounts, mock_client):
669
+ def test_update_acl_serializes_nested_body(self, experimental, mock_client):
670
response = Mock()
671
response.id = "ca_abc"
672
response.status = "ACTIVE"
673
response.success = True
674
mock_client.connected_accounts.patch.return_value = response
675
679
- result = connected_accounts.update_acl(
676
+ result = experimental.update_acl(
677
"ca_abc",
678
allow_all_users=True,
679
not_allowed_user_ids=["user_bob"],
681
682
mock_client.connected_accounts.patch.assert_called_once_with(
683
"ca_abc",
687
- acl_config_for_shared={
688
- "allow_all_users": True,
689
- "not_allowed_user_ids": ["user_bob"],
684
+ experimental={
685
+ "acl_config_for_shared": {
686
+ "allow_all_users": True,
687
+ "not_allowed_user_ids": ["user_bob"],
688
+ }
689
},
690
+ alias=omit,
691
+ connection=omit,
692
)
693
assert result is response
694
694
- def test_update_acl_omits_absent_fields(self, connected_accounts, mock_client):
695
- connected_accounts.update_acl("ca_abc", allowed_user_ids=["user_alice"])
695
+ def test_update_acl_omits_absent_fields(self, experimental, mock_client):
696
+ experimental.update_acl("ca_abc", allowed_user_ids=["user_alice"])
697
698
mock_client.connected_accounts.patch.assert_called_once_with(
699
"ca_abc",
699
- acl_config_for_shared={"allowed_user_ids": ["user_alice"]},
700
+ experimental={
701
+ "acl_config_for_shared": {"allowed_user_ids": ["user_alice"]}
702
+ },
703
+ alias=omit,
704
+ connection=omit,
705
)
706
702
- def test_update_acl_preserves_empty_array(self, connected_accounts, mock_client):
703
- connected_accounts.update_acl("ca_abc", allowed_user_ids=[])
707
+ def test_update_acl_preserves_empty_array(self, experimental, mock_client):
708
+ experimental.update_acl("ca_abc", allowed_user_ids=[])
709
710
mock_client.connected_accounts.patch.assert_called_once_with(
711
"ca_abc",
707
- acl_config_for_shared={"allowed_user_ids": []},
712
+ experimental={"acl_config_for_shared": {"allowed_user_ids": []}},
713
+ alias=omit,
714
+ connection=omit,
715
)
716
710
- def test_update_acl_rejects_all_none(self, connected_accounts, mock_client):
717
+ def test_update_acl_rejects_all_none(self, experimental, mock_client):
718
with pytest.raises(exceptions.ValidationError):
712
- connected_accounts.update_acl("ca_abc")
719
+ experimental.update_acl("ca_abc")
720
mock_client.connected_accounts.patch.assert_not_called()
721
722
def test_update_acl_maps_acl_only_for_shared_to_typed_error(
716
- self, connected_accounts, mock_client
723
+ self, experimental, mock_client
724
):
725
mock_client.connected_accounts.patch.side_effect = _make_bad_request_error(
726
"acl_config_for_shared is only valid on SHARED connections."
727
)
728
729
with pytest.raises(exceptions.ComposioAclOnlyForSharedError):
723
- connected_accounts.update_acl("ca_abc", allow_all_users=True)
730
+ experimental.update_acl("ca_abc", allow_all_users=True)
731
732
def test_update_acl_rethrows_non_acl_bad_request_errors(
726
- self, connected_accounts, mock_client
733
+ self, experimental, mock_client
734
):
735
unrelated = _make_bad_request_error("some other 400")
736
mock_client.connected_accounts.patch.side_effect = unrelated
738
from composio_client import BadRequestError
739
740
with pytest.raises(BadRequestError):
734
- connected_accounts.update_acl("ca_abc", allow_all_users=True)
741
+ experimental.update_acl("ca_abc", allow_all_users=True)
742
+
743
+ def test_update_acl_requires_client(self):
744
+ from composio.core.models.custom_tool import ExperimentalAPI
745
+
746
+ with pytest.raises(exceptions.ValidationError):
747
+ ExperimentalAPI().update_acl("ca_abc", allow_all_users=True)
748
+
749
+ # -- list(account_type=...) — flat experimental filter -----------------
750
+
751
+ def test_list_forwards_account_type_filter(self, connected_accounts, mock_client):
752
+ connected_accounts.list(account_type="SHARED", user_ids=["user_creator"])
753
+ mock_client.connected_accounts.list.assert_called_once_with(
754
+ account_type="SHARED", user_ids=["user_creator"]
755
+ )
756
757
758
# SEC-339: initiate() must gate its DeprecationWarning on the response