Exemplo n.º 1
0
	def testOutbox(self):
		'''Test the storage and retrieval of messages in the outbox'''
		db = supersimpledb.MurmeliDb()
		DbI.setDb(db)
		self.assertEqual(len(DbI.getOutboxMessages()), 0, "Outbox should be empty")
		# Add profile for this the target recipient
		DbI.updateProfile("ABC312", {"keyid":"ZYXW987", "status":"trusted", "name":"Best friend"})

		# add one message to the outbox
		DbI.addToOutbox(ExampleMessage(["ABC312"], "Doesn't matter really what the message is"))
		self.assertEqual(len(DbI.getOutboxMessages()), 1, "Outbox should have one message")
		self.checkMessageIndexes(DbI.getOutboxMessages())
		DbI.addToOutbox(ExampleMessage(["ABC312"], "A second message"))
		self.assertEqual(len(DbI.getOutboxMessages()), 2, "Outbox should have 2 messages")
		self.checkMessageIndexes(DbI.getOutboxMessages())
		self.assertTrue(DbI.deleteFromOutbox(0))
		self.assertEqual(len(DbI.getOutboxMessages()), 1, "Outbox should only have 1 message (1 empty)")
		nonEmptyMessages = DbI.getOutboxMessages()
		self.assertEqual(len(nonEmptyMessages), 1, "Outbox should only have 1 non-empty message")
		self.assertEqual(nonEmptyMessages[0]["_id"], 1, "Message 0 should have index 1")
		# See if index of third message is properly assigned
		DbI.addToOutbox(ExampleMessage(["ABC312"], "A third message"))
		self.assertEqual(len(DbI.getOutboxMessages()), 2, "Outbox should have 2 messages again")
		self.assertEqual(DbI.getOutboxMessages()[0]["_id"], 1, "Message 0 should have index 1")
		self.assertEqual(DbI.getOutboxMessages()[1]["_id"], 2, "Message 1 should have index 2")

		# done
		DbI.releaseDb()
Exemplo n.º 2
0
	def testBasics(self):
		'''Testing the basics of the interface with a super-simple db'''

		# Create new, empty database without file-storage
		db = supersimpledb.MurmeliDb()
		DbI.setDb(db)

		# Lists should be empty
		self.assertEqual(len(DbI.getMessageableProfiles()), 0, "Should be 0 messageables")
		self.assertEqual(len(DbI.getTrustedProfiles()), 0, "Should be 0 trusted")
		self.assertFalse(DbI.hasFriends(), "Shouldn't have any friends")

		# Store some profiles
		DbI.updateProfile("abc123", {"keyid":"ZYXW987", "status":"self", "name":"That's me"})
		DbI.updateProfile("def123", {"keyid":"JKLM987", "status":"trusted", "name":"Jimmy"})
		DbI.updateProfile("ghi123", {"keyid":"TUVWX987", "status":"untrusted", "name":"Dave"})

		# Get my ids
		self.assertEqual(DbI.getOwnTorid(), "abc123", "Should find correct tor id")
		self.assertEqual(DbI.getOwnKeyid(), "ZYXW987", "Should find correct key id")

		# Get all profiles
		self.assertEqual(len(DbI.getProfiles()), 3, "Should be three profiles in total")
		self.assertEqual(len(DbI.getMessageableProfiles()), 2, "Should be two messageables")
		self.assertEqual(len(DbI.getTrustedProfiles()), 1, "Should be one trusted")
		self.assertEqual(DbI.getTrustedProfiles()[0]['displayName'], "Jimmy", "Jimmy should be trusted")
		self.assertTrue(DbI.hasFriends(), "Should have friends")

		# Update an existing profile
		DbI.updateProfile("def123", {"displayName":"Slippin' Jimmy"})
		self.assertEqual(len(DbI.getTrustedProfiles()), 1, "Should still be one trusted")
		self.assertEqual(DbI.getTrustedProfiles()[0]['displayName'], "Slippin' Jimmy", "Slippin' Jimmy should be trusted")

		# Finished
		DbI.releaseDb()
