Ejemplo n.º 1
0
    def testSearchAndSomeSmartObject(self):
        sO = ServerObject()
        sO.name = "Test"
        l = LumaConnection(sO)

        # Have LumaConnection use a mock-object for the search
        l.ldapServerObject = MockLDAP()
        (success, resultList, exception) = l.search()

        # The search was successfull
        self.assertTrue(success)
        self.assertEqual(exception, None)

        # The returned smartdataobject gives correct data
        rso = resultList[0]  #smartdataobject returned
        self.assertEqual(rso.getServerAlias(), "Test")
        self.assertEqual(str(rso.getServerMeta()), str(sO))
        self.assertEqual(rso.getObjectClasses(), [])
        self.assertFalse(rso.hasStructuralClass())

        self.assertEqual(rso.getPrettyDN(), "dc=luma")
        self.assertEqual(rso.getPrettyRDN(), "dc=luma")

        self.assertEqual(rso.getAttributeList(), ["dc"])
        self.assertRaises(Exception, rso.getAttributeValueList)
        self.assertEqual(rso.getAttributeValueList("dc"), ['l', 'u', 'm', 'a'])
        self.assertEqual(rso.getAttributeValueList("not-ext."), None)

        self.assertRaises(Exception, rso.getAttributeValue)
        self.assertRaises(Exception, rso.getAttributeValue("dc",
                                                           -1))  #out of range
        self.assertEqual(rso.getAttributeValue("dc", 0), "l")
Ejemplo n.º 2
0
 def testBindToNonexistant(self):
     sO = ServerObject()  # defaults to invalid hostname
     l = LumaConnection(sO)
     (success, error) = l.bind()  # try bind
     self.assertFalse(success)  # Can connect to invalid hostname
     self.assertEqual(str(error), str({"desc":
                                       "Can't contact LDAP server"}))
Ejemplo n.º 3
0
    def testSearchAndSomeSmartObject(self):
	sO = ServerObject()
	sO.name = "Test"
	l = LumaConnection(sO)

	# Have LumaConnection use a mock-object for the search
	l.ldapServerObject = MockLDAP()
	(success, resultList, exception) = l.search()

	# The search was successfull
	self.assertTrue(success)
	self.assertEqual(exception, None)

	# The returned smartdataobject gives correct data
	rso = resultList[0] #smartdataobject returned
	self.assertEqual(rso.getServerAlias(), "Test")
	self.assertEqual(str(rso.getServerMeta()), str(sO))
	self.assertEqual(rso.getObjectClasses(), [])
	self.assertFalse(rso.hasStructuralClass())

	self.assertEqual(rso.getPrettyDN(), "dc=luma")
	self.assertEqual(rso.getPrettyRDN(), "dc=luma")

	self.assertEqual(rso.getAttributeList(),["dc"])
	self.assertRaises(Exception, rso.getAttributeValueList)
	self.assertEqual(rso.getAttributeValueList("dc"), ['l','u','m','a'])
	self.assertEqual(rso.getAttributeValueList("not-ext."), None)

	self.assertRaises(Exception, rso.getAttributeValue)
	self.assertRaises(Exception, rso.getAttributeValue("dc",-1)) #out of range
	self.assertEqual(rso.getAttributeValue("dc",0), "l")
Ejemplo n.º 4
0
    def showTempPasswordDialog(self):
        """ Sets overridePassword for a server.
        Using this one doesn't actually have to enter the password
        in the ServerDialog (and by extension save to disk).
        """
        serverList = ServerList()

        # Create a stringlist to be used by the qinputdialog
        stringList = []
        for server in serverList.getTable():
            stringList.append(server.name)

        # Display list of servers
        (serverString, ok) = QInputDialog.getItem(
            self,
            QApplication.translate("MainWindow", "Select server"),
            QApplication.translate("MainWindow", "Server:"),
            stringList,
            editable=False)
        if ok:
            server = serverList.getServerObjectByName(serverString)
            if server != None:
                # Ask for password
                (value, ok) = QInputDialog.getText(
                    self,
                    QApplication.translate("MainWindow", "Temporary password"),
                    QApplication.translate("MainWindow", "Enter password:"),
                    QLineEdit.Password)
                if ok:
                    # Use value as the overridePassword for the server.
                    LumaConnection(server).overridePassword(value)
Ejemplo n.º 5
0
 def testUtilityMethods(self):
     sO = ServerObject()
     l = LumaConnection(sO)
     #Tests cleanDN() and escape_dn_chars
     self.assertEqual(l.cleanDN("dc=l\,\=\+ma,dc=no"),
                      "dc=l\\2C\\3D\\2Bma,dc=no")
Ejemplo n.º 6
0
    def testUtilityMethods(self):
	sO = ServerObject()
	l = LumaConnection(sO)
	#Tests cleanDN() and escape_dn_chars
	self.assertEqual(l.cleanDN("dc=l\,\=\+ma,dc=no"),"dc=l\\2C\\3D\\2Bma,dc=no")
Ejemplo n.º 7
0
    def testBindToNonexistant(self):
	sO = ServerObject() # defaults to invalid hostname
	l = LumaConnection(sO)
	(success, error) = l.bind() # try bind
	self.assertFalse(success) # Can connect to invalid hostname
	self.assertEqual(str(error),str({"desc":"Can't contact LDAP server"}))