def test_clean_attestation_invalid(self): form = Fido2RegistrationForm({ 'client_data': 'e30=', 'attestation': 'A' }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'attestation': ['FIDO 2 response is malformed.']})
def test_clean_attestation_empty(self): form = Fido2RegistrationForm({ 'client_data': 'e30=', 'attestation': '' }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'attestation': ["Operation wasn't completed."]})
def test_clean_client_data_invalid(self): form = Fido2RegistrationForm({ 'client_data': 'A', 'attestation': ATTESTATION_OBJECT, 'user_handle': USER_HANDLE_B64 }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'client_data': ['FIDO 2 response is malformed.']})
def test_clean_client_data_empty(self): form = Fido2RegistrationForm({ 'client_data': '', 'attestation': ATTESTATION_OBJECT, 'user_handle': USER_HANDLE_B64 }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'client_data': ["Operation wasn't completed."]})
def test_clean_user_handle_invalid(self): form = Fido2RegistrationForm({ 'client_data': 'e30=', 'attestation': ATTESTATION_OBJECT, 'user_handle': '' }) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {'user_handle': ['This field is required.']})
def test_valid(self): # Test form with valid client data and attestation form = Fido2RegistrationForm({ 'client_data': 'eyJjaGFsbGVuZ2UiOiAiR2F6cGFjaG8hIn0=', 'attestation': ATTESTATION_OBJECT }) self.assertTrue(form.is_valid()) cleaned_data = { 'client_data': ClientData(b'{"challenge": "Gazpacho!"}'), 'attestation': AttestationObject(base64.b64decode(ATTESTATION_OBJECT)), 'label': '' } self.assertEqual(form.cleaned_data, cleaned_data)