Exemplo n.º 1
0
    def test_addUser(self):
        page = Add.addPage(self.avatarId, self.db, self.testSambaDomain)
        page.addSlash = False
        testutil.renderPage(page)
        submitData = {
            'userSettings.uid': u'test01',
            'userPermissions.employeeType': True,
            'userPermissions.tumsUser': None,
            'userSettings.userPassword': "******",
            'mailSettings.vacation': None,
            'mailSettings.mailAlternateAddress0': None,
            'userPermissions.tumsAdmin': True,
            'mailSettings.mailForwardingAddress0': None,
            'userPermissions.accountStatus': True,
            'userPermissions.employeeType': True,
            'userSettings.sn': u'test',
            'userSettings.givenName': u'test01',
            'userAccess.ftpEnabled': False,
            'userAccess.ftpGlobal': False,
            'userAccess.vpnEnabled': False,
            'userPermissions.copyto': '',
        }
        for i in range(10):
            submitData['mailSettings.mailAlternateAddress%s' % i] = None
            submitData['mailSettings.mailForwardingAddress%s' % i] = None
        form = None

        U = page.submitForm(self.aContext, form, submitData)

        U.addCallback(self._urlTest, page, '/Users/Edit/thusa.co.za/test01')
        return U
Exemplo n.º 2
0
    def test_editUser(self):
        page = Users.editPage(self.avatarId, self.db, 'root',
                              self.testSambaDomain)
        page.addSlash = False
        testutil.renderPage(page)

        submitData = {
            'userSettings.uid': u'root',
            'userPermissions.employeeType': True,
            'userPermissions.tumsUser': None,
            'userSettings.userPassword': None,
            'mailSettings.vacation': None,
            'mailSettings.mailAlternateAddress0': None,
            'userPermissions.tumsAdmin': True,
            'mailSettings.mailForwardingAddress0': None,
            'userPermissions.accountStatus': True,
            'userPermissions.employeeType': True,
            'userSettings.sn': u'root',
            'homeDirectory': ['/home/colin'],
            'userSettings.givenName': u'rooter'
        }
        form = None

        for i in range(10):
            submitData['mailSettings.mailAlternateAddress%s' % i] = None
            submitData['mailSettings.mailForwardingAddress%s' % i] = None

        U = page.submitForm(self.aContext, form, submitData)
        self.assertIn("/Users/Edit/thusa.co.za/root/Completed",
                      self.flattenUrl(U, page))

        return U
Exemplo n.º 3
0
    def test_deleteUser(self):
        page = Users.deletePage(self.avatarId, self.db)
        page.addSlash = False
        testutil.renderPage(page)
        U = page.locateChild(None, ['thusa.co.za', 'test01'])
        self.assertIn("/Users", self.flattenUrl(U[0], page))

        return U
Exemplo n.º 4
0
    def test_addGroup(self):
        page = Users.addGroups(self.avatarId, self.testSambaDomain,
                               self.testUser, self.db)
        page.addSlash = False
        testutil.renderPage(page)
        submitData = {'groupName': 'test01'}
        U = page.submitForm(self.aContext, None, submitData)
        self.assertIn('/Users/Groups/thusa.co.za/test',
                      self.flattenUrl(U, page))

        return U
Exemplo n.º 5
0
    def test_onlyUsernameSpecified(self):
        """
        Test that if the user only supplies the local part of their username
        then the password resetter will still find the correct user.
        """
        hostname = self.site.hostname.encode('ascii')

        def handleRequest(username, url):
            handleRequest.attempt = self.reset.newAttemptForUser(username)
            handleRequest.username = username

        class Request(FakeRequest):
            method = 'POST'

            def __init__(self, *a, **kw):
                FakeRequest.__init__(self, *a, **kw)
                self.args = {'username': ['joe'],
                             'email': ['']}
                self.received_headers['host'] = hostname

        self.reset.handleRequestForUser = handleRequest
        d = renderPage(self.reset, reqFactory=Request)
        d.addCallback(lambda _: self.assertEquals(handleRequest.username,
                                                  'joe@' + hostname))
        return d
