Esempio n. 1
0
    def testSetUp(self):
        client = getUtility(IAdminClient)
        if client._state == 'disconnected':
            zr = getUtility(IZopeReactor)
            zr.reactor.callFromThread(client.connect)

        wait_for_client_state(client, 'authenticated')
        setupXMPPEnvironment(client,
            member_jids=[JID('test_user_1_@localhost')],
            member_passwords={JID('test_user_1_@localhost'): 'secret'})
        wait_on_client_deferreds(client)
Esempio n. 2
0
 def setUpPloneSite(self, portal):
     # Install into Plone site using portal_setup
     applyProfile(portal, 'jarn.xmpp.core:default')
     registry = getUtility(IRegistry)
     registry['jarn.xmpp.adminJID'] = 'admin@localhost'
     registry['jarn.xmpp.pubsubJID'] = 'pubsub.localhost'
     registry['jarn.xmpp.conferenceJID'] = 'conference.localhost'
     registry['jarn.xmpp.xmppDomain'] = 'localhost'
     setupAdminClient(None, None)
     client = getUtility(IAdminClient)
     wait_for_client_state(client, 'authenticated')
Esempio n. 3
0
 def setUpPloneSite(self, portal):
     # Install into Plone site using portal_setup
     applyProfile(portal, 'jarn.xmpp.core:default')
     registry = getUtility(IRegistry)
     registry['jarn.xmpp.adminJID'] = 'admin@localhost'
     registry['jarn.xmpp.pubsubJID'] = 'pubsub.localhost'
     registry['jarn.xmpp.conferenceJID'] = 'conference.localhost'
     registry['jarn.xmpp.xmppDomain'] = 'localhost'
     setupAdminClient(None, None)
     client = getUtility(IAdminClient)
     wait_for_client_state(client, 'authenticated')
Esempio n. 4
0
    def testSetUp(self):
        client = getUtility(IAdminClient)
        if client._state == 'disconnected':
            zr = getUtility(IZopeReactor)
            zr.reactor.callFromThread(client.connect)

        wait_for_client_state(client, 'authenticated')
        _setupXMPPEnvironment(
            client,
            member_jids=[JID('test_user_1_@localhost')],
            member_passwords={JID('test_user_1_@localhost'): 'secret'})
        wait_on_client_deferreds(client)
Esempio n. 5
0
def setup_xmpp(context):
    # Setup existing users
    from jarn.xmpp.core.interfaces import IAdminClient
    from jarn.xmpp.core.subscribers.startup import setupAdminClient
    from jarn.xmpp.core.utils.setup import setupXMPPEnvironment
    from jarn.xmpp.twisted.testing import wait_for_client_state
    from jarn.xmpp.twisted.testing import wait_on_client_deferreds
    setupAdminClient(None, None)

    client = getUtility(IAdminClient)
    wait_for_client_state(client, 'authenticated')
    wait_on_client_deferreds(client)
    setupXMPPEnvironment(context)
    wait_on_client_deferreds(client)
Esempio n. 6
0
def setup_xmpp(context):
    # Setup existing users
    from jarn.xmpp.core.interfaces import IAdminClient
    from jarn.xmpp.core.subscribers.startup import setupAdminClient
    from jarn.xmpp.core.utils.setup import setupXMPPEnvironment
    from jarn.xmpp.twisted.testing import wait_for_client_state
    from jarn.xmpp.twisted.testing import wait_on_client_deferreds
    setupAdminClient(None, None)

    client = getUtility(IAdminClient)
    wait_for_client_state(client, 'authenticated')
    wait_on_client_deferreds(client)
    setupXMPPEnvironment(context)
    wait_on_client_deferreds(client)
    def test_component_connection(self):

        component = XMPPComponent('localhost',
                                  5347,
                                  'example.localhost',
                                  'secret')
        self.assertTrue(wait_for_client_state(component, 'authenticated'))
        self.assertEqual(component.jid, JID('example.localhost'))
    def test_client(self):

        def getVersion(xmlstream):
            iq = IQ(xmlstream, 'get')
            iq.addElement((NS_VERSION, 'query'))
            d = iq.send('localhost')
            return d

        client = XMPPClient(JID('admin@localhost'), 'admin')
        self.assertTrue(wait_for_client_state(client, 'authenticated'))
        d = getVersion(client.xmlstream)
        self.assertTrue(wait_on_deferred(d))
        self.assertEqual(d.result['type'], 'result')
        client.disconnect()
Esempio n. 9
0
 def testTearDown(self):
     client = getUtility(IAdminClient)
     client.disconnect()
     wait_for_client_state(client, 'disconnected')
Esempio n. 10
0
 def testTearDown(self):
     client = getUtility(IAdminClient)
     client.disconnect()
     wait_for_client_state(client, 'disconnected')
Esempio n. 11
0
def create_site_admin(app, args):
    # Display all messages on stderr
    logger.setLevel(logging.INFO)
    logger.handlers[0].setLevel(logging.INFO)

    existing = app.objectValues('Plone Site')
    site = existing and existing[0] or None
    if site is None:
        logger.error("No Plone site found in the database.")
        sys.exit(1)

    _, site = _setup(app, site)

    parser = OptionParser()
    parser.add_option('-l', '--login', default=None,
        help='Site admin login.')
    parser.add_option('-e', '--email', default=None,
        help='Site admin email.')
    parser.add_option('-n', '--fullname', default=None,
        help='Site admin full name.')
    parser.add_option('-a', '--hostname', default=None,
        help='Intranett site host name.')
    (options, args) = parser.parse_args(args=args)

    # User info
    login = options.login
    email = options.email
    fullname = options.fullname
    hostname = options.hostname

    if not login:
        logger.error("Missing option --login.")
        sys.exit(1)
    if not email:
        logger.error("Missing option --email.")
        sys.exit(1)
    if not fullname:
        logger.error("Missing option --fullname.")
        sys.exit(1)
    if not hostname:
        logger.error("Missing option --hostname.")
        sys.exit(1)

    # Add and notify the site admin user
    mt = aq_get(site, 'portal_membership')
    pt = aq_get(site, 'portal_password_reset')
    rt = aq_get(site, 'portal_registration')

    if mt.getMemberById(login) is not None:
        logger.error("User %s already exists." % login)
        sys.exit(1)

    from intranett.policy.browser.activation import ActivationMail

    # Get the hostname
    if not hostname.endswith('.intranett.no'):
        hostname += '.intranett.no'

    mt.addMember(login, rt.generatePassword(),
        ['Member', 'Site Administrator'], [])
    member = mt.getMemberById(login) # getMemberByLogin???
    member.setMemberProperties(dict(email=email, fullname=fullname))
    reset = pt.requestReset(login)

    # change ownership of all content to new user and update dates to now
    from DateTime import DateTime
    user = member.getUser()
    userid = user.getId()
    now = DateTime()

    catalog = aq_get(site, 'portal_catalog')
    brains = catalog.unrestrictedSearchResults()
    for brain in brains:
        if brain.portal_type.startswith('Member'):
            continue
        obj = brain.getObject()
        obj.setCreators(userid)
        obj.changeOwnership(user)
        obj.setCreationDate(now)
        obj.setEffectiveDate(now)
        obj.setModificationDate(now)
        obj.reindexObject(idxs=None)

    # Mail him
    mail_text = ActivationMail(site, site.REQUEST)(member=member,
        reset=reset, email=email, fullname=fullname, hostname=hostname)
    if isinstance(mail_text, unicode):
        mail_text = mail_text.encode('utf-8')
    mail_text = mail_text.replace('http://foo/Plone/passwordreset/',
                                  'https://%s/activate/' % hostname)

    message_obj = message_from_string(mail_text.strip())
    subject = message_obj['Subject']
    m_to = message_obj['To']
    m_from = message_obj['From']

    host = aq_get(site, 'MailHost')
    host.send(mail_text, m_to, m_from, subject=subject,
              charset='utf-8', immediate=True)

    from jarn.xmpp.core.interfaces import IAdminClient
    from jarn.xmpp.core.subscribers.startup import setupAdminClient
    from jarn.xmpp.core.subscribers.user_management import onUserCreation
    from jarn.xmpp.twisted.testing import wait_for_client_state
    from jarn.xmpp.twisted.testing import wait_on_deferred
    from jarn.xmpp.twisted.testing import wait_on_client_deferreds

    setupAdminClient(None, None)
    client = getUtility(IAdminClient)
    wait_for_client_state(client, 'authenticated')
    wait_on_client_deferreds(client)


    class FakeEvent(object):
        pass

    ev = FakeEvent()
    ev.principal = user
    d = onUserCreation(ev)
    wait_on_deferred(d)

    transaction.get().note('Added site admin user %r.' % login)
    transaction.get().commit()
    logger.info('Added site admin user %r.', login)
