From: Elrond Date: Mon, 20 May 2013 15:50:04 +0000 (+0200) Subject: piwigo: Return proper error for wrong user/password. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4adc3a85dda878b40f44e07b2283d4c55c6c5d02;p=mediagoblin.git piwigo: Return proper error for wrong user/password. And fix tests. --- diff --git a/mediagoblin/plugins/piwigo/tools.py b/mediagoblin/plugins/piwigo/tools.py index 30bb4b97..484ea531 100644 --- a/mediagoblin/plugins/piwigo/tools.py +++ b/mediagoblin/plugins/piwigo/tools.py @@ -84,7 +84,8 @@ def response_xml(result): err = ET.SubElement(r, "err") err.set("code", str(result.code)) err.set("msg", result.msg) - status = result.code + if result.code >= 100 and result.code < 600: + status = result.code else: _fill_element(r, result) return Response(ET.tostring(r, encoding="utf-8", xml_declaration=True), diff --git a/mediagoblin/plugins/piwigo/views.py b/mediagoblin/plugins/piwigo/views.py index 5633f136..1c655bf5 100644 --- a/mediagoblin/plugins/piwigo/views.py +++ b/mediagoblin/plugins/piwigo/views.py @@ -28,8 +28,8 @@ from mediagoblin.media_types import sniff_media from mediagoblin.submit.lib import check_file_field, prepare_queue_task, \ run_process_media -from .tools import CmdTable, PwgNamedArray, response_xml, check_form, \ - PWGSession +from .tools import CmdTable, response_xml, check_form, \ + PWGSession, PwgNamedArray, PwgError from .forms import AddSimpleForm, AddForm @@ -40,15 +40,14 @@ _log = logging.getLogger(__name__) def pwg_login(request): username = request.form.get("username") password = request.form.get("password") - _log.debug("Login for %r/%r...", username, password) user = request.db.User.query.filter_by(username=username).first() if not user: _log.info("User %r not found", username) fake_login_attempt() - return False + return PwgError(999, 'Invalid username/password') if not user.check_login(password): _log.warn("Wrong password for %r", username) - return False + return PwgError(999, 'Invalid username/password') _log.info("Logging %r in", username) request.session["user_id"] = user.id request.session.save() diff --git a/mediagoblin/tests/test_piwigo.py b/mediagoblin/tests/test_piwigo.py index 71d36ddb..16ad0111 100644 --- a/mediagoblin/tests/test_piwigo.py +++ b/mediagoblin/tests/test_piwigo.py @@ -44,11 +44,13 @@ class Test_PWG(object): def test_session(self): resp = self.do_post("pwg.session.login", {"username": u"nouser", "password": "wrong"}) - assert resp.body == XML_PREFIX + '0' + assert resp.body == XML_PREFIX \ + + '' resp = self.do_post("pwg.session.login", {"username": self.username, "password": "wrong"}) - assert resp.body == XML_PREFIX + '0' + assert resp.body == XML_PREFIX \ + + '' resp = self.do_get("pwg.session.getStatus") assert resp.body == XML_PREFIX \