~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/doveadm/dsync/test-dsync-proxy.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
2
 
 
3
 
#include "lib.h"
4
 
#include "array.h"
5
 
#include "str.h"
6
 
#include "mail-cache.h"
7
 
#include "dsync-proxy.h"
8
 
#include "test-dsync-common.h"
9
 
#include "test-common.h"
10
 
 
11
 
static void test_dsync_proxy_msg(void)
12
 
{
13
 
        static const char *test_keywords[] = {
14
 
                "kw1", "kw2", NULL
15
 
        };
16
 
        string_t *str;
17
 
        struct dsync_message msg_in, msg_out;
18
 
        const char *error;
19
 
        pool_t pool;
20
 
 
21
 
        memset(&msg_in, 0, sizeof(msg_in));
22
 
        memset(&msg_out, 0, sizeof(msg_out));
23
 
 
24
 
        pool = pool_alloconly_create("msg pool", 1024);
25
 
        str = t_str_new(256);
26
 
        msg_in.guid = "\t\001\r\nguid\t\001\n\r";
27
 
        msg_in.uid = (uint32_t)-1;
28
 
        msg_in.modseq = (uint64_t)-1;
29
 
        msg_in.save_date = (1U << 31)-1;
30
 
 
31
 
        test_begin("dsync proxy msg");
32
 
 
33
 
        /* no flags */
34
 
        dsync_proxy_msg_export(str, &msg_in);
35
 
        test_assert(dsync_proxy_msg_import(pool, str_c(str),
36
 
                                           &msg_out, &error) == 0);
37
 
        test_assert(dsync_messages_equal(&msg_in, &msg_out));
38
 
 
39
 
        /* expunged flag */
40
 
        msg_in.flags = DSYNC_MAIL_FLAG_EXPUNGED;
41
 
        str_truncate(str, 0);
42
 
        dsync_proxy_msg_export(str, &msg_in);
43
 
        test_assert(dsync_proxy_msg_import(pool, str_c(str),
44
 
                                           &msg_out, &error) == 0);
45
 
        test_assert(dsync_messages_equal(&msg_in, &msg_out));
46
 
 
47
 
        /* expunged flag and another flag */
48
 
        msg_in.flags = DSYNC_MAIL_FLAG_EXPUNGED | MAIL_DRAFT;
49
 
        str_truncate(str, 0);
50
 
        dsync_proxy_msg_export(str, &msg_in);
51
 
        test_assert(dsync_proxy_msg_import(pool, str_c(str),
52
 
                                           &msg_out, &error) == 0);
53
 
        test_assert(dsync_messages_equal(&msg_in, &msg_out));
54
 
 
55
 
        /* all flags, some keywords */
56
 
        msg_in.flags = MAIL_FLAGS_MASK;
57
 
        msg_in.keywords = test_keywords;
58
 
        str_truncate(str, 0);
59
 
        dsync_proxy_msg_export(str, &msg_in);
60
 
        test_assert(dsync_proxy_msg_import(pool, str_c(str),
61
 
                                           &msg_out, &error) == 0);
62
 
        test_assert(dsync_messages_equal(&msg_in, &msg_out));
63
 
 
64
 
        /* errors */
65
 
        test_assert(dsync_proxy_msg_import(pool, "0", &msg_out, &error) < 0);
66
 
        test_assert(dsync_proxy_msg_import(pool, "0\t0", &msg_out, &error) < 0);
67
 
        test_assert(dsync_proxy_msg_import(pool, "0\t0\t0", &msg_out, &error) < 0);
68
 
        test_assert(dsync_proxy_msg_import(pool, "0\t0\t0\t0", &msg_out, &error) < 0);
69
 
        test_assert(dsync_proxy_msg_import(pool, "0\t0\t0\t\\\t0", &msg_out, &error) < 0);
70
 
        test_assert(dsync_proxy_msg_import(pool, "0\t0\t0\t\\seen foo \\foo\t0", &msg_out, &error) < 0);
71
 
 
72
 
        /* flags */
73
 
        test_assert(dsync_proxy_msg_parse_flags(pool, "\\seen \\draft", &msg_out) == 0);
74
 
        test_assert(msg_out.flags == (MAIL_SEEN | MAIL_DRAFT));
75
 
        test_assert(dsync_proxy_msg_parse_flags(pool, "\\answered \\flagged", &msg_out) == 0);
76
 
        test_assert(msg_out.flags == (MAIL_ANSWERED | MAIL_FLAGGED));
77
 
        test_assert(dsync_proxy_msg_parse_flags(pool, "\\deleted \\recent", &msg_out) == 0);
78
 
        test_assert(msg_out.flags == (MAIL_DELETED | MAIL_RECENT));
79
 
        test_assert(dsync_proxy_msg_parse_flags(pool, "\\draft draft \\seen", &msg_out) == 0);
80
 
        test_assert(msg_out.flags == (MAIL_DRAFT | MAIL_SEEN));
81
 
        test_assert(strcasecmp(msg_out.keywords[0], "draft") == 0 && msg_out.keywords[1] == NULL);
82
 
 
83
 
        test_end();
84
 
        pool_unref(&pool);
85
 
}
86
 
 
87
 
static void test_dsync_proxy_mailbox(void)
88
 