Exemplo n.º 6
0
    def test_rssGeneration(self):
        """
        Test that the RSS generator produces the desired output.
        """
        BLOG_TITLE = u'Awesome! A Blog.'
        BLOG_DESC = u'A blog about stuff.'
        POST_TITLE = u'awesome title'
        POST_BODY = u'<div>body</div>'
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=BLOG_TITLE, body=BLOG_DESC,
                          author=self.BLOG_AUTHOR,
                          children=[MockBlurb(flavor=hyperblurb.FLAVOR.BLOG_POST,
                                              title=POST_TITLE,
                                              body=POST_BODY,
                                              author=self.BLOG_AUTHOR,
                                              children=[])])
        def checkData(rssData):
            def assertPathEqual(path, data):
                self.assertEqual(evaluateXPath(path, rssData)[0], data)
            assertPathEqual('/rss/channel/title/text()', BLOG_TITLE)
            assertPathEqual('/rss/channel/link/text()', self.BLOG_URL)
            assertPathEqual('/rss/channel/description/text()', BLOG_DESC)

            self.assertEqual(
                len(evaluateXPath('/rss/channel/item', rssData)), 1)
            assertPathEqual('/rss/channel/item[1]/title/text()', POST_TITLE)
            assertPathEqual('/rss/channel/item[1]/description/text()',
                            POST_BODY)
        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Exemplo n.º 7
0
    def test_urls(self):
        """
        Check that rendering URLs via L{renderPage} actually works.
        """
        class _URLPage(Page):
            docFactory = stan(root.child('foo'))

        def _checkForUrl(result):
            return self.assertEqual('http://localhost/foo', result)

        return renderPage(_URLPage()).addCallback(_checkForUrl)
    def test_urls(self):
        """
        Check that rendering URLs via L{renderPage} actually works.
        """
        class _URLPage(Page):
            docFactory = stan(
                root.child('foo'))

        def _checkForUrl(result):
            return self.assertEquals('http://localhost/foo', result)

        return renderPage(_URLPage()).addCallback(_checkForUrl)
Exemplo n.º 9
0
 def test_pageRenders(self):
     pages = [
         Log, Stats, Mail, MailQueue, Samba, Reports, Tools, VPN, Netdrive,
         Network, Backup, Dhcp, Computers, Squid, Firewall,
         PermissionDenied, GroupMatrix, Traffic, Exim, Overview,
         NetworkStats, System, Graph, MySQL, Existat, About, Menu, Ppp
     ]
     renderInstances = []
     for pname in pages:
         page = pname.Page(self.avatarId, self.db)
         page.addSlash = False
         renderInstances.append(testutil.renderPage(page))
     return renderInstances
Exemplo n.º 10
0
    def test_emptyRSS(self):
        """
        Test that RSS generation works properly for blurbs with no children.
        """
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=u"blog title", body=u"blog desc",
                          children=[], author=self.BLOG_AUTHOR)

        def checkData(rssData):
            rssDoc = minidom.parseString(rssData)
            self.assertEqual(evaluateXPath('/rss/channel/item', rssData), [])
        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Exemplo n.º 11
0
 def test_unsupportedBrowserPage(self):
     """
     Test that unsupported browsers get told they're unsupported.
     """
     ctx = WovenContext()
     page = athena.LivePage()
     req = FakeRequest()
     req.received_headers[
         'user-agent'] = "Mozilla/4.0 (compatible; MSIE 2.0; Windows NT 5.1)"
     ctx.remember(req, IRequest)
     d = renderPage(page, reqFactory=lambda: req)
     d.addCallback(self.assertEqual,
                   flat.flatten(page.unsupportedBrowserLoader))
     return d
