def setUp(self): self.org_1 = setup_org() self.org_2 = setup_org(name=tv.ORG_NAME_2, slug=tv.ORG_SLUG_2) self.user_1 = setup_user(org=self.org_1) self.user_2 = setup_user(org=self.org_1, email=tv.USER2_EMAIL, password=tv.USER2_PASS) self.user_3 = setup_user(org=self.org_2, email=tv.USER3_EMAIL, password=tv.USER3_PASS) self.user_1_codes_1 = ["AA1222", "AA1223"] self.user_1_codes_2 = ["BB1222", "BB1223"] self.user_2_codes = ["CC1222", "CC1223"] self.user_1_static_device_1 = setup_2fa_static_device( self.user_1, "user1 valid token set 1", codes_list=self.user_1_codes_1) self.user_1_static_device_2 = setup_2fa_static_device( self.user_1, "user1 valid token set 2", codes_list=self.user_1_codes_2) # invalid set with no codes left self.user_1_static_device_3 = setup_2fa_static_device( self.user_1, "user1 invalid token set 3") self.user_2_static_device_1 = setup_2fa_static_device( self.user_2, "user2 valid token set", codes_list=self.user_2_codes)
def setUp(self): self.org_1 = setup_org() self.user_1 = setup_user(org=self.org_1) self.user_1_static_device_1 = setup_2fa_static_device( self.user_1, tv.STATIC_DEVICE_NAME, codes_list=tv.STATIC_DEVICE_CODES_LIST)
def test_otp_check_redirect_to_proper_view(self): # Given no 2fa devices are setup response = self.client.get("/app/") # Home page is displayed self.assertTemplateUsed(response, "core/home.html") # Given a static device is setup setup_2fa_static_device(self.user, codes_list=tv.STATIC_DEVICE_CODES_LIST) response = self.client.get("/app/", follow=True) # User is redirect to otp_static_check self.assertRedirects(response, reverse_lazy("otp_static_check")) # Given static + totp device are setup setup_2fa_totp_device(self.user) response = self.client.get("/app/", follow=True) # User is redirect to otp_static_check self.assertRedirects(response, reverse_lazy("otp_totp_check")) # Given static + totp + 2fa device are setup setup_2fa_fido2_device(self.user) response = self.client.get("/app/", follow=True) # User is redirect to otp_static_check self.assertRedirects(response, reverse_lazy("otp_fido2_check"))
def setUp(self): self.org_1 = setup_org() self.org_2 = setup_org(name=tv.ORG_NAME_2, slug=tv.ORG_SLUG_2) self.user_1 = setup_user(org=self.org_1) self.user_2 = setup_user(org=self.org_1, email=tv.USER2_EMAIL, password=tv.USER2_PASS) self.user_1_codes_1 = ["AA1222", "AA1223"] self.user_1_static_device_1 = setup_2fa_static_device( self.user_1, "user1 valid token set 1", codes_list=self.user_1_codes_1) self.user_1_fido2_device_1 = setup_2fa_fido2_device( self.user_1, "user1 fido2 device 1") self.user_1_totp_device_1 = setup_2fa_totp_device( self.user_1, "user1 totp 1") self.user_1_totp_device_2 = setup_2fa_totp_device( self.user_1, "user1 totp 2") self.user_2_totp_device_2 = setup_2fa_totp_device( self.user_2, "user2 totp 1")
def setUp(self, **kwargs): # orgs, admin, users are already created super().setUp() self.admin_org = setup_org(name="admin-org", slug="admin-org") self.admin = setup_admin(self.admin_org) self.user1_org = setup_org(name=tv.ORG_NAME_1, slug=tv.ORG_SLUG_1) self.user1 = setup_user(self.user1_org, email=tv.USER1_EMAIL, password=tv.USER1_PASS) self.user2_org = setup_org(name=tv.ORG_NAME_2, slug=tv.ORG_SLUG_2) self.user2 = setup_user(self.user2_org, email=tv.USER2_EMAIL, password=tv.USER2_PASS) # mock OTPMiddleware._verify_user() to skip check page self.middleware_patcher = patch.object(OTPMiddleware, "_verify_user", mocked_verify_user) self.middleware_patcher.start() self.addCleanup( patch.stopall ) # ensure mock is remove after each test, even if the test crash self.addCleanup(totp_time_setter.reset_mock, side_effect=True) # admin, user1 and user2 have added documents, folders, otp devices self.admin_resources = {} self.admin_resources["folder1"] = setup_folder(self.admin_org) self.admin_resources["sub_folder1"] = setup_folder( self.admin_org, parent=self.admin_resources["folder1"]) self.admin_resources["doc1"] = setup_document( self.admin_org, ftl_user=self.admin, binary=setup_temporary_file().name) self.admin_resources["doc2"] = setup_document( self.admin_org, ftl_user=self.admin, ftl_folder=self.admin_resources["folder1"], binary=setup_temporary_file().name, ) self.admin_resources["doc3"] = setup_document( self.admin_org, ftl_user=self.admin, ftl_folder=self.admin_resources["sub_folder1"], binary=setup_temporary_file().name, ) self.admin_resources["totp_device"] = setup_2fa_totp_device( self.admin, secret_key=TOTP_DEVICE_SECRET_KEY) self.admin_resources["fido2_device"] = setup_2fa_fido2_device( self.admin) self.admin_resources["static_device"] = setup_2fa_static_device( self.admin, codes_list=["AAA"]) self.user1_resources = {} self.user1_resources["folder1"] = setup_folder(self.user1_org) self.user1_resources["sub_folder1"] = setup_folder( self.user1_org, parent=self.user1_resources["folder1"]) self.user1_resources["doc1"] = setup_document( self.user1_org, ftl_user=self.user1, binary=setup_temporary_file().name) self.user1_resources["doc2"] = setup_document( self.user1_org, ftl_user=self.user1, ftl_folder=self.user1_resources["folder1"], binary=setup_temporary_file().name, ) self.user1_resources["doc3"] = setup_document( self.user1_org, ftl_user=self.user1, ftl_folder=self.user1_resources["sub_folder1"], binary=setup_temporary_file().name, ) self.user1_resources["totp_device"] = setup_2fa_totp_device( self.user1, secret_key=TOTP_DEVICE_SECRET_KEY) self.user1_resources["fido2_device"] = setup_2fa_fido2_device( self.user1) self.user1_resources["static_device"] = setup_2fa_static_device( self.user1, codes_list=["AAA"]) self.user2_resources = {} self.user2_resources["folder1"] = setup_folder(self.user2_org) self.user2_resources["sub_folder1"] = setup_folder( self.user2_org, parent=self.user2_resources["folder1"]) self.user2_resources["doc1"] = setup_document(self.user2_org, ftl_user=self.user2) self.user2_resources["doc2"] = setup_document( self.user2_org, ftl_user=self.user2, ftl_folder=self.user2_resources["folder1"], ) self.user2_resources["doc3"] = setup_document( self.user2_org, ftl_user=self.user2, ftl_folder=self.user2_resources["sub_folder1"], ) self.user2_resources["totp_device"] = setup_2fa_totp_device( self.user2, secret_key=TOTP_DEVICE_SECRET_KEY) self.user2_resources["fido2_device"] = setup_2fa_fido2_device( self.user2) self.user2_resources["static_device"] = setup_2fa_static_device( self.user2, codes_list=["AAA"])