Esempio n. 1
0
 def _login_ldap(cls, login, parameters):
     if 'password' not in parameters:
         msg = cls.fields_get(['password'])['password']['string']
         raise LoginException('password', msg, type='password')
     password = parameters['password']
     try:
         server = ldap_server()
         if server:
             uid = config.get(section, 'uid', default='uid')
             users = cls.ldap_search_user(login, server, attrs=[uid])
             if users and len(users) == 1:
                 [(dn, attrs)] = users
                 con = ldap3.Connection(server, dn, password)
                 if (password and con.bind()):
                     # Use ldap uid so we always get the right case
                     login = attrs.get(uid, [login])[0]
                     user_id = cls._get_login(login)[0]
                     if user_id:
                         return user_id
                     elif config.getboolean(section, 'create_user'):
                         user, = cls.create([{
                             'name': login,
                             'login': login,
                         }])
                         return user.id
     except LDAPException:
         logger.error('LDAPError when login', exc_info=True)
Esempio n. 2
0
 def set_preferences(cls, values, parameters):
     if 'password' in values:
         if 'password' not in parameters:
             msg = cls.fields_get(['password'])['password']['string']
             raise LoginException('password', msg, type='password')
         old_password = parameters['password']
         try:
             server = ldap_server()
             if server:
                 user = cls(Transaction().user)
                 uid = config.get(section, 'uid', default='uid')
                 users = cls.ldap_search_user(user.login,
                                              server,
                                              attrs=[uid])
                 if users and len(users) == 1:
                     [(dn, attrs)] = users
                     con = ldap3.Connection(server, dn, old_password)
                     if con.bind():
                         con.extend.standard.modify_password(
                             dn, old_password, values['password'])
                         values = values.copy()
                         del values['password']
                     else:
                         cls.raise_user_error('wrong_password')
         except LDAPException:
             logger.error('LDAPError when setting preferences',
                          exc_info=True)
     super(User, cls).set_preferences(values, parameters)
Esempio n. 3
0
 def _login_sms(cls, login, parameters):
     pool = Pool()
     SMSCode = pool.get('res.user.login.sms_code')
     user_id, _ = cls._get_login(login)
     if user_id:
         SMSCode.send(user_id)
     if 'sms_code' in parameters:
         code = parameters['sms_code']
         if not code:
             return
         if SMSCode.check(user_id, code):
             return user_id
     msg = SMSCode.fields_get(['code'])['code']['string']
     raise LoginException('sms_code', msg, type='char')
Esempio n. 4
0
 def _login_password(cls, login, parameters):
     if 'password' not in parameters:
         msg = gettext('res.msg_user_password', login=login)
         raise LoginException('password', msg, type='password')
     user_id, password_hash, password_reset = cls._get_login(login)
     if user_id and password_hash:
         password = parameters['password']
         valid, new_hash = cls.check_password(password, password_hash)
         if valid:
             if new_hash:
                 logger.info("Update password hash for %s", user_id)
                 with Transaction().new_transaction() as transaction:
                     with transaction.set_user(0):
                         cls.write([cls(user_id)], {
                             'password_hash': new_hash,
                         })
             return user_id
     elif user_id and password_reset:
         if password_reset == parameters['password']:
             return user_id
    def _(request):
        raise unittest.mock.sentinel.exception

    client = get_client()
    _ = client.get("/exception")

    (e,) = exceptions
    assert e is exception


@pytest.mark.parametrize(
    "exception",
    [
        TrytondUserError("title"),
        TrytondUserWarning("title", "details"),
        LoginException("title", "details"),
    ],
)
def test_trytonderrors_not_captured(
    sentry_init, app, capture_exceptions, get_client, exception
):
    sentry_init(integrations=[TrytondWSGIIntegration()])
    exceptions = capture_exceptions()

    unittest.mock.sentinel.exception = exception

    @app.route("/usererror")
    def _(request):
        raise unittest.mock.sentinel.exception

    client = get_client()