def build_two_test_agents(volttron_instance): """Returns two agents for testing authorization The first agent is the "RPC callee." The second agent is the unauthorized "RPC caller." """ agent1 = volttron_instance.build_agent(identity='agent1') gevent.sleep(1) agent2 = volttron_instance.build_agent(identity='agent2') gevent.sleep(1) agent1.foo = lambda x: x agent1.foo.__name__ = 'foo' agent1.vip.rpc.export(method=agent1.foo) agent1.vip.rpc.allow(agent1.foo, 'can_call_foo') try: yield agent1, agent2 finally: agent1.core.stop() agent2.core.stop() auth_file = AuthFile(os.path.join(volttron_instance.volttron_home, 'auth.json')) allow_entries = auth_file.read_allow_entries() auth_file.remove_by_indices(list(range(3, len(allow_entries)))) # TODO if we have to wait for auth propagation anyways why do we create new agents for each test case # we should just update capabilities, at least we will save on agent creation and tear down time gevent.sleep(1)
def build_agents_with_capability_args(volttron_instance): """Returns two agents for testing authorization where one agent has rpc call with capability and argument restriction The first agent is the "RPC callee." The second agent is the unauthorized "RPC caller." """ # Can't call the fixture directly so build our own agent here. agent1 = volttron_instance.build_agent(identity='agent1') gevent.sleep(1) agent2 = volttron_instance.build_agent(identity='agent2') gevent.sleep(1) agent1.foo = lambda x: x agent1.foo.__name__ = 'foo' agent2.boo = lambda x, y: (x, y) agent2.boo.__name__ = 'boo' agent1.vip.rpc.export(method=agent1.foo) agent2.vip.rpc.export(method=agent2.boo) agent1.vip.rpc.allow(agent1.foo, 'can_call_foo') agent2.vip.rpc.allow(agent2.boo, 'can_call_boo') yield agent1, agent2 agent1.core.stop() agent2.core.stop() auth_file = AuthFile(os.path.join(volttron_instance.volttron_home, 'auth.json')) allow_entries = auth_file.read_allow_entries() auth_file.remove_by_indices(list(range(3, len(allow_entries)))) gevent.sleep(0.5)
def build_two_test_agents(volttron_instance): """Returns two agents for testing authorization The first agent is the "RPC callee." The second agent is the unauthorized "RPC caller." """ agent1 = build_agent(volttron_instance, 'agent1') agent2 = build_agent(volttron_instance, 'agent2') gevent.sleep(1) agent1.foo = lambda x: x agent1.foo.__name__ = 'foo' agent1.vip.rpc.export(method=agent1.foo) agent1.vip.rpc.allow(agent1.foo, 'can_call_foo') yield agent1, agent2 agent1.core.stop() agent2.core.stop() auth_file = AuthFile( os.path.join(volttron_instance.volttron_home, 'auth.json')) allow_entries = auth_file.read_allow_entries() auth_file.remove_by_indices(list(range(3, len(allow_entries)))) gevent.sleep(0.5)
def auth_file_platform_tuple(): with get_test_volttron_home('zmq') as vhome: auth_file = AuthFile(os.path.join(vhome, 'auth.json')) gevent.sleep(0.5) yield auth_file allow_entries = auth_file.read_allow_entries() auth_file.remove_by_indices(list(range(3, len(allow_entries)))) gevent.sleep(0.5)
def auth_file_platform_tuple(volttron_instance): platform = volttron_instance auth_file = AuthFile(os.path.join(platform.volttron_home, 'auth.json')) gevent.sleep(0.5) yield auth_file, platform allow_entries = auth_file.read_allow_entries() auth_file.remove_by_indices(list(range(3, len(allow_entries)))) gevent.sleep(0.5)