示例#1
0
 def installed(self):
     """
     Share this item once installed.
     """
     shareid = u'test'
     sharing.getEveryoneRole(self.store).shareItem(self, shareID=shareid)
     websharing.addDefaultShareID(self.store, shareid, 0)
示例#2
0
    def test_defaultUserSharedResource(self):
        """
        The resource for the default share can be accessed by an
        unauthenticated user.
        """
        # Make a user to own the shared item.
        username = u'alice'
        aliceAccount = self.login.addAccount(username,
                                             self.domain,
                                             u'password',
                                             internal=True)
        aliceStore = aliceAccount.avatars.open()

        # Make an item to share.
        sharedContent = u'content owned by alice and shared to everyone'
        shareID = getEveryoneRole(aliceStore).shareItem(
            DummyItem(store=aliceStore, markup=sharedContent)).shareID

        # Make it the default share.
        addDefaultShareID(aliceStore, shareID, 0)

        # Get it.
        page = getWithSession(self.factory, 3,
                              '/users/%s' % (username.encode('ascii'), ),
                              {'host': self.domain.encode('ascii')})

        def rendered(request):
            self.assertIn(sharedContent.encode('ascii'), request.accumulator)

        page.addCallback(rendered)
        return page
示例#3
0
    def test_defaultUserSharedResource(self):
        """
        The resource for the default share can be accessed by an authenticated
        user.
        """
        # Make an item and share it.
        sharedContent = u"content owned by alice and shared to everyone"
        shareID = (
            getEveryoneRole(self.userStore).shareItem(DummyItem(store=self.userStore, markup=sharedContent)).shareID
        )

        # Make it the default.
        addDefaultShareID(self.userStore, shareID, 0)

        # Get it.
        page = getWithSession(
            self.factory,
            1,
            "/users/%s" % (self.username.encode("ascii"),),
            {"host": self.domain.encode("ascii")},
            self.cookies,
        )

        def rendered(request):
            self.assertIn(sharedContent, request.accumulator)

        page.addCallback(rendered)
        return page
示例#4
0
    def test_defaultUserSharedResource(self):
        """
        The resource for the default share can be accessed by an
        unauthenticated user.
        """
        # Make a user to own the shared item.
        username = u"alice"
        aliceAccount = self.login.addAccount(username, self.domain, u"password", internal=True)
        aliceStore = aliceAccount.avatars.open()

        # Make an item to share.
        sharedContent = u"content owned by alice and shared to everyone"
        shareID = getEveryoneRole(aliceStore).shareItem(DummyItem(store=aliceStore, markup=sharedContent)).shareID

        # Make it the default share.
        addDefaultShareID(aliceStore, shareID, 0)

        # Get it.
        page = getWithSession(
            self.factory, 3, "/users/%s" % (username.encode("ascii"),), {"host": self.domain.encode("ascii")}
        )

        def rendered(request):
            self.assertIn(sharedContent.encode("ascii"), request.accumulator)

        page.addCallback(rendered)
        return page
示例#5
0
 def test_findShareID(self):
     """
     Verify that L{websharing.getDefaultShareID} reads the share ID set by a
     L{websharing.addDefaultShareID} call.
     """
     store = Store()
     websharing.addDefaultShareID(store, u'share id', 0)
     self.assertEqual(websharing.getDefaultShareID(store), u'share id')
示例#6
0
 def test_findShareID(self):
     """
     Verify that L{websharing.getDefaultShareID} reads the share ID set by a
     L{websharing.addDefaultShareID} call.
     """
     store = Store()
     websharing.addDefaultShareID(store, u'share id', 0)
     self.assertEqual(websharing.getDefaultShareID(store), u'share id')
示例#7
0
 def installed(self):
     """
     Share this item once installed.
     """
     shareid = u'test'
     sharing.getEveryoneRole(self.store
                     ).shareItem(self,
                       shareID=shareid)
     websharing.addDefaultShareID(self.store, shareid, 0)
示例#8
0
 def test_createsItem(self):
     """
     Verify that L{websharing.addDefaultShareID} creates a
     L{websharing._DefaultShareID} item.
     """
     store = Store()
     websharing.addDefaultShareID(store, u'share id', -22)
     item = store.findUnique(websharing._DefaultShareID)
     self.assertEqual(item.shareID, u'share id')
     self.assertEqual(item.priority, -22)
示例#9
0
 def test_createsItem(self):
     """
     Verify that L{websharing.addDefaultShareID} creates a
     L{websharing._DefaultShareID} item.
     """
     store = Store()
     websharing.addDefaultShareID(store, u'share id', -22)
     item = store.findUnique(websharing._DefaultShareID)
     self.assertEqual(item.shareID, u'share id')
     self.assertEqual(item.priority, -22)
示例#10
0
 def test_defaultShareIDInteractionNoMatch(self):
     """
     Verify that L{websharing.linkTo} explicitly includes a share ID in the
     URL if the ID of the share it is passed doesn't match the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     shareable = Shareable(store=self.s)
     sharing.shareItem(Shareable(store=self.s), shareID=u'not-the-share-id')
     share = sharing.getShare(
         self.s, sharing.getEveryoneRole(self.s), u'not-the-share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/not-the-share-id')
示例#11
0
 def test_defaultShareIDInteractionNoMatch(self):
     """
     Verify that L{websharing.linkTo} explicitly includes a share ID in the
     URL if the ID of the share it is passed doesn't match the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     shareable = Shareable(store=self.s)
     sharing.shareItem(Shareable(store=self.s), shareID=u'not-the-share-id')
     share = sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                              u'not-the-share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/not-the-share-id')
示例#12
0
 def test_emptySegmentWithDefault(self):
     """
     Verify that we get the right resource and segments from
     L{websharing.SharingIndex.locateChild} if there is a default share ID
     and we access the empty child.
     """
     websharing.addDefaultShareID(self.userStore, u'ashare', 0)
     sharingIndex = self.makeSharingIndex(None)
     SEGMENTS = ('', 'foo', 'bar')
     (res, segments) = sharingIndex.locateChild(None, SEGMENTS)
     self.assertEqual(res.wrappedFragment.showMagicValue(), self.magicValue)
     self.assertEqual(segments, SEGMENTS[1:])
示例#13
0
 def test_emptySegmentWithDefault(self):
     """
     Verify that we get the right resource and segments from
     L{websharing.SharingIndex.locateChild} if there is a default share ID
     and we access the empty child.
     """
     websharing.addDefaultShareID(self.userStore, u'ashare', 0)
     sharingIndex = self.makeSharingIndex(None)
     SEGMENTS = ('', 'foo', 'bar')
     (res, segments) = sharingIndex.locateChild(None, SEGMENTS)
     self.assertEqual(
         res.wrappedFragment.showMagicValue(), self.magicValue)
     self.assertEqual(segments, SEGMENTS[1:])
