launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #03686
lp:~deryck/launchpad/dont-oops-on-api-without-user-agent-781262 into lp:launchpad
Deryck Hodge has proposed merging lp:~deryck/launchpad/dont-oops-on-api-without-user-agent-781262 into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #781262 in Launchpad itself: "api request without user-agent gives oops"
https://bugs.launchpad.net/launchpad/+bug/781262
For more details, see:
https://code.launchpad.net/~deryck/launchpad/dont-oops-on-api-without-user-agent-781262/+merge/61660
This branch ensures we don't generate an OOPS when API clients do not specify a user agent. It builds on an existing webservice page test, ensuring that there is no X-Lazr-Ooopsid. The actual work is done by using the expose method, which is the provided means for disabling OOPS reporting on an error.
--
https://code.launchpad.net/~deryck/launchpad/dont-oops-on-api-without-user-agent-781262/+merge/61660
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~deryck/launchpad/dont-oops-on-api-without-user-agent-781262 into lp:launchpad.
=== modified file 'lib/canonical/launchpad/pagetests/webservice/xx-service.txt'
--- lib/canonical/launchpad/pagetests/webservice/xx-service.txt 2011-02-13 22:19:44 +0000
+++ lib/canonical/launchpad/pagetests/webservice/xx-service.txt 2011-05-19 20:44:31 +0000
@@ -155,20 +155,29 @@
...
You need to be logged in to view this URL.
-An empty or missing user agent results in an error.
+An empty or missing user agent results in an error. But there is
+no OOPS generated for this error.
>>> response = request_with_user_agent(' ')
- >>> print response.getOutput()
+ >>> output = response.getOutput()
+ >>> print output
HTTP/1.1 401 Unauthorized
...
Anonymous requests must provide a User-Agent.
+ >>> 'X-Lazr-Oopsid' not in output
+ True
+
>>> response = request_with_user_agent(None)
- >>> print response.getOutput()
+ >>> output = response.getOutput()
+ >>> print output
HTTP/1.1 401 Unauthorized
...
Anonymous requests must provide a User-Agent.
+ >>> 'X-Lazr-Oopsid' not in output
+ True
+
API Requests to other hosts
===========================
=== modified file 'lib/canonical/launchpad/webapp/servers.py'
--- lib/canonical/launchpad/webapp/servers.py 2011-04-13 13:19:09 +0000
+++ lib/canonical/launchpad/webapp/servers.py 2011-05-19 20:44:31 +0000
@@ -11,6 +11,7 @@
import threading
import xmlrpclib
+from lazr.restful.error import expose
from lazr.restful.interfaces import (
ICollectionResource,
IWebServiceConfiguration,
@@ -1235,8 +1236,8 @@
anonymous_request = True
consumer_key = request.getHeader('User-Agent', '')
if consumer_key == '':
- raise Unauthorized(
- 'Anonymous requests must provide a User-Agent.')
+ raise expose(Unauthorized(
+ 'Anonymous requests must provide a User-Agent.'), 401)
consumer = consumers.getByKey(consumer_key)
if consumer is None: