Ejemplo n.º 1
0
    def test_create_authevent_sms_with_captcha(self):
        self.ae.auth_method = 'sms'
        self.ae.auth_method_config = test_data.authmethod_config_sms_default
        self.ae.save()
        c = JClient()


        # add census without problem with captcha
        c.authenticate(0, test_data.admin)
        response = c.census(self.aeid, test_data.census_sms_default)
        self.assertEqual(response.status_code, 200)
        response = c.get('/api/auth-event/%d/census/' % self.aeid, {})
        self.assertEqual(response.status_code, 200)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(r['object_list']), 4)

        # add register: without captcha
        response = c.register(self.aeid, test_data.register_email_fields)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['message'], 'Incorrect data')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_sms_default
        data.update({'tlf': '999999999'})

        # add register: bad code
        data.update({'captcha_code': '', 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['message'], 'Incorrect data')

        # add register # TODO fix
        data.update({'captcha_code': captcha.code, 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 200)

        # add register: repeat captcha invalid
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['message'], 'Incorrect data')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_sms_fields
        data.update({'tlf': '888888888'})

        # add register: bad challenge
        data.update({'captcha_code': captcha.code, 'captcha': ''})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['message'], 'Incorrect data')
Ejemplo n.º 2
0
    def test_create_authevent_sms_with_captcha(self):
        self.ae.auth_method = 'sms'
        self.ae.auth_method_config = test_data.authmethod_config_sms_default
        self.ae.save()
        c = JClient()


        # add census without problem with captcha
        c.authenticate(0, test_data.admin)
        response = c.census(self.aeid, test_data.census_sms_default)
        self.assertEqual(response.status_code, 200)
        response = c.get('/api/auth-event/%d/census/' % self.aeid, {})
        self.assertEqual(response.status_code, 200)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(r['userids']), 4)

        # add register: without captcha
        response = c.register(self.aeid, test_data.register_email_fields)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertTrue(r['msg'].count('Invalid captcha'))

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_sms_default
        data.update({'tlf': '999999999'})

        # add register: bad code
        data.update({'captcha_code': '', 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['msg'], 'Invalid captcha')

        # add register # TODO fix
        data.update({'captcha_code': captcha.code, 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 200)

        # add register: repeat captcha invalid
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['msg'], 'Invalid captcha')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_sms_fields
        data.update({'tlf': '888888888'})

        # add register: bad challenge
        data.update({'captcha_code': captcha.code, 'captcha': ''})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['msg'], 'Invalid captcha')
Ejemplo n.º 3
0
    def test_create_authevent_email_with_captcha(self):
        c = JClient()

        # add census without problem with captcha
        c.authenticate(self.aeid, test_data.auth_email_default)
        response = c.census(self.aeid, test_data.census_email_default)
        self.assertEqual(response.status_code, 200)
        response = c.get('/api/auth-event/%d/census/' % self.aeid, {})
        self.assertEqual(response.status_code, 200)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(r['object_list']), 4)

        # add register: without captcha
        response = c.register(self.aeid, test_data.register_email_fields)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_email_fields

        # add register: bad code
        data.update({'captcha_code': '', 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')

        # add register # TODO fix
        data.update({
            'captcha_code': captcha.code,
            'captcha': captcha.challenge
        })
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 200)

        # add register: repeat captcha invalid
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_email_fields

        # add register: bad challenge
        data.update({'captcha_code': captcha.code, 'captcha': ''})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')
Ejemplo n.º 4
0
    def test_create_authevent_email_with_captcha(self):
        c = JClient()

        # add census without problem with captcha
        c.authenticate(self.aeid, test_data.auth_email_default)
        response = c.census(self.aeid, test_data.census_email_default)
        self.assertEqual(response.status_code, 200)
        response = c.get('/api/auth-event/%d/census/' % self.aeid, {})
        self.assertEqual(response.status_code, 200)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(len(r['object_list']), 4)

        # add register: without captcha
        response = c.register(self.aeid, test_data.register_email_fields)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_email_fields

        # add register: bad code
        data.update({'captcha_code': '', 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')

        # add register # TODO fix
        data.update({'captcha_code': captcha.code, 'captcha': captcha.challenge})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 200)

        # add register: repeat captcha invalid
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')

        # create captcha
        response = c.get('/api/captcha/new/', {})
        self.assertEqual(response.status_code, 200)
        captcha = Captcha.objects.all()[0]
        data = test_data.register_email_fields

        # add register: bad challenge
        data.update({'captcha_code': captcha.code, 'captcha': ''})
        response = c.register(self.aeid, data)
        self.assertEqual(response.status_code, 400)
        r = json.loads(response.content.decode('utf-8'))
        self.assertEqual(r['error_codename'], 'invalid_credentials')