Ejemplo n.º 1
0
    def testAcceptFromRealEndpoint(self):
        username = '******'
        request = RequestFactory().post('/login', {
            'username': username,
            'password': '******'
        })
        server = self.TestWebServer(self.Always200Handler)
        server.start()
        auth = HttpBasicEndpointAuth(endpoint=server.getUrl())
        # Stub out user object retrieval & creation
        mockUserDao = flexmock(User.objects)
        mockUserDao.should_receive('get').and_raise(User.DoesNotExist())
        mockUserDao.should_call('create_user').with_args(username, '')\
            .at_least.once
        # Ditto for group object retrieval
        group = Group.objects.create(name='test-group')
        group.save()
        mockGroupDao = flexmock(Group.objects)
        mockGroupDao.should_receive('get').with_args(name='test-group')\
            .and_return(group).at_least.once
        mockGroupDao.should_receive('get').with_args(name='unknown-group')\
            .and_raise(Group.DoesNotExist)

        result = auth.authenticate(request)
        server.stop()
        self._checkResult(result, username)
 def testDenyFromRealEndpoint(self):
     request = RequestFactory().post('/login', { 'username': '******',
                                                'password': '******'})
     server = self.TestWebServer(self.Always403Handler)
     server.start()
     auth = HttpBasicEndpointAuth(endpoint=server.getUrl())
     result = auth.authenticate(request)
     server.stop()
     assert result == None
 def testDenyOnFailure(self):
     request = RequestFactory().post('/login', { 'username': '******',
                                                'password': '******'})
     # A "successful" mock OpenerDirector
     error403 = urllib2.HTTPError(self.mock_endpoint, 403, "Forbidden", {}, None)
     mockOpener = flexmock(urllib2.OpenerDirector())
     mockOpener.should_receive('open').and_raise(error403)
     auth = HttpBasicEndpointAuth(mockOpener,endpoint=self.mock_endpoint)
     eq_(auth.authenticate(request), None)
 def testDenyFromRealEndpoint(self):
     request = RequestFactory().post('/login', { 'username': '******',
                                                'password': '******'})
     server = self.TestWebServer(self.Always403Handler)
     server.start()
     auth = HttpBasicEndpointAuth(endpoint=server.getUrl())
     result = auth.authenticate(request)
     server.stop()
     assert result == None
 def testDenyOnFailure(self):
     request = RequestFactory().post('/login', { 'username': '******',
                                                'password': '******'})
     # A "successful" mock OpenerDirector
     error403 = urllib2.HTTPError(self.mock_endpoint, 403, "Forbidden", {}, None)
     mockOpener = flexmock(urllib2.OpenerDirector())
     mockOpener.should_receive('open').and_raise(error403)
     auth = HttpBasicEndpointAuth(mockOpener,endpoint=self.mock_endpoint)
     eq_(auth.authenticate(request), None)
 def testAllowOnSuccess(self):
     username = '******'
     request = RequestFactory().post('/login', { 'username': username,
                                                'password': '******'})
     # A "successful" mock OpenerDirector
     result = tempfile.TemporaryFile(mode='r')
     mockOpener = flexmock(urllib2.OpenerDirector(), open = result)
     # Stub out user object retrieval & creation
     mockUserDao = flexmock(User.objects)
     mockUserDao.should_receive('get').and_raise(User.DoesNotExist())
     mockUserDao.should_call('create_user').with_args(username, '')\
         .at_least.once
     auth = HttpBasicEndpointAuth(mockOpener,endpoint=self.mock_endpoint)
     self._checkResult(auth.authenticate(request),username)
 def testAllowOnSuccess(self):
     username = '******'
     request = RequestFactory().post('/login', { 'username': username,
                                                'password': '******'})
     # A "successful" mock OpenerDirector
     result = tempfile.TemporaryFile(mode='r')
     mockOpener = flexmock(urllib2.OpenerDirector(), open = result)
     # Stub out user object retrieval & creation
     mockUserDao = flexmock(User.objects)
     mockUserDao.should_receive('get').and_raise(User.DoesNotExist())
     mockUserDao.should_call('create_user').with_args(username, '')\
         .at_least.once
     auth = HttpBasicEndpointAuth(mockOpener,endpoint=self.mock_endpoint)
     self._checkResult(auth.authenticate(request),username)
Ejemplo n.º 8
0
 def testAcceptFromRealEndpoint(self):
     username = '******'
     request = RequestFactory().post('/login', { 'username': username,
                                                'password': '******'})
     server = self.TestWebServer(self.Always200Handler)
     server.start()
     auth = HttpBasicEndpointAuth(endpoint=server.getUrl())
     # Stub out user object retrieval & creation
     mockUserDao = flexmock(User.objects)
     mockUserDao.should_receive('get').and_raise(User.DoesNotExist())
     mockUserDao.should_call('create_user').with_args(username, '')\
         .at_least.once
     result = auth.authenticate(request)
     server.stop()
     self._checkResult(result, username)