Esempio n. 1
0
    def test_start_router_component(self):
        """
        Starting a class-based router component works.
        """
        r = router.RouterController(config=self.config, reactor=reactor)

        # Open the transport
        transport = FakeWAMPTransport(r)
        r.onOpen(transport)

        realm_config = {
            u"name":
            u"realm1",
            u'roles': [{
                u'name':
                u'anonymous',
                u'permissions': [{
                    u'subscribe': True,
                    u'register': True,
                    u'call': True,
                    u'uri': u'*',
                    u'publish': True
                }]
            }]
        }

        r.start_router_realm(u"realm1", realm_config)

        permissions = RouterPermissions(u'', True, True, True, True, True)
        routera = r._router_factory.get(u'realm1')
        routera.add_role(
            RouterRoleStaticAuth(router,
                                 'anonymous',
                                 default_permissions=permissions))

        component_config = {
            u"type": u"class",
            u"classname":
            u"crossbar.worker.test.examples.goodclass.AppSession",
            u"realm": u"realm1"
        }

        r.start_router_component("newcomponent", component_config)

        self.assertEqual(len(r.get_router_components()), 1)
        self.assertEqual(r.get_router_components()[0]["id"], "newcomponent")

        self.assertEqual(len(_), 1)
        _.pop()  # clear this global state
Esempio n. 2
0
    def setUp(self):
        """
        Setup router and router session factories.
        """

        # create a router factory
        self.router_factory = RouterFactory()

        # start a realm
        self.router_factory.start_realm(RouterRealm(None, {u'name': u'realm1'}))

        # allow everything
        permissions = RouterPermissions('', True, True, True, True, True)
        router = self.router_factory.get(u'realm1')
        router.add_role(RouterRoleStaticAuth(router, None, default_permissions=permissions))

        # create a router session factory
        self.session_factory = RouterSessionFactory(self.router_factory)