Esempio n. 12
0
def create_site_admin(app, args):
    # Display all messages on stderr
    logger.setLevel(logging.INFO)
    logger.handlers[0].setLevel(logging.INFO)

    existing = app.objectValues('Plone Site')
    site = existing and existing[0] or None
    if site is None:
        logger.error("No Plone site found in the database.")
        sys.exit(1)

    _, site = _setup(app, site)

    parser = OptionParser()
    parser.add_option('-l', '--login', default=None,
        help='Site admin login.')
    parser.add_option('-e', '--email', default=None,
        help='Site admin email.')
    parser.add_option('-n', '--fullname', default=None,
        help='Site admin full name.')
    parser.add_option('-a', '--hostname', default=None,
        help='Intranett site host name.')
    (options, args) = parser.parse_args(args=args)

    # User info
    login = options.login
    email = options.email
    fullname = options.fullname
    hostname = options.hostname

    if not login:
        logger.error("Missing option --login.")
        sys.exit(1)
    if not email:
        logger.error("Missing option --email.")
        sys.exit(1)
    if not fullname:
        logger.error("Missing option --fullname.")
        sys.exit(1)
    if not hostname:
        logger.error("Missing option --hostname.")
        sys.exit(1)

    # Add and notify the site admin user
    mt = aq_get(site, 'portal_membership')
    pt = aq_get(site, 'portal_password_reset')
    rt = aq_get(site, 'portal_registration')

    if mt.getMemberById(login) is not None:
        logger.error("User %s already exists." % login)
        sys.exit(1)

    from intranett.policy.browser.activation import ActivationMail

    # Get the hostname
    if not hostname.endswith('.intranett.no'):
        hostname += '.intranett.no'

    mt.addMember(login, rt.generatePassword(),
        ['Member', 'Site Administrator'], [])
    member = mt.getMemberById(login) # getMemberByLogin???
    member.setMemberProperties(dict(email=email, fullname=fullname))
    reset = pt.requestReset(login)

    # change ownership of all content to new user and update dates to now
    from intranett.policy.config import PERSONAL_FOLDER_ID
    from DateTime import DateTime
    user = member.getUser()
    userid = user.getId()
    now = DateTime()

    catalog = aq_get(site, 'portal_catalog')
    brains = catalog.unrestrictedSearchResults()
    for brain in brains:
        if brain.portal_type.startswith('Member'):
            continue
        if brain.getId == PERSONAL_FOLDER_ID:
            continue
        obj = brain.getObject()
        obj.setCreators(userid)
        obj.changeOwnership(user)
        obj.setCreationDate(now)
        obj.setEffectiveDate(now)
        obj.setModificationDate(now)
        obj.reindexObject(idxs=None)

    # Mail him
    mail_text = ActivationMail(site, site.REQUEST)(member=member,
        reset=reset, email=email, fullname=fullname, hostname=hostname)
    if isinstance(mail_text, unicode):
        mail_text = mail_text.encode('utf-8')
    mail_text = mail_text.replace('http://foo/Plone/passwordreset/',
                                  'https://%s/activate/' % hostname)

    message_obj = message_from_string(mail_text.strip())
    subject = message_obj['Subject']
    m_to = message_obj['To']
    m_from = message_obj['From']

    host = aq_get(site, 'MailHost')
    host.send(mail_text, m_to, m_from, subject=subject,
              charset='utf-8', immediate=True)

    from jarn.xmpp.core.interfaces import IAdminClient
    from jarn.xmpp.core.subscribers.startup import setupAdminClient
    from jarn.xmpp.core.subscribers.user_management import onUserCreation
    from jarn.xmpp.twisted.testing import wait_for_client_state
    from jarn.xmpp.twisted.testing import wait_on_deferred
    from jarn.xmpp.twisted.testing import wait_on_client_deferreds

    setupAdminClient(None, None)
    client = getUtility(IAdminClient)
    wait_for_client_state(client, 'authenticated')
    wait_on_client_deferreds(client)


    class FakeEvent(object):
        pass

    ev = FakeEvent()
    ev.principal = user
    d = onUserCreation(ev)
    wait_on_deferred(d)

    transaction.get().note('Added site admin user %r.' % login)
    transaction.get().commit()
    logger.info('Added site admin user %r.', login)