Пример #1
0
 def test_plain_auth_baddata(self):
     handler = SASLAuthHandler()
     auth_element = ET.Element("auth")
     auth_element.set("mechanism", "PLAIN")
     auth_element.text = "something\0totallywronghere"
     with self.assertRaises(MalformedRequestError) as cm:
         handler.process(auth_element)
Пример #2
0
 def test_plain_auth_good(self):
     pyfire.singletons._validation_registry.success = True
     handler = SASLAuthHandler()
     auth_element = ET.Element("auth")
     auth_element.set("mechanism", "PLAIN")
     auth_element.text = b64encode(unichr(0).join(["zid", "user", "pass"]))
     handler.process(auth_element)
Пример #3
0
 def test_plain_auth_baddata(self):
     handler = SASLAuthHandler()
     auth_element = ET.Element("auth")
     auth_element.set("mechanism", "PLAIN")
     auth_element.text = "something\0totallywronghere"
     with self.assertRaises(MalformedRequestError) as cm:
         handler.process(auth_element)
Пример #4
0
 def test_plain_auth_good(self):
     pyfire.singletons._validation_registry.success = True
     handler = SASLAuthHandler()
     auth_element = ET.Element("auth")
     auth_element.set("mechanism", "PLAIN")
     auth_element.text = b64encode(unichr(0).join(["zid", "user", "pass"]))
     handler.process(auth_element)
Пример #5
0
 def test_plain_auth_bad(self):
     pyfire.singletons._validation_registry.success = False
     handler = SASLAuthHandler()
     auth_element = ET.Element("auth")
     auth_element.set("mechanism", "PLAIN")
     auth_element.text = b64encode(unichr(0).join(["zid", "user", "pass"]))
     with self.assertRaises(NotAuthorizedError) as cm:
         handler.process(auth_element)
Пример #6
0
 def test_plain_auth_bad(self):
     pyfire.singletons._validation_registry.success = False
     handler = SASLAuthHandler()
     auth_element = ET.Element("auth")
     auth_element.set("mechanism", "PLAIN")
     auth_element.text = b64encode(unichr(0).join(["zid", "user", "pass"]))
     with self.assertRaises(NotAuthorizedError) as cm:
         handler.process(auth_element)
Пример #7
0
    def authenticate(self, tree):
        """Authenticates user for session"""

        # Currently RFC specifies only SASL as supported way of auth'ing
        handler = SASLAuthHandler()
        if tree.get('xmlns') != handler.namespace:
            raise MalformedRequestError
        handler.process(tree)
        self.connection.parser.reset()
        self.jid = JID("@".join([handler.authenticated_user, self.hostname]))
        self.authenticated = True
        response_element = ET.Element("success")
        response_element.set("xmlns", handler.namespace)
        self.send_element(response_element)
Пример #8
0
    def add_auth_options(self, feature_element):
        """Add supported auth mechanisms to feature element"""

        handler = SASLAuthHandler()
        mechtype_element = ET.SubElement(feature_element, "mechanisms")
        mechtype_element.set("xmlns", handler.namespace)
        for mech in handler.supported_mechs:
            mech_element = ET.SubElement(mechtype_element, 'mechanism')
            mech_element.text = mech