Beispiel #1
0
    def authenticate_user( self, wsgi_env, response_callback ):
        try:

            auth_data = self.parse_auth_data( wsgi_env )

            # LDAP query
            user = get_user_from_ldap(auth_data['username'], auth_data['password'])

            token = self.generate_token( user )

            # Save token to DB
            self.update_user_data( user, token )

            response_callback( '200 OK', self.headers )
            return self.build_token_msg( token )

        # Known problems - specific response
        except (BoardLDAPAuthError, BoardLDAPUserNotFound) as e:
            # TODO LOG
            #traceback.print_exc()
            print "[DEBUG] BoardLDAPAuthError: ", e

            response_callback( '401 Unauthorized', self.headers )
            return self.build_error_msg( "The given username and password combination is invalid." )

        except BoardAuthError as e:
            # TODO LOG
            #traceback.print_exc()
            print "[DEBUG] BoardAuthError: ", e

            response_callback( '401 Unauthorized', self.headers )
            return self.build_error_msg( e )

        # Unkown problems - generic response
        except Exception as e:
            # TODO LOG
            #traceback.print_exc()
            print "[DEBUG] Exception: ", e

            response_callback( '500 Internal Server Error', self.headers )
            return self.build_error_msg( "There was an unexpected error during authentication." )
Beispiel #2
0
def test_get_user_from_ldap():

    with pytest.raises(ldap_utils.BoardLDAPConnectionError):
        ldap_utils.get_user_from_ldap("nouser", "nopass")