/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "net.h"
#include "imap-url.h"
#include "test-common.h"
struct valid_imap_url_test {
const char *url;
};
/* Valid IMAP URL tests */
{
.url = "imap://localhost",
.url_parsed = {
},{
.url = "imap://user@localhost",
.url_parsed = {
.userid = "user" }
},{
.url = "imap://user;AUTH=PLAIN@localhost",
.url_parsed = {
.userid = "user",
.auth_type = "PLAIN" }
},{
.url = "imap://;AUTH=PLAIN@localhost",
.url_parsed = {
.auth_type = "PLAIN" }
},{
.url = "imap://%68endri%6B;AUTH=GSS%41PI@%65%78%61%6d%70%6c%65.com",
.url_parsed = {
.userid = "hendrik",
.auth_type = "GSSAPI" }
},{
.url = "imap://user@localhost:993",
.url_parsed = {
.userid = "user",
.port = 993 }
},{
.url = "imap://user@127.0.0.1",
.url_parsed = {
.host = {
.name = "127.0.0.1",
.userid = "user" }
},{
.url = "imap://user@[::1]",
.url_parsed = {
.host = {
.name = "[::1]",
.userid = "user" }
},{
.url = "imap://user@4example.com:423",
.url_parsed = {
.userid = "user",
.port = 423 }
},{
.url = "imap://beelzebub@666.4example.com:999",
.url_parsed = {
.userid = "beelzebub",
.port = 999 }
},{
.url = "imap://user@example.com/",
.url_parsed = {
.userid = "user",
},{
.url = "imap://user@example.com/./",
.url_parsed = {
.userid = "user",
},{
.url = "imap://user@example.com/INBOX",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX" }
},{
.url = "imap://user@example.com/INBOX/",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX" }
},{
.url = "imap://user@example.com//",
.url_parsed = {
.userid = "user"}
},{
.url_parsed = {
.userid = "user",
},{
.url_parsed = {
.userid = "user",
.mailbox = "INBOX" }
},{
.url_parsed = {
.userid = "user",
.mailbox = "INBOX" }
},{
.url_parsed = {
.userid = "user",
},{
.url = "imap://user@example.com/INBOX.Trash",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX.Trash" }
},{
.url = "imap://user@example.com/INBOX%3BTrash",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX;Trash" }
},{
.url = "imap://user@example.com/INBOX;UIDVALIDITY=1341",
.url_parsed = {
.userid = "user",
},{
.url = "imap://user@example.com/INBOX/;UIDVALIDITY=23423",
.url_parsed = {
.userid = "user",
},{
.url_parsed = {
.userid = "user",
},{
.url_parsed = {
.userid = "user",
.uid = 16 }
},{
.url_parsed = {
.userid = "user",
.uid = 0 }
},{
.url_parsed = {
.userid = "user",
.uid = 0 }
},{
";UID=434/;SECTION=HEADER",
.url_parsed = {
.userid = "user",
},{
";UID=437/;SECTION=1.2.MIME",
.url_parsed = {
.userid = "user",
},{
.url_parsed = {
.userid = "user",
},{
.url_parsed = {
.userid = "user",
},{
.url_parsed = {
.userid = "user",
},{
";SECTION=HEADER.FIELDS%20(%22To%22%20%22From%22)",
.url_parsed = {
.userid = "user",
},{
";PARTIAL=10.250",
.url_parsed = {
.userid = "user",
},{
";SECTION=1.3.TEXT/;PARTIAL=0.34254",
.url_parsed = {
.userid = "hendrik",
},{
";UIDVALIDITY=534?SUBJECT%20%22Frop?%22",
.url_parsed = {
.userid = "hendrik",
.search_program = "SUBJECT \"Frop?\"" }
},{
.url_base = {
.userid = "user" },
.url_parsed = {
.userid = "hendrik",
},{
.url_base = {
.userid = "user" },
.url_parsed = {
.userid = "user",
},{
.url = "user@example.com",
.url_base = {
.userid = "user",
.url_parsed = {
.userid = "user",
},{
.url = "Drafts",
.url_base = {
.userid = "user",
.mailbox = "INBOX/" },
.url_parsed = {
.userid = "user",
},{
.url = "../Drafts",
.url_base = {
.userid = "user",
.url_parsed = {
.userid = "user",
},{
.url = "../Junk",
.url_base = {
.userid = "user",
.uidvalidity = 23452 },
.url_parsed = {
.userid = "user",
.uidvalidity = 0 }
},{
.url = "../Junk;UIDVALIDITY=23",
.url_base = {
.userid = "user",
.uidvalidity = 23452 },
.url_parsed = {
.userid = "user",
.uidvalidity = 23 }
},{
.url = "../../%23shared;UIDVALIDITY=23452",
.url_base = {
.userid = "user",
.uidvalidity = 764 },
.url_parsed = {
.userid = "user",
.mailbox = "#shared",
.uidvalidity = 23452 }
},{
.url = "../../%23news;UIDVALIDITY=546/;UID=456",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65 },
.url_parsed = {
.userid = "user",
.mailbox = "#news",
.uidvalidity = 546,
.uid = 456 }
},{
.url = "",
.url_base = {
.userid = "user",
.uidvalidity = 23452 },
.url_parsed = {
.userid = "user",
.uidvalidity = 23452 }
},{
.url = "",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65 },
.url_parsed = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65 }
},{
.url = "",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65,
.url_parsed = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65,
},{
.url = "",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65,
.url_parsed = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65,
},{
.url = ";UID=4767",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65 },
.url_parsed = {
.userid = "user",
.uidvalidity = 23452,
.uid = 4767 }
},{
.url = ";UID=4767",
.url_base = {
.userid = "user",
.uidvalidity = 23452},
.url_parsed = {
.userid = "user",
.uidvalidity = 23452,
.uid = 4767 }
},{
.url = "../;UID=4767",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65 },
.url_parsed = {
.userid = "user",
.mailbox = "INBOX",
.uidvalidity = 0,
.uid = 4767 }
},{
.url = "../;UID=4767/;SECTION=TEXT",
.url_base = {
.userid = "user",
.uidvalidity = 23452,
.uid = 65,
.section = "1.2.3.MIME" },
.url_parsed = {
.userid = "user",
.uidvalidity = 23452,
.uid = 4767,
.section = "TEXT" }
},{
.url = ";SECTION=TEXT",
.url_base = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.section = "1.2.3.MIME" },
.url_parsed = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.section = "TEXT" }
},{
.url = "..",
.url_base = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.url_parsed = {
.userid = "user",
.uidvalidity = 769,
.uid = 43 }
},{
.url = "../;SECTION=CC",
.url_base = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.url_parsed = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.section = "CC" }
},{
.url = "CC",
.url_base = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.url_parsed = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
},{
.url = ";PARTIAL=1024.1024",
.url_base = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.url_parsed = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
},{
.url = "../CC/;PARTIAL=0.512",
.url_base = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
.url_parsed = {
.userid = "user",
.uidvalidity = 769,
.uid = 43,
},{
.url = "imap://user@example.com/INBOX/;UID=377;URLAUTH=anonymous",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX",
.uid = 377,
.uauth_rumpurl = "imap://user@example.com/INBOX/;UID=377"
";URLAUTH=anonymous",
.uauth_access_application = "anonymous"}
},{
.url = "imap://user@example.com/INBOX/;UID=377"
";URLAUTH=anonymous:internal:4142434445464748494A4B4C4D4E4F5051525354",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX",
.uid = 377,
.uauth_rumpurl = "imap://user@example.com/INBOX/;UID=377"
";URLAUTH=anonymous",
.uauth_access_application = "anonymous",
.uauth_mechanism = "internal",
.uauth_token = (const unsigned char *)"ABCDEFGHIJKLMNOPQRST",
.uauth_token_size = 20}
},{
.url = "imap://user@example.com/INBOX/;UID=377"
";EXPIRE=2011-02-12T12:45:14+01:00"
";URLAUTH=user+frop:internal:4142434445464748494A4B4C4D4E4F5051525354",
.url_parsed = {
.userid = "user",
.mailbox = "INBOX",
.uid = 377,
.uauth_rumpurl = "imap://user@example.com/INBOX/;UID=377"
";EXPIRE=2011-02-12T12:45:14+01:00;URLAUTH=user+frop",
.uauth_access_application = "user",
.uauth_access_user = "frop",
.uauth_mechanism = "internal",
.uauth_token = (const unsigned char *)"ABCDEFGHIJKLMNOPQRST",
.uauth_token_size = 20}
}
};
static void test_imap_url_valid(void)
{
unsigned int i;
for (i = 0; i < valid_url_test_count; i++) T_BEGIN {
} else {
}
} else {
}
} else {
}
test_out_quiet("url->port = (unspecified)",
} else {
}
test_out_quiet("url->host.ip = (unspecified)",
} else {
test_out_quiet("url->host.ip = (valid)",
}
} else {
}
} else {
}
} else {
}
} else {
}
} else {
urlt->uauth_access_application) == 0);
}
} else {
urlt->uauth_access_user) == 0);
}
} else {
}
} else {
size_t i;
equal);
if (equal) {
for (i = 0; i < urlp->uauth_token_size; i++) {
break;
}
}
equal);
}
}
}
}
test_end();
} T_END;
}
struct invalid_imap_url_test {
const char *url;
};
{
},{
.url = "imap:/INBOX"
},{
.url = "imap://user@example.com/INBOX",
.url_base = {
.userid = "user" }
},{
.url = ""
},{
.url = "/INBOX/;UID=377"
},{
.url = "imap://user@example.com/INBOX/;UID=377/;SECTION=TEXT?ALL"
},{
.url = "imap://user@example.com/INBOX/?"
},{
.url = "imap://user@example.com/INBOX/#Fragment"
},{
.url = "imap://user@example.com/INBOX/\""
},{
.url = "imap:///INBOX"
},{
.url = "imap://[]/INBOX"
},{
.url = "imap://[v08.234:232:234:234:2221]/INBOX"
},{
.url = "imap://[1::34a:34:234::6]/INBOX"
},{
},{
},{
},{
},{
.url = "imap://user;ATH=frop@example.com"
},{
.url = "imap://user;AUTH=frop;friep@example.com"
},{
},{
.url = "imap://user:password@example.com"
},{
.url = "imap://user;AUTH=A:B@example.com"
},{
},{
.url = "imap://user%00@example.com"
},{
},{
.url = "imap://;AUTH=FR%etD@example.com"
},{
},{
.url = "imap://user;AUTH=%00@example.com"
},{
.url = "imap://example.com/INBOX/%00/"
},{
.url = "imap://example.com/INBOX/%0r/"
},{
.url = "imap://example.com/INBOX/Trash/%/"
},{
.url = "imap://example.com/INBOX;UIDVALIDITY=23423;FROP=friep/"
},{
.url = "imap://example.com/INBOX;UIDVALIDITY=0/;UID=377"
},{
.url = "imap://example.com/INBOX;UIDVALIDITY=/"
},{
.url = "imap://example.com/INBOX;UIDVALIDITY=33a/"
},{
.url = "imap://example.com/INBOX;FROP=friep/"
},{
.url = "imap://example.com/INBOX/;UID=377;FROP=friep/"
},{
.url = "imap://example.com/INBOX/;UID=0/"
},{
.url = "imap://example.com/INBOX/;UID=/"
},{
.url = "imap://example.com/INBOX/;UID=5e6/"
},{
.url = "imap://example.com/INBOX/;UID=35/;SECTION=ALL;FROP=43/"
},{
.url = "imap://example.com/INBOX/;UID=35/;SECTION=/"
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL="
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL=0."
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL=0.e10"
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL=.3"
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL=5t4.3"
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL=0.0"
},{
.url = "imap://example.com/INBOX/;UID=34/;PARTIAL=0.23409823409820938409823"
},{
.url = "imap://example.com/INBOX/;UID=377/;FROP=34"
},{
.url = "imap://example.com/INBOX/;UID=377;FROP=34"
},{
.url = "imap://example.com/INBOX/;UID=377;EXPIRE=2010-02-02T12:00:12Z"
},{
.url = "imap://example.com/INBOX/;UID=377"
";URLAUTH=anonymous:internal:0ad89fafd79f54afe4523f45aadf2afe"
},{
.url = "imap://example.com/INBOX/;UID=377;EXPIRE=2011-15-02T00:00:00Z"
";URLAUTH=anonymous:internal:0ad89fafd79f54afe4523f45aadf2afe",
},{
.url = "imap://example.com/INBOX/;UID=377;EXPIRE=2011-10-02T00:00:00Z",
},{
.url = "/INBOX/;UID=377;EXPIRE=2011-10-02T00:00:00Z"
";URLAUTH=anonymous:internal:0ad89fafd79f54afe4523f45aadf2afe",
},{
.url = "imap://example.com/INBOX/;UID=377;URLAUTH=",
},{
.url = "imap://example.com/INBOX/;UID=377"
";URLAUTH=:internal:0ad89fafd79f54afe4523f45aadf2afe",
},{
.url = "imap://example.com/INBOX/;UID=377"
";URLAUTH=user+:internal:0ad89fafd79f54afe4523f45aadf2afe",
},{
.url = "imap://example.com/INBOX/;UID=377"
";URLAUTH=+frop:internal:0ad89fafd79f54afe4523f45aadf2afe",
},{
.url = "imap://example.com/INBOX/;UID=377;URLAUTH=anonymous:",
},{
.url = "imap://example.com/INBOX/;UID=377"
";URLAUTH=anonymous::0ad89fafd79f54afe4523f45aadf2afe",
},{
.url = "imap://example.com/INBOX/;UID=377;URLAUTH=anonymous:internal:",
},{
.url = "imap://example.com/INBOX/;UID=377"
";URLAUTH=anonymous:internal:fd79f54afe4523",
},{
.url = "imap://example.com/INBOX/;UID=377;EXPIRE=2011-10-02T00:00:00Z"
";URLAUTH=anonymous:internal:0ad89fafd79f54afe4523q45aadf2afe",
},
};
static void test_imap_url_invalid(void)
{
unsigned int i;
for (i = 0; i < invalid_url_test_count; i++) T_BEGIN {
test_end();
} T_END;
}
static const char *parse_create_url_tests[] = {
"imap://host.example.com/",
"imap://10.0.0.1/",
"imap://[::1]/",
"imap://user@host.example.com/",
"imap://user@host.example.com:993/",
"imap://su%3auser@host.example.com/",
"imap://user;AUTH=PLAIN@host.example.com/",
"imap://user;AUTH=PLAIN@host.example.com/INBOX",
"imap://user;AUTH=PLAIN@host.example.com/INBOX/;UID=5",
"imap://user;AUTH=PLAIN@host.example.com/INBOX;UIDVALIDITY=15/;UID=5",
"imap://user;AUTH=PLAIN@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=TEXT",
"imap://user;AUTH=PLAIN@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=TEXT/;PARTIAL=1",
"imap://user;AUTH=PLAIN@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=TEXT/;PARTIAL=1.14",
"imap://user;AUTH=PLAIN@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=TEXT/;PARTIAL=1.14;URLAUTH=anonymous",
"imap://user;AUTH=PLAIN@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=TEXT/;PARTIAL=1.14;URLAUTH=user+username",
"imap://user;AUTH=PLAIN@host.example.com/INBOX?SUBJECT%20%22Frop?%22",
"imap://user%3ba@host.example.com/",
"imap://user%40example.com@host.example.com/",
"imap://user%40example.com;AUTH=STR%23ANGE@host.example.com/",
"imap://user@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=HEADER.FIELDS%20(DATE%20FROM)",
"imap://user@host.example.com/INBOX;UIDVALIDITY=15/;UID=5"
"/;SECTION=TEXT/;PARTIAL=1.14;URLAUTH=user+user%3bname",
};
static void test_imap_url_parse_create(void)
{
unsigned int i;
for (i = 0; i < parse_create_url_test_count; i++) T_BEGIN {
if (imap_url_parse
}
test_end();
} T_END;
}
int main(void)
{
static void (*const test_functions[])(void) = {
};
return test_run(test_functions);
}