Esempio n. 1
0
    def setUp(self):
        yield super(iSchedulePOST, self).setUp()

        serversDB = ServersDB()
        a_server = Server("A", "http://localhost:8008", thisServer=True)
        serversDB.addServer(a_server)
        b_server = Server("B", "http://localhost:8108", thisServer=False)
        serversDB.addServer(b_server)
        yield self.buildStoreAndDirectory(serversDB=serversDB)

        self.site.resource.putChild(
            "ischedule",
            IScheduleInboxResource(self.site.resource, self.storeUnderTest()))
        self.site.resource.putChild(
            "podding",
            IScheduleInboxResource(self.site.resource,
                                   self.storeUnderTest(),
                                   podding=True))

        yield self.populate()

        # iSchedule server
        IScheduleServers()
        server = IScheduleServerRecord("http://127.0.0.1")
        server.allow_from = True
        IScheduleServers._domainMap["example.org"] = server
        self.addCleanup(lambda: IScheduleServers._domainMap.pop("example.org")
                        )  #@UndefinedVariable
Esempio n. 2
0
    def setUp(self):
        yield super(MultiStoreConduitTest, self).setUp()

        # Store 1
        serversDB1 = ServersDB()
        server1a = Server("A", "http://127.0.0.1:8008", "A", True)
        serversDB1.addServer(server1a)
        server1b = Server("B", "http://127.0.0.1:8108", "B", False)
        serversDB1.addServer(server1b)
        yield self.buildStoreAndDirectory(serversDB=serversDB1)
        self.store.queryCacher = None  # Cannot use query caching
        self.store.conduit = self.makeConduit(self.store)

        # Store 2
        serversDB2 = ServersDB()
        server2a = Server("A", "http://127.0.0.1:8008", "A", False)
        serversDB2.addServer(server2a)
        server2b = Server("B", "http://127.0.0.1:8108", "B", True)
        serversDB2.addServer(server2b)

        self.store2 = yield self.buildStore(self.theStoreBuilder2)
        directory2 = buildTestDirectory(self.store2,
                                        self.mktemp(),
                                        serversDB=serversDB2)

        self.store2.setDirectoryService(directory2)
        self.store2.queryCacher = None  # Cannot use query caching
        self.store2.conduit = self.makeConduit(self.store2)

        FakeConduitRequest.addServerStore(server1a, self.store)
        FakeConduitRequest.addServerStore(server2b, self.store2)
Esempio n. 3
0
    def setUp(self):
        yield super(ExternalHome, self).setUp()

        serversDB = ServersDB()
        serversDB.addServer(Server("A", "http://127.0.0.1", "A", True))
        serversDB.addServer(Server("B", "http://127.0.0.2", "B", False))

        yield self.buildStoreAndDirectory(serversDB=serversDB)

        self.site.resource.putChild("conduit", ConduitResource(self.site.resource, self.storeUnderTest()))
Esempio n. 4
0
    def setUp(self):
        yield super(ConduitPOST, self).setUp()

        serversDB = ServersDB()
        self.thisServer = Server("A", "http://127.0.0.1", "A", True)
        serversDB.addServer(self.thisServer)
        yield self.buildStoreAndDirectory(serversDB=serversDB)

        self.site.resource.putChild("conduit", ConduitResource(self.site.resource, self.storeUnderTest()))

        yield self.populate()
Esempio n. 5
0
    def setUp(self):
        yield super(MultiStoreConduitTest, self).setUp()

        # Stores
        for i in range(self.numberOfStores):
            serversDB = ServersDB()
            for j in range(self.numberOfStores):
                letter = chr(ord("A") + j)
                port = 8008 + 100 * j
                server = Server(letter, "http://127.0.0.1:{}".format(port),
                                letter, j == i)
                serversDB.addServer(server)

            if i == 0:
                yield self.buildStoreAndDirectory(
                    serversDB=serversDB, storeBuilder=self.theStoreBuilders[i])
                self.theStores[i] = self.store
            else:
                self.theStores[i] = yield self.buildStore(
                    self.theStoreBuilders[i])
                directory = buildTestDirectory(self.theStores[i],
                                               self.mktemp(),
                                               serversDB=serversDB)
                self.theStores[i].setDirectoryService(directory)

            self.theStores[i].queryCacher = None  # Cannot use query caching
            self.theStores[i].conduit = self.makeConduit(self.theStores[i])

            FakeConduitRequest.addServerStore(
                serversDB.getServerById(chr(ord("A") + i)), self.theStores[i])
Esempio n. 6
0
    def setUp(self):
        yield super(ConduitPOST, self).setUp()

        serversDB = ServersDB()
        self.thisServer = Server("A", "http://127.0.0.1", "A", True)
        serversDB.addServer(self.thisServer)
        yield self.buildStoreAndDirectory(serversDB=serversDB)

        self.site.resource.putChild("conduit", ConduitResource(self.site.resource, self.storeUnderTest()))

        yield self.populate()
