Commit graph

44 commits

Author SHA1 Message Date
Michael Gratton
0ae633d88f Update existing tests to work with ValaUnit 2020-06-30 17:31:07 +10:00
Michael Gratton
21aea73a3d test/test-engine.vala: Minor test ordering improvement 2020-05-06 14:58:56 +10:00
Michael Gratton
3b0815a1dc Geary.Logging: Remove Flag enum
Now that we have classes logging on sub-domains, and the ability to
suppress specific domains, remove flags and switch over to doing
domain suppression for manipulating debug settings in the client.
2020-04-15 17:05:09 +10:00
Michael Gratton
d84899e064 test: Enable engine logging if test harness verbose flag is set 2020-04-10 14:31:41 +10:00
Michael Gratton
339d8ae26e Add unit test for Geary.Imap.ClientSession 2020-03-27 08:29:14 +11:00
Michael Gratton
95c1916abf Add unit test for Geary.Imap.ClientConnection 2020-03-27 08:29:14 +11:00
Chris Heywood
eaa98883a7 Tests for ComposedEmail.contains_inline_img_src and replace_inline_img_src 2019-11-17 16:40:13 +11:00
Michael Gratton
bf4f5c4780 Fix GenericAccount::to_email_identifier not actually working
The GVariant type "*" only matches a single data type, not many, and
the sense of the test to check serialised ids was wrong anyway. As a
reuslt, this method probably never worked. Add a unit test.
2019-10-30 14:12:52 +11:00
Michael Gratton
8206cf434d Remove Flatpak test locale hack, just use en_US.UTF-8 for now
FDO 19.08 runtime now includes C.UTF-8 locale, but since Fedora
now ships one that collates high-bit chars, it differs compared
to Debian et al's and FDO.

As a result, just use en_US.UTF-8 for now, probably until glibc
actually ships it and so they all agree.
2019-10-16 13:36:29 +11:00
Michael Gratton
da6ac828bd Move Geary.JS package into client as Util.JS
The only reason it was in the engine was so it could be used by both
the client and the web extension, without worrying about the
webkit2gtk and webkit2gtk_web_extension packages conflicting. However
it didn't really belong there, and added a dependency for the engine
on javascriptcoregtk which doesn't belong. So this fixes all that.
2019-07-21 10:00:32 +10:00
Michael Gratton
faf84db9f4 Actually ensure the engine PartTest suite is run 2019-07-18 14:37:23 +10:00
Michael Gratton
7b124abd2e Fix engine test failure under flatpak
Geary.ImapDb.Database/utf8_case_insensitive_collation depends on a well
known UTF-8 collation order, but distros only ship C.UTF-8 by default
and Flatpak doesn't ship that, so support en_US.UTF-8 as a fallback.

See https://gitlab.com/freedesktop-sdk/freedesktop-sdk/issues/812
2019-06-26 12:46:08 +10:00
Michael Gratton
788a06144f Ensure test drivers all have sane locales set 2019-06-22 14:08:03 +10:00
Michael Gratton
65ab37938f Implement new contact harvester for the engine
Replaces harvesting code in ImapDB code so as to be stand-alone and
reusable. Implement harvesting policy to only harvest from a set of
whitelisted special folder types (so junk and trash is not harvested)
and only harvest valid, non-spoofed, addresses.
2019-06-13 16:32:47 +10:00
Michael Gratton
809f664319 ContactStoreImpl unit tests 2019-06-13 16:28:55 +10:00
Michael James Gratton
dd3a7a1bc8 Add API for (de)serialising FolderPath and EmailIdentifier
Supports (de)serialising via GLib.Variant for use as GLib.Action targets
transmission via DBus, etc.
2019-04-17 09:06:24 +10:00
Michael Gratton
ef8f97628e Merge branch 'wip/remove-ci-test-workaround' into 'mainline'
Remove CI test workaround

See merge request GNOME/geary!198

(cherry picked from commit 8654c7ae136d2467f7b5b2e85a436d9039bd64bc)

4fc688de Revert "Work around DB tests always failing on gcc150.osuosl.org CI runner"
6b4b598a Add test runner multiplier to account for slow CI runners
2019-04-09 16:16:10 +00:00
Michael Gratton
b3b44ccd42 Work around DB tests always failing on gcc150.osuosl.org CI runner
See Infrastructure/Infrastructure#97
2019-02-19 17:12:26 +11:00
Michael Gratton
539893fb72 Add some unit tests for setting email flags 2019-02-13 18:41:49 +11:00
Michael Gratton
5a22e8e4a2 Convert Geary.FolderRoot to be an actual root, not just a top-level
Instead of each top-level IMAP folder being a FolderRoot object, then
children of that being FolderPath objects, this makes FolderRoot an
"empty" FolderPath, so that both top-level and descendant folders are
plain FolderPath objects. Aside from being more technically correct,
this means that empty namespace roots can now be used interchangably
with non-empty namespace roots (addressing issue #181), and custom
folder implementations no longer need to provide their own trivial,
custom FolderRoot.

To support this, a notion of an IMAP root and a local root have been
added from which all remote and local folder paths are now derived,
existing places that assume top-level == root have been fixed, and
unit tests have been added.
2019-01-15 00:18:45 +11:00
Michael Gratton
faf7a2bdfd Add some unit tests for Geary.ImapDb.Account folder management 2019-01-14 11:01:03 +11:00
Michael Gratton
9884faba84 Add general impls for converting enum values to nicks and back.
Use this for service provider related enums.
2018-11-30 23:49:30 +11:00
Michael James Gratton
43ba38bb05 Add unit test for IMAP FETCH command constructor. 2018-09-01 22:09:18 +10:00
Michael James Gratton
51b44f0f4b Remove ListParameter.parent property so lists can have multiple parents.
The ListParameter.parent property only existed to make the deserialier's
life easier, but is also why sketchy code was needed for appending search
criteria from a ServerSearchEmail replay op to the actual IMAP search
command sent to the server.

This removes the property altogether, and replaces its only use in
Deserialier with a stack, as nature intended. This means lists can be
added to more than one other list, and e.g. when a search is executed,
the search critera can be used for multiple requests.
2018-09-01 22:09:18 +10:00
Michael James Gratton
b345af61e3 Fix mailbox names not being sent to the server quoted if needed.
Since MailboxParameter inherited from StringParameter directly, it meant
that we could never send mailbox names as quoted strings. Also, the
modified-UTF-7 encoding used for mailbox names does not encode
atom-specials such as "\", so if a mailbox name contained one or more of
these, it would be sent to the mail server unquoted.

This removes the MailboxParameter class altogether, and does the
parameter conversion to/from appropriate StringParameter subclasses as
needed. Also adds unit tests for param conversion for ASCII,
atom-specials, and non-ASCII mailbox names.

Fixes issue #40
2018-07-20 13:43:42 +10:00
Michael James Gratton
d9c913268d Fix Imap.DataFormat.is_atom_special not flagging \, [, or DEL as special
Add unit tests.
2018-07-20 13:29:09 +10:00
Michael James Gratton
0e6d499808 Fix AccountInformation.has_email_address, add tests. 2018-07-02 21:22:15 +10:00
Michael James Gratton
4e0950f9bc Introduce a ConfigFile class to improve config management.
ConfigFile is a GLib.KeyFile-like class (and is backed by a KeyFile) that
nonetheless provides convenient a high-level API for getting and setting
grouped config values and asynchronous loading and saving.

* src/engine/util/util-config-file.vala: New ConfigFile class.

* src/engine/api/geary-service-information.vala (ServiceInformation):
  Require ConfigFile groups rather than KeyFile instances for loading and
  saving. Update subclasses and unit tests.

* src/client/accounts/account-manager.vala (AccountManager): Move generic
  account key consts here from Config. Instead of using KeyFile directly,
  use ConfigFile groups for loading and saving settings. Rename load and
  save methods to be a bit more consistent with the class's role, and
  make save_account() throw its errors so they can be reported to the
  user. Update call sites.

* src/client/accounts/local-service-information.vala
  (LocalServiceInformation): Move service-specific config key consts
  here, use new ConfigFile groups for loading and saving.

* src/engine/api/geary-config.vala: Removed, all config consts have been
  moved to the classes using them and KeyFile convenience methods
  subsumed by ConfigFile.
2018-05-25 15:42:56 +10:00
Michael James Gratton
440a4d5932 Merge branch 'wip/726281-text-attachment-crlf'. Fixes Bug 726281. 2018-05-19 14:59:10 +10:00
Michael James Gratton
ba861b8ed1 Fix failing RFC822.Mailbox test.
Reverting commit 1d8c4aea broke the mailbox class a bit. This fixes the
issue, introduces Ascii.last_index_of which is needed by Mailbox anyway,
and adds some test for it. Also 'optimises' Ascii.index_of bit as well.
2018-05-17 15:41:28 +10:00
Michael James Gratton
037af00740 Improve how attachments are saved to the db and disk.
This mostly aims to make the Geary.Attachment and ImapDB.Attachment
objects usable more generally for managing attachments, allowing
these to be instantiated once, persisted, and then reused, rather than
going through a number of representations (GMime, SQlite, Geary) and
having to be saved and re-loaded.

* src/engine/api/geary-attachment.vala (Attachment): Remove id property
  and allow both file and filesize properties to be set after instances
  are constructed. Update call sites.

* src/engine/api/geary-email.vala (Email): Remove get_attachment_by_id
  since it unused.

* src/engine/imap-db/imap-db-attachment.vala (Attachment): Chase
  Geary.Attachment API changes, move object-specific persistence code
  into methods on the actual object class itself and modernise a
  bit. Rename static methods to be a bit more terse. Update call sites
  and add unit tests.

* src/engine/imap-db/imap-db-folder.vala (Folder): Rather than saving
  attachments to the db then reloading them to add them to their email
  objects, just instantiate Attachment instances once, save and then add
  them.

* src/engine/imap-db/imap-db-gc.vala (GC): Replace custom SQL with
  existing accessor for listing attachments.

* src/engine/util/util-stream.vala (MimeOutputStream): New adaptor class
  for GMime streams to GIO output streams.
2018-05-10 13:53:24 +10:00
Michael James Gratton
15d8789685 Move attachment related code from ImapDB.Folder to Attachment. 2018-05-08 13:28:48 +10:00
Michael James Gratton
743b24dd5d Make database classes more amenable to asynchronous use.
This makes both the open() and open_connection() methods on
Geary.DB.Database asynchronous, which allows the VersionedDatabase
open_background() and its hackery to be removed, and upgrades to be
performed asynchronously as well. It also adds a
exec_transaction_async() method to Connection, allowing an existing
object to also be used to establish an async transaction.

* src/engine/db/db-connection.vala (Connection): Add
  exec_transaction_async method, update doc comments.

* src/engine/db/db-database.vala (Database): Make open and
  open_connection async by executing SQLite code in a background thread,
  update call sites. Move job management code out of
  exec_transaction_async into a new internal add_async_job() method so it
  can be used by Connection. Add unit tests.

* src/engine/db/db-transaction-async-job.vala (TransactionAsyncJob): Add
  an optional internal connection method and make the job's cancellable
  an internal property so a Connection instance can specify itself for
  the transaction.

* src/engine/db/db-versioned-database.vala (VersionedDatabase): Remove
  open_background() hack since open() is now async. Make version upgrade
  hooks for derived classes async and update call sites. Use a
  Nonblocking.Mutex rather than GLib mutex so upgrade exclusion works
  asynchronously. Add unit tests.

* src/engine/imap-db/imap-db-database.vala (Database): Make database
  upgrade methods async and execute SQL in async instructions now that
  the bases classes support it. Add unit tests.
2018-05-08 12:24:48 +10:00
Michael James Gratton
3bf2ac181a Add unit tests for ConversationMonitor, fix a few issues.
* src/engine/app/app-conversation-monitor.vala (ConversationMonitor):
  Don't check the folder blacklist for external folder signals when the
  signal is received, do it when the operation is executed so it's fresh.

* src/engine/app/conversation-monitor/app-fill-window-operation.vala
  (FillWindowOperation): Only re-fill the conversation if we get a full
  load, anything else means we hit the end of the folder.

* test/engine/app/app-conversation-monitor-test.vala: New unit tests
  for ConversationMonitor.

* test/engine/api/geary-account-mock.vala,
  test/engine/api/geary-folder-mock.vala: Mix in MockObject mock up all
  method calls.

* test/engine/api/geary-email-identifier-mock.vala: Fix the comparator
  method when the other instance is null.
2018-04-07 10:02:24 +10:00
Michael James Gratton
178ce35113 Fix MailboxAddresses.to_rfc822_string formatting, add unit tests. 2018-01-31 16:15:29 +10:30
Michael James Gratton
71e0e6835e Check for spoofed sender addresses, only display the address if so.
This adds a check for malware spoofing of RFC 822 mailbox addresses such
as those found in Mailsploit, and if found only displays the email
address part and not the mailbox name part.

Part 1 of Mailsploit mitigation.

* src/engine/rfc822/rfc822-mailbox-address.vala (MailboxAddress): Add new
  is_spoofed method to check if the mailbox address looks like it has
  been spoofed. Add is_distinct method to determine if the name and the
  label is the same. Do whitespace and non-printing character stripping
  when generating display versions of the mailbox address, rename methods
  to make it more obvious what they do and update call sites. Add unit
  tests to cover all this.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Check name is distinct and is not valid before
  displaying it. Use new MailboxAddress methods for getting display
  versions of the address, to ensure we get the stripped versions of the
  addresses.

* src/client/conversation-list/formatted-conversation-data.vala
  (ParticipantDisplay): Ensure full addresses are always HTML-markup
  escaped before displaying them as markup, to avoid dropping "<address>"
  values as invalid HTML. Always show the full address if an address is
  invalid.

* src/engine/util/util-string.vala (reduce_whitespace): Strip not only
  whitespace but also non-printing characters. Add unit tests.
2018-01-31 16:15:29 +10:30
Michael James Gratton
6c5a7d5868 Merge branch 'wip/778276-better-flag-updates'. Fixes Bug 778276. 2018-01-12 11:56:57 +11:00
Michael James Gratton
dcdbcbeef9 Add some useful Engine API mock objects. 2017-12-19 10:23:47 +11:00
Michael James Gratton
b24c554f51 Add an operations queue to GenericAccount for server operations.
This generalises the approach used to execute the flag watcher and
background sync, provides a high-level means of managing local and remote
operations, and provides a means of compartmentalising operation-specific
code.

* src/engine/imap-engine/imap-engine-account-operation.vala
  (AccountProcessor): Interface for denoting classes that implements some
  account-specific operation.

* src/engine/imap-engine/imap-engine-account-processor.vala
  (AccountProcessor): Class to manage the operation queue and execute
  operations.

* src/engine/imap-engine/imap-engine-generic-account.vala
  (GenericAccount): Create and manage an instance of AccountProcessor,
  add queue_operation method to allow operations to be queued.
2017-12-19 09:41:50 +11:00
Michael James Gratton
5ed7de55dd Split test running up into test-engine and test-client.
This allows us to compile the engine tests against the internal VAPI, so
we can unit test internal classes.

* CMakeLists.txt: Add top-level targets test-engine-run and
  test-client-run that execute the respective test binaries. Make
  the tests target depend on them and make them depend on their
  binaries.

* Makefile.in: Add test-client and test-engin targets for convenience.

* src/CMakeLists.txt: Make the right invocation of valac to generate a
  correct geary-engine-internal.vapi. Make gsettings schema generation
  depend on geary-client so it exists for test-client if the main binary
  hasn't been built.

* test/CMakeLists.txt: Split everything up into to builds, one for
  test-engine and the other for test-client. Use geary-engine-internal
  when building test-engine for access to internal classes and members.

* test/engine/util-idle-manager-test.vala,
  test/engine/util-timeout-manager-test.vala: Use Glib MainContext rather
  than the GTK main loop for pumping events so the test cases compile
  without GTK.

* test/test-engine.vala, test/test-client.vala: New main source file for
  test binaries based on old main.vala.
2017-12-19 09:41:50 +11:00
Michael James Gratton
5c1aecb685 Make Geary.App.ConversationSet unit testable, add unit tests.
* src/engine/app/conversation-monitor/app-conversation-set.vala
  (ConversationSet.add_all_emails_async): Replace monitor arg with a
  multiset of email paths, update call site to do the path lookup on the
  caller's side instead. Add unit tests.
  (ConversationSet.merge_conversations_async): Remove monitor arg with a
  multiset of email paths, get paths for emails to be merged from the
  conversations themselves, since they should be up to date.
  (Conversation.remove_all_emails_by_identifier): Add unit tests.
2017-12-18 14:49:04 +11:00
Michael James Gratton
57f40ffec3 Make Geary.App.Conversation unit testable, add some tests.
* src/engine/app/app-conversation.vala (Conversation): We currently can't
  easily unit test Conversation instances since the ctor requires a
  ConversationMonitor argument, which is complicated. Replace the monitor
  arg with a base folder (which is what it actually needs the monitor for
  anyway) and remove the signals in favour of adding and modifying the
  API to allow folder paths to be explicitly updated. Remove
  clear_owner() method and dtor now it's useless. Update call sites. Add
  unit tests to make sure the add/remove and multi-path related code
  still works at least.
2017-12-18 14:49:04 +11:00
Michael James Gratton
0f3aa9dc11 Add some useful Engine API mock objects. 2017-12-18 14:49:04 +11:00
Michael James Gratton
878b9aacae Split test running up into test-engine and test-client.
This allows us to compile the engine tests against the internal VAPI, so
we can unit test internal classes.

* CMakeLists.txt: Add top-level targets test-engine-run and
  test-client-run that execute the respective test binaries. Make
  the tests target depend on them and make them depend on their
  binaries.

* Makefile.in: Add test-client and test-engin targets for convenience.

* src/CMakeLists.txt: Make the right invocation of valac to generate a
  correct geary-engine-internal.vapi. Make gsettings schema generation
  depend on geary-client so it exists for test-client if the main binary
  hasn't been built.

* test/CMakeLists.txt: Split everything up into to builds, one for
  test-engine and the other for test-client. Use geary-engine-internal
  when building test-engine for access to internal classes and members.

* test/engine/util-idle-manager-test.vala,
  test/engine/util-timeout-manager-test.vala: Use Glib MainContext rather
  than the GTK main loop for pumping events so the test cases compile
  without GTK.

* test/test-engine.vala, test/test-client.vala: New main source file for
  test binaries based on old main.vala.
2017-12-18 14:49:04 +11:00