Changeset 94:c0473c62802d


Ignore:
Timestamp:
Feb 12, 2011, 11:16:02 PM (10 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Catch KeyError? for unsupported verbs in legacy PubSubService? usage.

Author: ralphm.
Fixes: #70.

Because requests are now parsed by PubSubRequest?, it can happen that a request
is succesfully parsed, but there is no legacy handler available. This used
to raise a KeyError?, resulting in a internal-server-error being returned.
Now it returns a feature-not-implemented error.

Location:
wokkel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r93 r94  
    11821182                handler = getattr(resource, request.verb)
    11831183            except AttributeError:
    1184                 # fix lookup feature
    11851184                text = "Request verb: %s" % request.verb
    11861185                return defer.fail(Unsupported('', text))
     
    11881187            d = handler(request)
    11891188        else:
    1190             handlerName, argNames = self._legacyHandlers[request.verb]
     1189            try:
     1190                handlerName, argNames = self._legacyHandlers[request.verb]
     1191            except KeyError:
     1192                text = "Request verb: %s" % request.verb
     1193                return defer.fail(Unsupported('', text))
     1194
    11911195            handler = getattr(self, handlerName)
     1196
    11921197            args = [getattr(request, arg) for arg in argNames]
    11931198            if 'options' in argNames:
    11941199                args[argNames.index('options')] = request.options.getValues()
     1200
    11951201            d = handler(*args)
    11961202
  • wokkel/test/test_pubsub.py

    r93 r94  
    38023802
    38033803
     3804    def test_unknown(self):
     3805        """
     3806        Unknown verb yields unsupported error.
     3807        """
     3808        xml = """
     3809        <iq type='get' to='pubsub.example.org'
     3810                       from='user@example.org'>
     3811          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
     3812            <affiliations node='test'/>
     3813          </pubsub>
     3814        </iq>
     3815        """
     3816
     3817        def cb(result):
     3818            self.assertEquals('feature-not-implemented', result.condition)
     3819            self.assertEquals('unsupported', result.appCondition.name)
     3820            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     3821
     3822        d = self.handleRequest(xml)
     3823        self.assertFailure(d, error.StanzaError)
     3824        d.addCallback(cb)
     3825        return d
     3826
     3827
    38043828
    38053829class PubSubResourceTest(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.