Exemplo n.º 3
0
	def testConversationIds(self):
		'''Test the increment of conversation ids'''
		db = supersimpledb.MurmeliDb()
		DbI.setDb(db)
		# If we start with an empty db, the id should start at 1
		for i in range(100):
			self.assertEqual(DbI.getNewConversationId(), i+1, "id should be 1 more than i")
		# Add profiles for us and a messages sender
		DbI.updateProfile("F055", {"keyid":"ZYXW987", "status":"self", "name":"That's me"})
		DbI.updateProfile("ABC312", {"keyid":"ZYXW987", "status":"trusted", "name":"Best friend"})
		# Add an inbox message with a conversation id
		DbI.addToInbox({"messageBody":"Gorgonzola and Camembert", "timestamp":"early 2017",
			"fromId":"ABC312"})
		# Get this message again, and check the conversation id, should be 101
		msg0 = DbI.getInboxMessages()[0]
		self.assertEqual(msg0.get("conversationid", 0), 101, "Id should now be 101")

		# Add another message with the parent hash referring to the first one
		DbI.addToInbox({"messageBody":"Fried egg sandwich", "timestamp":"middle 2017",
			"fromId":"ABC312", "parentHash":'40e98bae7a811c23b59b89bd0f11b0a0'})
		msg1 = DbI.getInboxMessages()[0]
		self.assertTrue("Fried egg" in msg1.get("messageBody", ""), "Fried egg should be first")
		self.assertEqual(msg1.get("conversationid", 0), 101, "Id should now also be 101")

		# Add another message with an unrecognised parent hash
		DbI.addToInbox({"messageBody":"Red wine and chocolate", "timestamp":"late 2017",
			"fromId":"ABC312", "parentHash":'ff3'})
		msg2 = DbI.getInboxMessages()[0]
		self.assertTrue("Red wine" in msg2.get("messageBody", ""), "Red wine should be first")
		self.assertEqual(msg2.get("conversationid", 0), 102, "Id should take 102")

		# done
		DbI.releaseDb()
Exemplo n.º 4
0
	def testSearching(self):
		'''Test the searching of the inbox'''
		db = supersimpledb.MurmeliDb()
		DbI.setDb(db)
		# Add some inbox messages with different text
		DbI.addToInbox({"messageBody":"There were some children playing in the park", "timestamp":"", "fromId":"ABC312"})
		DbI.addToInbox({"messageBody":"There was a child playing in the castle", "timestamp":"", "fromId":"ABC312"})
		DbI.addToInbox({"messageBody":"Children were making far too much noise", "timestamp":"", "fromId":"ABC312"})
		# Get this message again, and check the conversation id, should be 101
		self.assertEqual(len(DbI.getInboxMessages()), 3, "Inbox has 3")

		search1 = DbI.searchInboxMessages("child")
		self.assertEqual(len(search1), 2, "Only 2 match 'child'")
		search2 = DbI.searchInboxMessages("children")
		self.assertEqual(len(search2), 1, "Only 1 matches 'children'")
		search3 = DbI.searchInboxMessages("")
		self.assertEqual(len(search3), 3, "All match empty search string")
		search4 = DbI.searchInboxMessages("hild")
		self.assertEqual(len(search4), 3, "All match 'hild'")
		search5 = DbI.searchInboxMessages("noisy")
		self.assertEqual(len(search5), 0, "None are noisy")
		search6 = DbI.searchInboxMessages("Child")
		self.assertEqual(len(search6), 1, "Only 1 matches 'Child'")

		# done
		DbI.releaseDb()
Exemplo n.º 5
0
    def __init__(self, *args):
        self.logPanel = LogWindow()
        GuiWindow.__init__(self, lowerItem=self.logPanel)
        self.clearWebCache()
        self.postmen = None
        self.toolbar = self.makeToolbar([
            ("images/toolbar-home.png", self.onHomeClicked,
             "mainwindow.toolbar.home"),
            ("images/toolbar-people.png", self.onContactsClicked,
             "mainwindow.toolbar.contacts"),
            ("images/toolbar-messages.png", self.onMessagesClicked,
             "mainwindow.toolbar.messages"),
            ("images/toolbar-messages-highlight.png", self.onMessagesClicked,
             "mainwindow.toolbar.messages"),
            ("images/toolbar-calendar.png", self.onCalendarClicked,
             "mainwindow.toolbar.calendar"),
            ("images/toolbar-settings.png", self.onSettingsClicked,
             "mainwindow.toolbar.settings")
        ])
        self.addToolBar(self.toolbar)
        self.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
        # status bar
        self.statusbar = QtWidgets.QStatusBar(self)
        self.statusbar.setObjectName("statusbar")
        self.setStatusBar(self.statusbar)

        self.setWindowTitle(I18nManager.getText("mainwindow.title"))

        self.setStatusTip("Murmeli")
        self.setPageServer(PageServer())
        self.navigateTo("/")
        # we want to be notified of Config changes
        Config.registerSubscriber(self)
        self.postmen = [
            postmen.IncomingPostman(self),
            postmen.OutgoingPostman(self)
        ]
        self.postmen[1].messageSentSignal.connect(self.logPanel.notifyLogEvent)
        MessageShuffler.getTannoy().updateSignal.connect(
            self.logPanel.notifyLogEvent)
        # Make sure Tor client is started
        if not TorClient.isStarted():
            TorClient.startTor()
        # Create database instance if not already set
        if not DbI.hasDbSet():
            DbI.setDb(MurmeliDb(Config.getSsDatabaseFile()))
        # Make sure the status of the contacts matches our keyring
        missingKeyNames = ContactMaker.checkAllContactsKeys()
        if missingKeyNames:
            warningTexts = [I18nManager.getText("warning.keysnotfoundfor")
                            ] + missingKeyNames
            QtWidgets.QMessageBox.warning(self, "Murmeli",
                                          "\n   ".join(warningTexts))
Exemplo n.º 6
0
 def setupOwnProfile(keyId):
     tempDb = MurmeliDb()
     DbI.setDb(tempDb)
     DbI.updateProfile(
         TestUtils._ownTorId, {
             "status":
             "self",
             "ownprofile":
             True,
             "keyid":
             keyId,
             "name":
             "Geoffrey Lancaster",
             "displayName":
             "Me",
             "description":
             "Ä fictitious person with a couple of Umläute in his description."
         })
Exemplo n.º 7
0
	def testAvatars(self):
		'''Test the loading, storing and exporting of binary avatar images'''
		db = supersimpledb.MurmeliDb()
		DbI.setDb(db)
		inputPath = "testdata/example-avatar.jpg"
		outPath = "cache/avatar-deadbeef.jpg"
		if os.path.exists(outPath):
			os.remove(outPath)
		os.makedirs('cache', exist_ok=True)
		self.assertFalse(os.path.exists(outPath))
		DbI.updateProfile("deadbeef", {"profilepicpath":inputPath})
		# Output file still shouldn't exist, we didn't give a path to write picture to
		self.assertFalse(os.path.exists(outPath))
		DbI.updateProfile("deadbeef", {"profilepicpath":inputPath}, "cache")
		# Output file should exist now
		self.assertTrue(os.path.exists(outPath))
		# TODO: Any way to compare input with output?  They're not the same.
		DbI.releaseDb()
Exemplo n.º 8
0
 def run(self):
     # Check each of the services in turn
     self.successFlags = {}
     # Database
     time.sleep(0.5)
     DbI.setDb(MurmeliDb(Config.getSsDatabaseFile()))
     self.successFlags['database'] = True
     self.updatedSignal.emit()
     time.sleep(0.5)
     # Gnupg
     self.successFlags['gpg'] = CryptoClient.checkGpg()
     self.updatedSignal.emit()
     time.sleep(1)
     # Tor
     if TorClient.startTor():
         torid = TorClient.getOwnId()
         if torid:
             print("Started tor, our own id is: ", torid)
             self.successFlags['tor'] = True
         else:
             print("Failed to start tor")
     else:
         print("startTor returned false :(")
Exemplo n.º 9
0
try:
    from gnupg import GPG
    # found them
except ImportError:
    canStartMurmeli = False

# if it all looks ok so far, we need to check the database
db = None
dbFilePath = Config.getSsDatabaseFile()
if not os.path.exists(dbFilePath):
    canStartMurmeli = False

if canStartMurmeli:
    print("I think I can start Murmeli, checking database status")
    db = MurmeliDb(dbFilePath)
    DbI.setDb(db)

    try:
        ownprofile = DbI.getProfile()
        if ownprofile is None or ownprofile.get("keyid", None) is None:
            print(
                "I didn't get a profile or didn't get a key, so I can't start Murmeli"
            )
            canStartMurmeli = False
        else:
            print("I think I got a profile and a keyid: '",
                  ownprofile.get("keyid", ""),
                  "' so I'm going to start Murmeli")
    except Exception as e:
        print(
            "Exception thrown trying to get profile, so I can't start Murmeli:",