Exemplo n.º 12
0
 def test_pages(self):
     pages = [
         About,
         Apache,
         Backup,
         Computers,
         DNS,
         Dhcp,
         Diagnose,
         Exim,
         Existat,
         FileBrowser,
         Firewall,
         Graph,
         GroupMatrix,
         InterfaceStats,
         Log,
         Mail,
         Menu,
         MySQL,
         Netdrive,
         Network,
         NetworkStats,
         Overview,
         PermissionDenied,
         Policy,
         Ppp,
         Profiles,
         Qos,
         Reports,
         Routing,
         Samba,
         SambaConfig,
         Sar,
         Shorewall,
         Squid,
         System,
         MailQueue,
         Tools,
         Traffic,
         VPN,
         Xen,
     ]
     renderInstances = []
     for pname in pages:
         page = pname.Page(self.avatarId, self.db)
         page.addSlash = False
         renderInstances.append(testutil.renderPage(page))
     return defer.DeferredList(renderInstances)
Exemplo n.º 13
0
    def test_emptyRSS(self):
        """
        Test that RSS generation works properly for blurbs with no children.
        """
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=u"blog title",
                          body=u"blog desc",
                          children=[],
                          author=self.BLOG_AUTHOR)

        def checkData(rssData):
            rssDoc = minidom.parseString(rssData)
            self.assertEqual(evaluateXPath('/rss/channel/item', rssData), [])

        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Exemplo n.º 14
0
    def test_peopleMessageListRendering(self):
        mlister = MessageLister(store=self.substore)
        installOn(mlister, self.substore)

        p = Person(store=self.substore, name=u'Bob')

        EmailAddress(store=self.substore, person=p, address=u'bob@internet')

        for i in xrange(5):
            testMessageFactory(
                store=self.substore, subject=unicode(str(i)),
                receivedWhen=Time(), spam=False, sender=u'bob@internet')


        self.assertEqual(len(list(mlister.mostRecentMessages(p))), 5)
        return renderPage(
            rend.Page(docFactory=loaders.stan(MessageList(mlister, p))))
Exemplo n.º 15
0
    def test_peopleMessageListRendering(self):
        mlister = MessageLister(store=self.substore)
        installOn(mlister, self.substore)

        p = Person(store=self.substore, name=u'Bob')

        EmailAddress(store=self.substore, person=p, address=u'bob@internet')

        for i in xrange(5):
            testMessageFactory(store=self.substore,
                               subject=unicode(str(i)),
                               receivedWhen=Time(),
                               spam=False,
                               sender=u'bob@internet')

        self.assertEqual(len(list(mlister.mostRecentMessages(p))), 5)
        return renderPage(
            rend.Page(docFactory=loaders.stan(MessageList(mlister, p))))
Exemplo n.º 16
0
 def test_redirectToSettingsWhenLoggedIn(self):
     """
     When a user is already logged in, navigating to /resetPassword should
     redirect to the settings page, since the user can change their password
     from there.
     """
     self.assertNotIdentical(self.userStore.parent, None) # sanity check
     prefPage = ixmantissa.IPreferenceAggregator(self.userStore)
     urlPath = ixmantissa.IWebTranslator(self.userStore).linkTo(prefPage.storeID)
     request = FakeRequest(headers={"host": "example.com"})
     app = IResource(self.userStore)
     rsc = IResource(app.locateChild(request, ("resetPassword",))[0])
     d = renderPage(rsc, reqFactory=lambda : request)
     def rendered(result):
         self.assertEquals(
             'http://example.com' + urlPath,
             request.redirected_to)
     d.addCallback(rendered)
     return d
Exemplo n.º 17
0
    def test_nothingSpecified(self):
        """
        Submitting an empty form should redirect the user back to the form.
        """
        self.reset.handleRequestForUser = lambda *args: self.fail(args)

        _request = FakeRequest(
            headers={'host': 'example.org'},
            uri='/resetPassword',
            currentSegments=['resetPassword'],
            args={'username': [''], 'email': ['']})
        _request.method = 'POST'

        d = renderPage(self.reset, reqFactory=lambda: _request)
        def rendered(_):
            self.assertEquals(_request.redirected_to,
                              'http://example.org/resetPassword')
        d.addCallback(rendered)
        return d
Exemplo n.º 18
0
    def test_elementPreprocessors(self):
        """
        Make sure that LiveElements have their preprocessors applied to their
        document.
        """
        preprocessed = []

        tag = tags.span
        element = athena.LiveElement(docFactory=loaders.stan(tag))
        page = athena.LivePage(docFactory=loaders.stan(element))
        element.preprocessors = [preprocessed.append]
        element.setFragmentParent(page)
        renderDeferred = renderPage(page)

        def rendered(result):
            page.action_close(None)
            self.assertEquals(preprocessed, [[tag]])

        renderDeferred.addCallback(rendered)
        return renderDeferred
Exemplo n.º 19
0
    def test_emailAddressSpecified(self):
        """
        If an email address and no username is specified, then the password
        resetter should still find the correct user.
        """
        requests = []
        def handleRequest(username, url):
            requests.append((username, url))

        class Request(FakeRequest):
            method = 'POST'
            def __init__(self, *a, **k):
                FakeRequest.__init__(self, *a, **k)
                self.args = {'username': [''],
                             'email': ['*****@*****.**']}

        self.reset.handleRequestForUser = handleRequest
        d = renderPage(self.reset, reqFactory=Request)
        def completedRequest():
            self.assertEqual(len(requests), 1)
            self.assertEqual(requests[0][0], '*****@*****.**')
        d.addCallback(lambda ign: completedRequest())
        return d
Exemplo n.º 20
0
    def specifyBogusEmail(self, bogusEmail):
        """
        If an email address (which is not present in the system) and no
        username is specified, then the password reset should still ask the
        user to check their email.  No distinction is provided to discourage
        "oafish attempts at hacking", as duncan poetically put it.
        """
        requests = []
        def handleRequest(username, url):
            requests.append((username, url))

        class Request(FakeRequest):
            method = 'POST'
            def __init__(self, *a, **k):
                FakeRequest.__init__(self, *a, **k)
                self.args = {'username': [''],
                             'email': [bogusEmail]}

        self.reset.handleRequestForUser = handleRequest
        d = renderPage(self.reset, reqFactory=Request)
        def completedRequest():
            self.assertEqual(len(requests), 0)
        d.addCallback(lambda ign: completedRequest())
        return d
Exemplo n.º 21
0
    def test_rssGeneration(self):
        """
        Test that the RSS generator produces the desired output.
        """
        BLOG_TITLE = u'Awesome! A Blog.'
        BLOG_DESC = u'A blog about stuff.'
        POST_TITLE = u'awesome title'
        POST_BODY = u'<div>body</div>'
        blurb = MockBlurb(flavor=hyperblurb.FLAVOR.BLOG,
                          title=BLOG_TITLE,
                          body=BLOG_DESC,
                          author=self.BLOG_AUTHOR,
                          children=[
                              MockBlurb(flavor=hyperblurb.FLAVOR.BLOG_POST,
                                        title=POST_TITLE,
                                        body=POST_BODY,
                                        author=self.BLOG_AUTHOR,
                                        children=[])
                          ])

        def checkData(rssData):
            def assertPathEqual(path, data):
                self.assertEqual(evaluateXPath(path, rssData)[0], data)

            assertPathEqual('/rss/channel/title/text()', BLOG_TITLE)
            assertPathEqual('/rss/channel/link/text()', self.BLOG_URL)
            assertPathEqual('/rss/channel/description/text()', BLOG_DESC)

            self.assertEqual(len(evaluateXPath('/rss/channel/item', rssData)),
                             1)
            assertPathEqual('/rss/channel/item[1]/title/text()', POST_TITLE)
            assertPathEqual('/rss/channel/item[1]/description/text()',
                            POST_BODY)

        rssView = hyperbola_view.blurbViewDispatcher(blurb).child_rss(None)
        return renderPage(rssView).addCallback(checkData)