{
89
 
        static struct mailbox_cache_field cache1 =
90
 
                { "cache1", MAIL_CACHE_DECISION_NO, 1234 };
91
 
        static struct mailbox_cache_field cache2 =
92
 
                { "cache2", MAIL_CACHE_DECISION_TEMP | MAIL_CACHE_DECISION_FORCED, 0 };
93
 
        string_t *str;
94
 
        struct dsync_mailbox box_in, box_out;
95
 
        const char *error;
96
 
        pool_t pool;
97
 
 
98
 
        memset(&box_in, 0, sizeof(box_in));
99
 
        memset(&box_out, 0, sizeof(box_out));
100
 
 
101
 
        pool = pool_alloconly_create("mailbox pool", 1024);
102
 
        str = t_str_new(256);
103
 
 
104
 
        test_begin("dsync proxy mailbox");
105
 
 
106
 
        /* test \noselect mailbox */
107
 
        box_in.name = "\t\001\r\nname\t\001\n\r";
108
 
        box_in.name_sep = '/';
109
 
        box_in.flags = DSYNC_MAILBOX_FLAG_NOSELECT;
110
 
        dsync_proxy_mailbox_export(str, &box_in);
111
 
        test_assert(dsync_proxy_mailbox_import(pool, str_c(str),
112
 
                                               &box_out, &error) == 0);
113
 
        test_assert(dsync_mailboxes_equal(&box_in, &box_out));
114
 
 
115
 
        /* real mailbox */
116
 
        i_assert(sizeof(box_in.mailbox_guid.guid) == sizeof(test_mailbox_guid1));
117
 
        memcpy(box_in.mailbox_guid.guid, test_mailbox_guid2, GUID_128_SIZE);
118
 
        box_in.flags = 24242 & ~DSYNC_MAILBOX_FLAG_NOSELECT;
119
 
        box_in.uid_validity = 0xf74d921b;
120
 
        box_in.uid_next = 73529472;
121
 
        box_in.highest_modseq = 0x123456789abcdef0ULL;
122
 
 
123
 
        str_truncate(str, 0);
124
 
        dsync_proxy_mailbox_export(str, &box_in);
125
 
        test_assert(dsync_proxy_mailbox_import(pool, str_c(str),
126
 
                                               &box_out, &error) == 0);
127
 
        test_assert(dsync_mailboxes_equal(&box_in, &box_out));
128
 
 
129
 
        /* limits */
130
 
        box_in.uid_next = (uint32_t)-1;
131
 
        box_in.highest_modseq = (uint64_t)-1;
132
 
 
133
 
        str_truncate(str, 0);
134
 
        dsync_proxy_mailbox_export(str, &box_in);
135
 
        test_assert(dsync_proxy_mailbox_import(pool, str_c(str),
136
 
                                               &box_out, &error) == 0);
137
 
        test_assert(dsync_mailboxes_equal(&box_in, &box_out));
138
 
 
139
 
        /* mailbox with cache fields */
140
 
        t_array_init(&box_in.cache_fields, 10);
141
 
        array_append(&box_in.cache_fields, &cache1, 1);
142
 
        array_append(&box_in.cache_fields, &cache2, 1);
143
 
 
144
 
        str_truncate(str, 0);
145
 
        dsync_proxy_mailbox_export(str, &box_in);
146
 
        test_assert(dsync_proxy_mailbox_import(pool, str_c(str),
147
 
                                               &box_out, &error) == 0);
148
 
        test_assert(dsync_mailboxes_equal(&box_in, &box_out));
149
 
 
150
 
        test_end();
151
 
        pool_unref(&pool);
152
 
}
153
 
 
154
 
static void test_dsync_proxy_guid(void)
155
 
{
156
 
        mailbox_guid_t guid_in, guid_out;
157
 
        string_t *str;
158
 
 
159
 
        test_begin("dsync proxy mailbox guid");
160
 
 
161
 
        str = t_str_new(128);
162
 
        memcpy(guid_in.guid, test_mailbox_guid1, sizeof(guid_in.guid));
163
 
        dsync_proxy_mailbox_guid_export(str, &guid_in);
164
 
        test_assert(dsync_proxy_mailbox_guid_import(str_c(str), &guid_out) == 0);
165
 
        test_assert(memcmp(guid_in.guid, guid_out.guid, sizeof(guid_in.guid)) == 0);
166
 
 
167
 
        test_assert(dsync_proxy_mailbox_guid_import("12345678901234567890123456789012", &guid_out) == 0);
168
 
        test_assert(dsync_proxy_mailbox_guid_import("1234567890123456789012345678901", &guid_out) < 0);
169
 
        test_assert(dsync_proxy_mailbox_guid_import("1234567890123456789012345678901g", &guid_out) < 0);
170
 
        test_assert(dsync_proxy_mailbox_guid_import("", &guid_out) < 0);
171
 
 
172
 
        test_end();
173
 
}
174
 
 
175
 
int main(void)
176
 
{
177
 
        static void (*test_functions[])(void) = {
178
 
                test_dsync_proxy_msg,
179
 
                test_dsync_proxy_mailbox,
180
 
                test_dsync_proxy_guid,
181
 
                NULL
182
 
        };
183
 
        return test_run(test_functions);
184
 
}