class ConduitPOST(CommonCommonTests, txweb2.dav.test.util.TestCase):
    class FakeConduit(PoddingConduit):
        def recv_fake(self, txn, j):
            return succeed({
                "result": "ok",
                "back2u": j["echo"],
                "more": "bits",
            })

    @inlineCallbacks
    def setUp(self):
        yield super(ConduitPOST, self).setUp()

        serversDB = ServersDB()
        self.thisServer = Server("A", "http://127.0.0.1", "A", True)
        serversDB.addServer(self.thisServer)
        yield self.buildStoreAndDirectory(serversDB=serversDB)

        self.site.resource.putChild(
            "conduit",
            ConduitResource(self.site.resource, self.storeUnderTest()))

        yield self.populate()

    @inlineCallbacks
    def populate(self):
        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
        self.notifierFactory.reset()

    @classproperty(cache=False)
    def requirements(cls):  #@NoSelf
        return {
            "user01": {
                "calendar_1": {},
                "inbox": {},
            },
            "user02": {
                "calendar_1": {},
                "inbox": {},
            },
            "user03": {
                "calendar_1": {},
                "inbox": {},
            },
        }

    @inlineCallbacks
    def test_receive_no_secret(self):
        """
        Cross-pod request fails when there is no shared secret header present.
        """

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(
                rawHeaders={"Content-Type": ("text/plain", )}),
            content="""Hello, World!
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.FORBIDDEN)

    @inlineCallbacks
    def test_receive_wrong_mime(self):
        """
        Cross-pod request fails when Content-Type header is wrong.
        """

        request = SimpleRequest(self.site,
                                "POST",
                                "/conduit",
                                headers=http_headers.Headers(
                                    rawHeaders={
                                        "Content-Type": ("text/plain", ),
                                        self.thisServer.secretHeader()[0]:
                                        self.thisServer.secretHeader()[1],
                                    }),
                                content="""Hello, World!
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)

    @inlineCallbacks
    def test_receive_invalid_json(self):
        """
        Cross-pod request fails when request data is not JSON.
        """

        request = SimpleRequest(self.site,
                                "POST",
                                "/conduit",
                                headers=http_headers.Headers(
                                    rawHeaders={
                                        "Content-Type": ("application/json", ),
                                        self.thisServer.secretHeader()[0]:
                                        self.thisServer.secretHeader()[1],
                                    }),
                                content="""Hello, World!
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)

    @inlineCallbacks
    def test_receive_bad_json(self):
        """
        Cross-pod request fails when JSON data does not have an "action".
        """

        request = SimpleRequest(self.site,
                                "POST",
                                "/conduit",
                                headers=http_headers.Headers(
                                    rawHeaders={
                                        "Content-Type": ("application/json", ),
                                        self.thisServer.secretHeader()[0]:
                                        self.thisServer.secretHeader()[1],
                                    }),
                                content="""
{
    "foo":"bar"
}
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)

    @inlineCallbacks
    def test_receive_ping(self):
        """
        Cross-pod request works with the "ping" action.
        """

        request = SimpleRequest(self.site,
                                "POST",
                                "/conduit",
                                headers=http_headers.Headers(
                                    rawHeaders={
                                        "Content-Type": ("application/json", ),
                                        self.thisServer.secretHeader()[0]:
                                        self.thisServer.secretHeader()[1],
                                    }),
                                content="""
{
    "action":"ping"
}
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.OK)
        data = (yield allDataFromStream(response.stream))
        j = json.loads(data)
        self.assertTrue("result" in j)
        self.assertEqual(j["result"], "ok")

    @inlineCallbacks
    def test_receive_fake_conduit_no_action(self):
        """
        Cross-pod request fails when conduit does not support the action.
        """

        store = self.storeUnderTest()
        self.patch(store, "conduit", self.FakeConduit(store))

        request = SimpleRequest(self.site,
                                "POST",
                                "/conduit",
                                headers=http_headers.Headers(
                                    rawHeaders={
                                        "Content-Type": ("application/json", ),
                                        self.thisServer.secretHeader()[0]:
                                        self.thisServer.secretHeader()[1],
                                    }),
                                content="""
{
    "action":"bogus",
    "echo":"bravo"
}
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)

    @inlineCallbacks
    def test_receive_fake_conduit(self):
        """
        Cross-pod request works when conduit does support the action.
        """

        store = self.storeUnderTest()
        self.patch(store, "conduit", self.FakeConduit(store))

        request = SimpleRequest(self.site,
                                "POST",
                                "/conduit",
                                headers=http_headers.Headers(
                                    rawHeaders={
                                        "Content-Type": ("application/json", ),
                                        self.thisServer.secretHeader()[0]:
                                        self.thisServer.secretHeader()[1],
                                    }),
                                content="""
{
    "action":"fake",
    "echo":"bravo"
}
""".replace("\n", "\r\n"))

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.OK)
        data = (yield allDataFromStream(response.stream))
        j = json.loads(data)
        self.assertTrue("result" in j)
        self.assertEqual(j["result"], "ok")
        self.assertTrue("back2u" in j)
        self.assertEqual(j["back2u"], "bravo")
        self.assertTrue("more" in j)
        self.assertEqual(j["more"], "bits")
