def test_delete_duplicated_tokens_for_aidant(self): aidant = AidantFactory() for _ in range(5): add_static_token(aidant.username, 123456) self.assertEqual(StaticToken.objects.count(), 5) call_command(self.command_name) self.assertEqual(StaticToken.objects.count(), 1)
def test_keep_one_token_of_every_value_for_aidant(self): aidant = AidantFactory() for _ in range(5): add_static_token(aidant.username, 123456) add_static_token(aidant.username, 789123) self.assertEqual(StaticToken.objects.count(), 10) call_command(self.command_name) self.assertEqual(StaticToken.objects.count(), 2)
def after_import_row(self, row, row_result, row_number=None, **kwargs): if row_result.import_type not in ( RowResult.IMPORT_TYPE_NEW, RowResult.IMPORT_TYPE_UPDATE, ): return token = str(row.get("token")) if token and len(token) == 6 and token.isnumeric(): add_static_token(row["username"], token)
def test_delete_static_device_for_confirmed_simple_aidants(self): aidants = [ AidantFactory(), AidantFactory(is_staff=True), AidantFactory(is_staff=True, is_superuser=True), ] for aidant in aidants: add_static_token(aidant.username, 123456) TOTPDevice(user=aidant, confirmed=True).save() self.assertEqual(StaticToken.objects.count(), 3) self.assertEqual(TOTPDevice.objects.count(), 3) call_command(self.command_name) # only the first aidant's static device was deleted self.assertEqual(StaticToken.objects.count(), 2)
def handle(self, *args, **options): username = options['username'] try: statictoken = add_static_token(username, options.get('token')) except get_user_model().DoesNotExist: raise CommandError('User "{0}" does not exist.'.format(username)) self.stdout.write(force_text(statictoken.token))
def test_user_auth_otp(self): from django_otp import DEVICE_ID_SESSION_KEY from django_otp.plugins.otp_static.lib import add_static_token self.client.login(username='******', password='******') st = add_static_token('*****@*****.**') sess = self.client.session sess[DEVICE_ID_SESSION_KEY] = st.device.persistent_id sess.save() self.user_auth_tests(8, fail_otponly=False)
def handle(self, *args, **options): if len(args) != 1: raise CommandError('Please specify exactly one username.') username = args[0] try: statictoken = add_static_token(username, options.get('token')) except get_user_model().DoesNotExist: raise CommandError('User "{0}" does not exist.'.format(username)) self.stdout.write(statictoken.token)
def test_user_auth_otp_nostaff(self): from django_otp import DEVICE_ID_SESSION_KEY from django_otp.plugins.otp_static.lib import add_static_token self.client.login(username='******', password='******') st = add_static_token('*****@*****.**') sess = self.client.session sess[DEVICE_ID_SESSION_KEY] = st.device.persistent_id sess.save() webauth_models.User.objects.filter( email='*****@*****.**').update(is_staff=False) self.user_auth_tests(6, fail_otponly=False)
def handle(self, *args, **options): if len(args) != 1: raise CommandError('Please specify exactly one username.') username = args[0] try: statictoken = add_static_token(username, options.get('token')) except get_user_model().DoesNotExist: raise CommandError('User "{0}" does not exist.'.format(username)) print(statictoken.token, file=self.stdout)