Ensure syntax errors are always reported by the deserialiser.
Add unit tests. * src/engine/imap/transport/imap-deserializer.vala (Deserialiser): Add a new EOL even handler to the FAILED state that is the one place where the deserialize_failure() signal is fired and that any existing params are reset. (Deserialiser::push_line): Remove signal calls and unused return value. Don't use EOS to detect NUL to avoid some confusion. Ensure an EOL event is always fired so that the FAILED EOF handler is always run. (Deserialiser::push_data): Remove signal calls and unused return value. (Deserialiser::flush_params): Don't bother returning a state, since we now always know what the next one should be when calling it. Only trigger the parameters_ready() signal if there is a valid parameter. Make logging consistent with the rest of the class. (Deserialiser::reset_params): New common method for resetting any existing deserialised message. (Deserialiser::on_literal_char): Minor tidy up. (Deserialiser::on_eos): Ensure that any existing param is sent on EOS so that any BYE+EOS sent by the server is picked up.
This commit is contained in:
parent
25e700d22a
commit
9ac2b05a23
2 changed files with 139 additions and 78 deletions
|
|
@ -23,10 +23,17 @@ class Geary.Imap.DeserializerTest : Gee.TestCase {
|
|||
add_test("test_cyrus_2_4_greeting", test_cyrus_2_4_greeting);
|
||||
add_test("test_aliyun_greeting", test_aliyun_greeting);
|
||||
|
||||
add_test("test_invalid_atom_prefix", test_invalid_atom_prefix);
|
||||
|
||||
add_test("test_gmail_flags", test_gmail_flags);
|
||||
add_test("test_gmail_permanent_flags", test_gmail_permanent_flags);
|
||||
add_test("test_cyrus_flags", test_cyrus_flags);
|
||||
|
||||
add_test("test_runin_special_flag", test_runin_special_flag);
|
||||
add_test("test_invalid_flag_prefix", test_invalid_flag_prefix);
|
||||
|
||||
add_test("test_instant_eos", test_instant_eos);
|
||||
add_test("test_bye_eos", test_bye_eos);
|
||||
}
|
||||
|
||||
public override void set_up() {
|
||||
|
|
@ -73,6 +80,15 @@ class Geary.Imap.DeserializerTest : Gee.TestCase {
|
|||
assert(message.to_string() == parsed);
|
||||
}
|
||||
|
||||
public void test_invalid_atom_prefix() {
|
||||
string flags = """* OK %atom""";
|
||||
this.stream.add_data(flags.data);
|
||||
this.stream.add_data(EOL.data);
|
||||
|
||||
this.process.begin(Expect.DESER_FAIL, (obj, ret) => { async_complete(ret); });
|
||||
this.process.end(async_result());
|
||||
}
|
||||
|
||||
public void test_gmail_flags() {
|
||||
string flags = """* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $NotPhishing $Phishing)""";
|
||||
this.stream.add_data(flags.data);
|
||||
|
|
@ -106,6 +122,50 @@ class Geary.Imap.DeserializerTest : Gee.TestCase {
|
|||
assert(message.to_string() == flags);
|
||||
}
|
||||
|
||||
public void test_runin_special_flag() {
|
||||
// since we must terminate a special flag upon receiving the
|
||||
// '*', the following atom will be treated as a run-on but
|
||||
// distinct atom.
|
||||
string flags = """* OK \*atom""";
|
||||
string expected = """* OK \* atom""";
|
||||
this.stream.add_data(flags.data);
|
||||
this.stream.add_data(EOL.data);
|
||||
|
||||
this.process.begin(Expect.MESSAGE, (obj, ret) => { async_complete(ret); });
|
||||
RootParameters? message = this.process.end(async_result());
|
||||
|
||||
assert(message.to_string() == expected);
|
||||
}
|
||||
|
||||
public void test_invalid_flag_prefix() {
|
||||
string flags = """* OK \%atom""";
|
||||
this.stream.add_data(flags.data);
|
||||
this.stream.add_data(EOL.data);
|
||||
|
||||
this.process.begin(Expect.DESER_FAIL, (obj, ret) => { async_complete(ret); });
|
||||
this.process.end(async_result());
|
||||
}
|
||||
|
||||
public void test_instant_eos() {
|
||||
this.process.begin(Expect.EOS, (obj, ret) => { async_complete(ret); });
|
||||
this.process.end(async_result());
|
||||
assert(this.deser.is_halted());
|
||||
}
|
||||
|
||||
public void test_bye_eos() {
|
||||
string bye = """* OK bye""";
|
||||
this.stream.add_data(bye.data);
|
||||
|
||||
bool eos = false;
|
||||
this.deser.eos.connect(() => { eos = true; });
|
||||
|
||||
this.process.begin(Expect.MESSAGE, (obj, ret) => { async_complete(ret); });
|
||||
RootParameters? message = this.process.end(async_result());
|
||||
assert(message.to_string() == bye);
|
||||
assert(eos);
|
||||
assert(this.deser.is_halted());
|
||||
}
|
||||
|
||||
protected async RootParameters? process(Expect expected) {
|
||||
RootParameters? message = null;
|
||||
bool eos = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue