Example #1
0
    def test_getRolesForPrincipal(self):
        helper = self._makeOne()
        request = FakeRequest()

        helper._updateProperty('ip_roles', ['10.0.1.1/24:Manager,Member'])
        request.client_ip = '10.0.1.1'
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Member', 'Manager'])

        helper._updateProperty('ip_roles',
                               ['10.0.1.1/24:Manager', '10.0.1.1/16:Member'])
        request.client_ip = '10.0.255.0'
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Member'])
        request.client_ip = '10.0.1.1'
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Member', 'Manager'])

        # Check that only anonymous get roles if anon_only is checked.
        helper.anon_only = True
        request.client_ip = '10.0.1.1'
        user = SimpleUser('someone', 'something', [], [])
        self.assertEqual(helper.getRolesForPrincipal(user, request), [])

        user = SimpleUser('Anonymous User', 'something', [], [])
        self.assertEqual(helper.getRolesForPrincipal(user, request),
                         ['Member', 'Manager'])
        helper.anon_only = False

        # Test for invalid ip address
        helper._updateProperty('ip_roles',
                               ['10.0.1.1/24:Manager', '10.0.1.1/16:Member'])
        request.client_ip = '999.0.255.1234'
        self.assertEqual(helper.getRolesForPrincipal(None, request), [])
        request.client_ip = 'invalidip'
        self.assertEqual(helper.getRolesForPrincipal(None, request), [])
        request.client_ip = None
        self.assertEqual(helper.getRolesForPrincipal(None, request), [])

        # Test for invalid subnets
        request.client_ip = '10.0.255.0'
        helper._updateProperty('ip_roles', [])
        self.assertEqual(helper.getRolesForPrincipal(None, request), [])
        self.assertRaises(ValueError, helper._updateProperty, 'ip_roles', [
            '999.0.1.1/24:Manager', '10.0.1.1/16:', ':Manager',
            'invalidsubnet', None
        ])

        # 0 is a valid subnet, meaning everything.
        helper._updateProperty('ip_roles', ['16.16.16.16/0:Manager'])
        request.client_ip = '240.240.240.240'
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Manager'])
Example #2
0
    def authenticate(self, name, password, REQUEST):
        participants = self.getMeeting().getParticipants()
        subscriptions = participants.getSubscriptions()

        key = REQUEST.SESSION.get('nymt-current-key', None)
        if subscriptions._is_signup(key):
            role = participants._get_attendees()[key]['role']
            return SimpleUser('signup:' + key, '', (role, ), [])
        if subscriptions._is_pending_signup(key):
            role = 'Meeting Waiting List'
            return SimpleUser('signup:' + key, '', (role, ), [])
        else:
            return None
Example #3
0
 def test_example4(self):
     # login
     noSecurityManager()
     self.app.aq_chain[-1].id = 'testing'
     newSecurityManager(
         None,
         SimpleUser('Test User', '', ('Manager', ), []).__of__(self.app))
     try:
         # setup
         self.r.form['file'] = self.makeFileUpload(diskname='example4.mt')
         self.app.manage_addProduct['MailTemplates'].addMailTemplate(
             id='my_mt', mailhost='MailHost', REQUEST=self.r)
         self.app.my_mt.manage_addProperty('subject', 'Welcome to %s',
                                           'string')
         self.app.my_mt.manage_addProperty('mfrom', '*****@*****.**',
                                           'string')
         self.r.form['file'] = self.makeFileUpload(diskname='example4.py')
         self.app.manage_addProduct['PythonScripts'].manage_addPythonScript(
             id='send_mail', REQUEST=self.r)
         # set expected
         self.MailHost.setExpected(mfrom='*****@*****.**',
                                   mto=('*****@*****.**', ),
                                   filename='example4.txt')
         # test
         self.assertEqual(self.app.send_mail(), 'Mail Sent!')
         self.MailHost.checkSent()
     finally:
         # logout
         noSecurityManager()
         newSecurityManager(None, SystemUser)
Example #4
0
 def authenticate(self, name, password, request):
     invitation = self.invitations.get_current_invitation(request)
     if invitation is not None and invitation.enabled:
         return SimpleUser('invite:' + invitation.key, '',
                           ('InvitedReviewer', ), [])
     else:
         return None
Example #5
0
    def test_getRolesForPrincipal(self):
        helper = self._makeOne()
        request = FakeRequest()

        helper._updateProperty(
            'match_roles',
            [r'REMOTE_ADDR;127\.0\.0\.;Manager,Member;python:True'])
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Member', 'Manager'])

        helper._updateProperty('match_roles', [
            r'REMOTE_ADDR;127\.0\.0\.;Manager;python:True',
            r'REMOTE_ADDR;1\.28\.;Member;python:True',
            r'HTTP_USER_AGENT;Mozilla\/5\.0;Member,Manager;python:True'
        ])
        request.REMOTE_ADDR = '1.28.1.1'
        request.HTTP_USER_AGENT = 'Funny 1.0'
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Member'])
        request.REMOTE_ADDR = '10.0.1.49'
        request.HTTP_USER_AGENT = ORIGINAL_HTTP_USER_AGENT
        self.assertEqual(helper.getRolesForPrincipal(None, request),
                         ['Member', 'Manager'])

        # Check that only anonymous get roles if anon_only is checked.
        helper.anon_only = True
        request.REMOTE_ADDR = '10.0.1.1'
        user = SimpleUser('someone', 'something', [], [])
        self.assertEqual(helper.getRolesForPrincipal(user, request), [])

        user = SimpleUser('Anonymous User', 'something', [], [])
        self.assertEqual(helper.getRolesForPrincipal(user, request),
                         ['Member', 'Manager'])
        helper.anon_only = False

        # Test for invalid ip address
        helper._updateProperty('match_roles', [
            r'REMOTE_ADDR;10\.0\.0\.;Manager;python:True',
            r'REMOTE_ADDR;10\.1\.0\.;Manager;python:True'
        ])
        request.REMOTE_ADDR = 'invalidip'
        self.assertEqual(helper.getRolesForPrincipal(None, request), [])
        request.REMOTE_ADDR = ''
        self.assertEqual(helper.getRolesForPrincipal(None, request), [])
 def test_example2(self):
     # login
     noSecurityManager()
     self.app.aq_chain[-1].id = 'testing'
     newSecurityManager(
         None,
         SimpleUser('Test User','',('Manager',),[]).__of__(self.app)
         )
     try:
         # setup
         self.app.portal_membership = DummyMembershipTool()
         # set expected
         self.MailHost.setExpected(mfrom='*****@*****.**',
                                   mto='*****@*****.**',
                                   filename='example2.txt')
         # test
         self.ob.fake_skin.send_mails()
     finally:
         # logout
         noSecurityManager()
         newSecurityManager( None, SystemUser )
Example #7
0
 def __init__(self, id):
     SimpleUser.__init__(self, id, '', (), ())
Example #8
0
 def __init__(self, id):
     SimpleUser.__init__(self, id, '', (), ())
 def __init__(self, name, password, roles, domains):
     SimpleUser.__init__(self, name, password, roles, domains)
     self._created = time.time()
Example #10
0
 def __init__(self, name, password, roles, domains):
     SimpleUser.__init__(self, name, password, roles, domains)
     self._created = time.time()