示例#14
0
 def test_defaultShareIDInteractionMatching(self):
     """
     Verify that L{websharing.linkTo} does not explicitly include a share
     ID in the URL if the ID of the share it is passed matches the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     sharing.shareItem(Shareable(store=self.s), shareID=u'share-id')
     share = sharing.getShare(
         self.s, sharing.getEveryoneRole(self.s), u'share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/')
     # and if we call child()
     self.assertEqual(str(url.child('child')), '/users/right/share-id/child')
示例#15
0
    def test_authenticatedUserVirtualHostDefaultShare(self):
        """
        A request by an authenticated user for I{/} on a subdomain of of the
        website's is responded to in the same way as the same request made by
        an anonymous user.
        """
        # Make an account as which to authenticate.
        username = u'bob'
        bobAccount = self.login.addAccount(username,
                                           self.domain,
                                           u'password',
                                           internal=True)
        bobStore = bobAccount.avatars.open()

        # Make a product that includes PrivateApplication.  This supposes that
        # viewing user-subdomain virtual hosting is the responsibility of
        # PrivateApplication.
        web = Product(store=self.store, types=[qual(PrivateApplication)])
        # Give it to Bob.
        web.installProductOn(bobStore)

        # Make something the default share.
        addDefaultShareID(self.userStore, self.share.shareID, 0)

        # Log in through the web as Bob.
        cookies = {}
        login = getWithSession(
            self.factory, 3, '/__login__?username=%s@%s&password=%s' %
            (username.encode('ascii'), self.domain.encode('ascii'),
             'password'), {'host': self.domain.encode('ascii')})

        def loggedIn(request):
            # Get the share page as the authenticated user.
            return getResource(
                self.factory,
                '/',
                headers={'host': self.virtualHost.encode('ascii')},
                cookies=request.cookies)

        login.addCallback(loggedIn)

        def rendered(request):
            # Make sure we're really authenticated.
            self.assertIn(username.encode('ascii'), request.accumulator)
            # Make sure the shared thing is there.
            self.assertIn(self.sharedContent.encode('ascii'),
                          request.accumulator)

        login.addCallback(rendered)
        return login
示例#16
0
 def test_defaultShareIDInteractionMatching(self):
     """
     Verify that L{websharing.linkTo} does not explicitly include a share
     ID in the URL if the ID of the share it is passed matches the default.
     """
     websharing.addDefaultShareID(self.s, u'share-id', 0)
     sharing.shareItem(Shareable(store=self.s), shareID=u'share-id')
     share = sharing.getShare(self.s, sharing.getEveryoneRole(self.s),
                              u'share-id')
     url = websharing.linkTo(share)
     self.assertEqual(str(url), '/users/right/')
     # and if we call child()
     self.assertEqual(str(url.child('child')),
                      '/users/right/share-id/child')
示例#17
0
    def test_authenticatedUserVirtualHostDefaultShare(self):
        """
        A request by an authenticated user for I{/} on a subdomain of of the
        website's is responded to in the same way as the same request made by
        an anonymous user.
        """
        # Make an account as which to authenticate.
        username = u"bob"
        bobAccount = self.login.addAccount(username, self.domain, u"password", internal=True)
        bobStore = bobAccount.avatars.open()

        # Make a product that includes PrivateApplication.  This supposes that
        # viewing user-subdomain virtual hosting is the responsibility of
        # PrivateApplication.
        web = Product(store=self.store, types=[qual(PrivateApplication)])
        # Give it to Bob.
        web.installProductOn(bobStore)

        # Make something the default share.
        addDefaultShareID(self.userStore, self.share.shareID, 0)

        # Log in through the web as Bob.
        cookies = {}
        login = getWithSession(
            self.factory,
            3,
            "/__login__?username=%s@%s&password=%s"
            % (username.encode("ascii"), self.domain.encode("ascii"), "password"),
            {"host": self.domain.encode("ascii")},
        )

        def loggedIn(request):
            # Get the share page as the authenticated user.
            return getResource(
                self.factory, "/", headers={"host": self.virtualHost.encode("ascii")}, cookies=request.cookies
            )

        login.addCallback(loggedIn)

        def rendered(request):
            # Make sure we're really authenticated.
            self.assertIn(username.encode("ascii"), request.accumulator)
            # Make sure the shared thing is there.
            self.assertIn(self.sharedContent.encode("ascii"), request.accumulator)

        login.addCallback(rendered)
        return login
示例#18
0
    def test_validShareID(self):
        """
        Verify that we get the right resource and segments from
        L{websharing.SharingIndex.locateChild} if we access a valid share ID.
        """
        websharing.addDefaultShareID(self.userStore, u'', 0)

        otherShareable = Shareable(store=self.userStore,
                                   magicValue=self.magicValue + 3)

        for _shareID in [u'foo', u'f\xf6\xf6']:
            otherShare = sharing.shareItem(otherShareable, shareID=_shareID)
            sharingIndex = self.makeSharingIndex(None)
            SEGMENTS = (_shareID.encode('utf-8'), 'bar')
            (res, segments) = sharingIndex.locateChild(None, SEGMENTS)
            self.assertEqual(res.wrappedFragment.showMagicValue(),
                             self.magicValue + 3)
            self.assertEqual(segments, SEGMENTS[1:])
示例#19
0
    def test_validShareID(self):
        """
        Verify that we get the right resource and segments from
        L{websharing.SharingIndex.locateChild} if we access a valid share ID.
        """
        websharing.addDefaultShareID(self.userStore, u'', 0)

        otherShareable = Shareable(store=self.userStore,
                                   magicValue=self.magicValue + 3)

        for _shareID in [u'foo', u'f\xf6\xf6']:
            otherShare = sharing.shareItem(otherShareable, shareID=_shareID)
            sharingIndex = self.makeSharingIndex(None)
            SEGMENTS = (_shareID.encode('utf-8'), 'bar')
            (res, segments) = sharingIndex.locateChild(None, SEGMENTS)
            self.assertEqual(
                res.wrappedFragment.showMagicValue(), self.magicValue + 3)
            self.assertEqual(segments, SEGMENTS[1:])
示例#20
0
    def test_defaultUserSharedResource(self):
        """
        The resource for the default share can be accessed by an authenticated
        user.
        """
        # Make an item and share it.
        sharedContent = u'content owned by alice and shared to everyone'
        shareID = getEveryoneRole(self.userStore).shareItem(
            DummyItem(store=self.userStore, markup=sharedContent)).shareID

        # Make it the default.
        addDefaultShareID(self.userStore, shareID, 0)

        # Get it.
        page = getWithSession(self.factory, 1,
                              '/users/%s' % (self.username.encode('ascii'), ),
                              {'host': self.domain.encode('ascii')},
                              self.cookies)

        def rendered(request):
            self.assertIn(sharedContent, request.accumulator)

        page.addCallback(rendered)
        return page
示例#21
0
 def test_findHighestPriorityShareID(self):
     """
     Verify that L{websharing.getDefaultShareID} reads the highest-priority
     share ID set by L{websharing.addDefaultShareID}.
     """
     store = Store()
     websharing.addDefaultShareID(store, u'share id!', 24)
     websharing.addDefaultShareID(store, u'share id', 25)
     websharing.addDefaultShareID(store, u'share id.', -1)
     self.assertEqual(websharing.getDefaultShareID(store), u'share id')
示例#22
0
 def test_findHighestPriorityShareID(self):
     """
     Verify that L{websharing.getDefaultShareID} reads the highest-priority
     share ID set by L{websharing.addDefaultShareID}.
     """
     store = Store()
     websharing.addDefaultShareID(store, u'share id!', 24)
     websharing.addDefaultShareID(store, u'share id',  25)
     websharing.addDefaultShareID(store, u'share id.', -1)
     self.assertEqual(websharing.getDefaultShareID(store), u'share id')