Exemplo n.º 22
0
    def test_editUser(self):
        page = Edit.editPage(self.avatarId, self.db, 'root',
                             self.testSambaDomain)
        page.addSlash = False
        testutil.renderPage(page)

        submitData = {
            'userPermissions.employeeType':
            False,
            'uid': ['root'],
            'objectClass': [
                'inetOrgPerson', 'sambaSamAccount', 'posixAccount',
                'shadowAccount'
            ],
            'userAccess.ftpGlobal':
            False,
            'uidNumber': ['0'],
            'sambaAcctFlags': ['[U]'],
            'sambaPrimaryGroupSID':
            ['S-1-5-21-3603831541-3007533189-3710063549-512'],
            'mailSettings.mailAlternateAddress7':
            None,
            'mailSettings.mailAlternateAddress6':
            None,
            'mailSettings.mailAlternateAddress5':
            None,
            'mailSettings.mailAlternateAddress4':
            None,
            'userSettings.givenName':
            u'root',
            'mailSettings.mailAlternateAddress2':
            None,
            'mailSettings.mailAlternateAddress1':
            None,
            'mailSettings.mailAlternateAddress0':
            None,
            'sambaLogoffTime': ['2147483647'],
            'mailSettings.vacation':
            None,
            'sambaPwdCanChange': ['0'],
            'cn': ['root root'],
            'mailSettings.mailForwardingAddress6':
            None,
            'employeeType': ['tumsAdmin'],
            'mailSettings.mailForwardingAddress5':
            None,
            'userPassword': ['{SHA}+GW1NiOxIf007lQmx5Llwzr4wic='],
            'sambaPwdMustChange': ['1209377073'],
            'userPermissions.tumsReports':
            False,
            'mailSettings.mailAlternateAddress9':
            None,
            'sambaLogonTime': ['0'],
            'sambaLMPassword': ['AC804745EE68EBEA1AA818381E4E281B'],
            'mailSettings.mailAlternateAddress8':
            None,
            'userAccess.ftpEnabled':
            False,
            'mailSettings.mailForwardingAddress3':
            None,
            'mailSettings.mailForwardingAddress2':
            None,
            'mailSettings.mailForwardingAddress1':
            None,
            'mailSettings.mailForwardingAddress0':
            None,
            'mailSettings.mailForwardingAddress7':
            None,
            'userPermissions.tumsAdmin':
            True,
            'userSettings.uid':
            u'root',
            'mailSettings.mailForwardingAddress4':
            None,
            'loginShell': ['/bin/false'],
            'mailSettings.mailForwardingAddress9':
            None,
            'mailSettings.mailForwardingAddress8':
            None,
            'gidNumber': ['0'],
            'sambaKickoffTime': ['2147483647'],
            'sambaPwdLastSet': ['1205489073'],
            'sambaNTPassword': ['3008C87294511142799DCA1191E69A0F'],
            'userPermissions.tumsUser':
            None,
            'userSettings.sn':
            u'root',
            'userAccess.vpnEnabled':
            False,
            'userPermissions.accountStatus':
            False,
            'userSettings.userPassword':
            None,
            'mailSettings.vacen':
            False,
            'sambaSID': ['S-1-5-21-3603831541-3007533189-3710063549-500'],
            'gecos': ['Netbios Domain Administrator'],
            'sn': ['root'],
            'homeDirectory': ['/home/root'],
            'mailSettings.mailAlternateAddress3':
            None,
            'givenName': ['root'],
            'userPermissions.copyto':
            None
        }
        form = None

        for i in range(10):
            submitData['mailSettings.mailAlternateAddress%s' % i] = None
            submitData['mailSettings.mailForwardingAddress%s' % i] = None

        U = page.submitForm(self.aContext, form, submitData)
        self.assertIn("/Users/Edit/thusa.co.za/root/Completed",
                      self.flattenUrl(U, page))

        return U
Exemplo n.º 23
0
 def test_Users(self):
     page = Users.Page(self.avatarId, self.db)
     page.addSlash = False
     return testutil.renderPage(page)
Exemplo n.º 24
0
 def test_render(self):
     page = Exim.Page(self.avatarId, self.db)
     page.addSlash = False
     return testutil.renderPage(page)
Exemplo n.º 25
0
 def test_editGroupMembership(self):
     page = Users.editGroups(self.avatarId, self.db, self.testUser,
                             self.testSambaDomain)
     page.addSlash = False
     return testutil.renderPage(page)