Esempio n. 8
0
class ConduitPOST (CommonCommonTests, txweb2.dav.test.util.TestCase):

    class FakeConduit(PoddingConduit):

        def recv_fake(self, txn, j):
            return succeed({
                "result": "ok",
                "back2u": j["echo"],
                "more": "bits",
            })


    @inlineCallbacks
    def setUp(self):
        yield super(ConduitPOST, self).setUp()

        serversDB = ServersDB()
        self.thisServer = Server("A", "http://127.0.0.1", "A", True)
        serversDB.addServer(self.thisServer)
        yield self.buildStoreAndDirectory(serversDB=serversDB)

        self.site.resource.putChild("conduit", ConduitResource(self.site.resource, self.storeUnderTest()))

        yield self.populate()


    @inlineCallbacks
    def populate(self):
        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
        self.notifierFactory.reset()


    @classproperty(cache=False)
    def requirements(cls): #@NoSelf
        return {
        "user01": {
            "calendar_1": {
            },
            "inbox": {
            },
        },
        "user02": {
            "calendar_1": {
            },
            "inbox": {
            },
        },
        "user03": {
            "calendar_1": {
            },
            "inbox": {
            },
        },
    }


    @inlineCallbacks
    def test_receive_no_secret(self):
        """
        Cross-pod request fails when there is no shared secret header present.
        """

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("text/plain",)
            }),
            content="""Hello, World!
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.FORBIDDEN)


    @inlineCallbacks
    def test_receive_wrong_mime(self):
        """
        Cross-pod request fails when Content-Type header is wrong.
        """

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("text/plain",),
                self.thisServer.secretHeader()[0]: self.thisServer.secretHeader()[1],
            }),
            content="""Hello, World!
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)


    @inlineCallbacks
    def test_receive_invalid_json(self):
        """
        Cross-pod request fails when request data is not JSON.
        """

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("application/json",),
                self.thisServer.secretHeader()[0]: self.thisServer.secretHeader()[1],
            }),
            content="""Hello, World!
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)


    @inlineCallbacks
    def test_receive_bad_json(self):
        """
        Cross-pod request fails when JSON data does not have an "action".
        """

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("application/json",),
                self.thisServer.secretHeader()[0]: self.thisServer.secretHeader()[1],
            }),
            content="""
{
    "foo":"bar"
}
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)


    @inlineCallbacks
    def test_receive_ping(self):
        """
        Cross-pod request works with the "ping" action.
        """

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("application/json",),
                self.thisServer.secretHeader()[0]: self.thisServer.secretHeader()[1],
            }),
            content="""
{
    "action":"ping"
}
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.OK)
        data = (yield allDataFromStream(response.stream))
        j = json.loads(data)
        self.assertTrue("result" in j)
        self.assertEqual(j["result"], "ok")


    @inlineCallbacks
    def test_receive_fake_conduit_no_action(self):
        """
        Cross-pod request fails when conduit does not support the action.
        """

        store = self.storeUnderTest()
        self.patch(store, "conduit", self.FakeConduit(store))

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("application/json",),
                self.thisServer.secretHeader()[0]: self.thisServer.secretHeader()[1],
            }),
            content="""
{
    "action":"bogus",
    "echo":"bravo"
}
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.BAD_REQUEST)


    @inlineCallbacks
    def test_receive_fake_conduit(self):
        """
        Cross-pod request works when conduit does support the action.
        """

        store = self.storeUnderTest()
        self.patch(store, "conduit", self.FakeConduit(store))

        request = SimpleRequest(
            self.site,
            "POST",
            "/conduit",
            headers=http_headers.Headers(rawHeaders={
                "Content-Type": ("application/json",),
                self.thisServer.secretHeader()[0]: self.thisServer.secretHeader()[1],
            }),
            content="""
{
    "action":"fake",
    "echo":"bravo"
}
""".replace("\n", "\r\n")
        )

        response = (yield self.send(request))
        self.assertEqual(response.code, responsecode.OK)
        data = (yield allDataFromStream(response.stream))
        j = json.loads(data)
        self.assertTrue("result" in j)
        self.assertEqual(j["result"], "ok")
        self.assertTrue("back2u" in j)
        self.assertEqual(j["back2u"], "bravo")
        self.assertTrue("more" in j)
        self.assertEqual(j["more"], "bits")