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')
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')
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')
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')
def test_get_new_captcha_generate_other_captcha(self): self.assertEqual(Captcha.objects.count(), 0) self.assertEqual(Captcha.objects.filter(used=True).count(), 0) c = JClient() response = c.get('/api/captcha/new/', {}) self.assertEqual(response.status_code, 200) r = json.loads(response.content.decode('utf-8')) self.assertTrue(r['image_url'] and r['captcha_code']) response = c.get('/api/captcha/new/', {}) self.assertEqual(response.status_code, 200) r = json.loads(response.content.decode('utf-8')) self.assertTrue(r['image_url'] and r['captcha_code']) self.assertEqual(Captcha.objects.count(), 2) self.assertEqual(Captcha.objects.filter(used=True).count(), 2)
def test_ping(self): c = JClient() response = c.authenticate(self.aeid, test_data.pwd_auth) self.assertEqual(response.status_code, 200) response = c.get('/api/auth-event/%s/ping/' % self.aeid, {}) self.assertEqual(response.status_code, 200) r = json.loads(response.content.decode('utf-8')) self.assertTrue(r['auth-token'].startswith('khmac:///sha-256'))
def test_create_new_captcha(self): c = JClient() self.assertEqual(0, Captcha.objects.count()) response = c.get('/api/captcha/new/', {}) self.assertEqual(response.status_code, 200) self.assertEqual(1, Captcha.objects.count())