def test_verify_two_factor_with_valid_code(self): fake_session = sessions.Session( data={ 'two_factor_auth': { 'auth_user_username': self.user.username, 'auth_user_id': self.user._primary_key, 'auth_user_fullname': self.user.fullname, } }) sessions.set_session(fake_session) response = verify_two_factor( self.user._id, _valid_code(self.user_settings.totp_secret)) assert_true(isinstance(response, BaseResponse)) assert_equal(response.location, u'/dashboard/') assert_equal(response.status_code, 302)
def test_verify_two_factor_with_valid_code(self): fake_session = sessions.Session(data={ 'two_factor_auth':{ 'auth_user_username': self.user.username, 'auth_user_id': self.user._primary_key, 'auth_user_fullname': self.user.fullname, } }) sessions.set_session(fake_session) response = verify_two_factor(self.user._id, _valid_code(self.user_settings.totp_secret) ) assert_true(isinstance(response, BaseResponse)) assert_equal(response.location, u'/dashboard/') assert_equal(response.status_code, 302)
def two_factor(**kwargs): """View for handling two factor code authentication methods: GET, POST """ if request.method != 'POST': return {} two_factor_code = request.form['twoFactorCode'] try: # verify two factor for current user response = verify_two_factor( session.data['two_factor_auth']['auth_user_id'], two_factor_code) return response except exceptions.TwoFactorValidationError: status.push_status_message(language.TWO_FACTOR_FAILED) # Get next URL from GET / POST data next_url = request.args.get('next', request.form.get('next_url', '')) return {'next_url': next_url}, http.UNAUTHORIZED
def two_factor(**kwargs): """View for handling two factor code authentication methods: GET, POST """ if request.method != 'POST': return {} two_factor_code = request.form['twoFactorCode'] try: # verify two factor for current user response = verify_two_factor(session.data['two_factor_auth']['auth_user_id'], two_factor_code) return response except exceptions.TwoFactorValidationError: status.push_status_message(language.TWO_FACTOR_FAILED) # Get next URL from GET / POST data next_url = request.args.get( 'next', request.form.get( 'next_url', '' ) ) return {'next_url': next_url}, http.UNAUTHORIZED
def test_verify_two_factor_with_invalid_code(self): with assert_raises(TwoFactorValidationError): verify_two_factor(self.user._id, 1234567)