mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-18 18:56:28 +00:00
use Resource instead of Page for web-status
This commit is contained in:
parent
01b09f3bac
commit
6910309e8f
@ -5939,7 +5939,7 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
|
||||
self.assertRaises(
|
||||
server.UnsupportedMethod,
|
||||
self.page.renderHTTP, req,
|
||||
self.page.render, req,
|
||||
)
|
||||
|
||||
def test_missing_token(self):
|
||||
@ -5947,7 +5947,7 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
|
||||
exc = self.assertRaises(
|
||||
common.WebError,
|
||||
self.page.renderHTTP, req,
|
||||
self.page.render, req,
|
||||
)
|
||||
self.assertEquals(exc.text, "Missing token")
|
||||
self.assertEquals(exc.code, 401)
|
||||
@ -5958,7 +5958,7 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
|
||||
exc = self.assertRaises(
|
||||
common.WebError,
|
||||
self.page.renderHTTP, req,
|
||||
self.page.render, req,
|
||||
)
|
||||
self.assertEquals(exc.text, "Do not pass 'token' as URL argument")
|
||||
self.assertEquals(exc.code, 400)
|
||||
@ -5970,7 +5970,7 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
|
||||
exc = self.assertRaises(
|
||||
common.WebError,
|
||||
self.page.renderHTTP, req,
|
||||
self.page.render, req,
|
||||
)
|
||||
self.assertEquals(exc.text, "Invalid token")
|
||||
self.assertEquals(exc.code, 401)
|
||||
@ -5980,7 +5980,7 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
req.fields['token'] = FakeField(self.client.token)
|
||||
|
||||
with self.assertRaises(common.WebError) as exc:
|
||||
self.page.renderHTTP(req)
|
||||
self.page.render(req)
|
||||
self.assertEquals(exc.exception.text, "Must provide 't=' argument")
|
||||
self.assertEquals(exc.exception.code, 400)
|
||||
|
||||
@ -5990,7 +5990,7 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
req.args['t'] = 'not at all json'
|
||||
|
||||
with self.assertRaises(common.WebError) as exc:
|
||||
self.page.renderHTTP(req)
|
||||
self.page.render(req)
|
||||
self.assertTrue("invalid type" in exc.exception.text)
|
||||
self.assertEquals(exc.exception.code, 400)
|
||||
|
||||
@ -5999,5 +5999,5 @@ class TestTokenOnlyApi(unittest.TestCase):
|
||||
req.fields['token'] = FakeField(self.client.token)
|
||||
req.args['t'] = ['json']
|
||||
|
||||
result = self.page.renderHTTP(req)
|
||||
result = self.page.render(req)
|
||||
self.assertTrue(result == NotImplemented)
|
||||
|
@ -2,7 +2,7 @@
|
||||
import time
|
||||
import simplejson
|
||||
|
||||
from twisted.web import http, server
|
||||
from twisted.web import http, server, resource
|
||||
from twisted.python import log
|
||||
from zope.interface import Interface
|
||||
from nevow import loaders, appserver, rend
|
||||
@ -386,7 +386,7 @@ class RenderMixin:
|
||||
return m(ctx)
|
||||
|
||||
|
||||
class TokenOnlyWebApi(rend.Page):
|
||||
class TokenOnlyWebApi(resource.Resource):
|
||||
"""
|
||||
I provide a rend.Page implementation that only accepts POST calls,
|
||||
and only if they have a 'token=' arg with the correct
|
||||
@ -402,14 +402,12 @@ class TokenOnlyWebApi(rend.Page):
|
||||
"""
|
||||
|
||||
def __init__(self, client):
|
||||
super(TokenOnlyWebApi, self).__init__()
|
||||
self.client = client
|
||||
|
||||
def post_json(self, req):
|
||||
return NotImplemented
|
||||
|
||||
def renderHTTP(self, ctx):
|
||||
req = IRequest(ctx)
|
||||
def render(self, req):
|
||||
if req.method != 'POST':
|
||||
raise server.UnsupportedMethod(('POST',))
|
||||
if req.args.get('token', False):
|
||||
|
Loading…
Reference in New Issue
Block a user