Skip to content

Commit 0c1298b

Browse files
committed
♻️ Move FETCH msg-att response parser tests to yaml
BODY/BODYSTRUCTURE is very complicated and often buggy [requiring many workarounds and tests), so it's kept in its own file.
1 parent c94d92d commit 0c1298b

File tree

2 files changed

+79
-51
lines changed

2 files changed

+79
-51
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
:tests:
3+
test_fetch_msg_att_uid:
4+
:response: "* 1 FETCH (UID 92285)\r\n"
5+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
6+
name: FETCH
7+
data: !ruby/struct:Net::IMAP::FetchData
8+
seqno: 1
9+
attr:
10+
UID: 92285
11+
raw_data: "* 1 FETCH (UID 92285)\r\n"
12+
13+
test_fetch_msg_att_flags_and_uid:
14+
:response: "* 1 FETCH (FLAGS (\\Seen $MDNSent \\Flagged Custom) UID 5)\r\n"
15+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
16+
name: FETCH
17+
data: !ruby/struct:Net::IMAP::FetchData
18+
seqno: 1
19+
attr:
20+
FLAGS:
21+
- :Seen
22+
- "$MDNSent"
23+
- :Flagged
24+
- Custom
25+
UID: 5
26+
raw_data: "* 1 FETCH (FLAGS (\\Seen $MDNSent \\Flagged Custom) UID 5)\r\n"
27+
28+
test_invalid_fetch_msg_att_extra_space:
29+
:response: "* 1 FETCH (UID 92285 )\r\n"
30+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
31+
name: FETCH
32+
data: !ruby/struct:Net::IMAP::FetchData
33+
seqno: 1
34+
attr:
35+
UID: 92285
36+
raw_data: "* 1 FETCH (UID 92285 )\r\n"
37+
38+
test_fetch_msg_att_modseq:
39+
:comments: |
40+
[Bug #10119]
41+
:response: "* 1 FETCH (FLAGS (Seen) MODSEQ (12345) UID 5)\r\n"
42+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
43+
name: FETCH
44+
data: !ruby/struct:Net::IMAP::FetchData
45+
seqno: 1
46+
attr:
47+
FLAGS:
48+
- Seen
49+
MODSEQ: 12345
50+
UID: 5
51+
raw_data: "* 1 FETCH (FLAGS (Seen) MODSEQ (12345) UID 5)\r\n"
52+
53+
test_fetch_msg_att_rfc822:
54+
:response: "* 123 FETCH (RFC822 {5}\r\nfoo\r\n)\r\n"
55+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
56+
name: FETCH
57+
data: !ruby/struct:Net::IMAP::FetchData
58+
seqno: 123
59+
attr:
60+
RFC822: "foo\r\n"
61+
raw_data: "* 123 FETCH (RFC822 {5}\r\nfoo\r\n)\r\n"
62+
63+
test_invalid_fetch_msg_att_rfc822_with_brackets:
64+
:response: "* 123 FETCH (RFC822[] {5}\r\nfoo\r\n)\r\n"
65+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
66+
name: FETCH
67+
data: !ruby/struct:Net::IMAP::FetchData
68+
seqno: 123
69+
attr:
70+
RFC822: "foo\r\n"
71+
raw_data: "* 123 FETCH (RFC822[] {5}\r\nfoo\r\n)\r\n"
72+
73+
test_invalid_fetch_msg_att_unknown_fails:
74+
:test_type: :assert_parse_failure
75+
:response: "* 123 FETCH (UNKNOWN 92285)\r\n"
76+
:message: !ruby/regexp / for \{123\}/

test/net/imap/test_imap_response_parser.rb

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def teardown
3939
# RFC3501 §7.2.5: SEARCH response (obsolete in IMAP4rev2):
4040
generate_tests_from fixture_file: "search_responses.yml"
4141

42+
# §7.5.2: FETCH response, misc msg-att
43+
generate_tests_from fixture_file: "fetch_responses.yml"
44+
4245
# §7.5.2: FETCH response, BODYSTRUCTURE msg-att
4346
generate_tests_from fixture_file: "body_structure_responses.yml"
4447

@@ -81,50 +84,6 @@ def test_flag_xlist_inbox
8184
assert_equal [:Inbox], response.data.attr
8285
end
8386

84-
def test_msg_att_extra_space
85-
parser = Net::IMAP::ResponseParser.new
86-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
87-
* 1 FETCH (UID 92285)
88-
EOF
89-
assert_equal 92285, response.data.attr["UID"]
90-
91-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
92-
* 1 FETCH (UID 92285 )
93-
EOF
94-
assert_equal 92285, response.data.attr["UID"]
95-
end
96-
97-
def test_msg_att_parse_error
98-
parser = Net::IMAP::ResponseParser.new
99-
e = assert_raise(Net::IMAP::ResponseParseError) {
100-
parser.parse(<<EOF.gsub(/\n/, "\r\n"))
101-
* 123 FETCH (UNKNOWN 92285)
102-
EOF
103-
}
104-
assert_match(/ for \{123\}/, e.message)
105-
end
106-
107-
def test_msg_att_rfc822_text
108-
parser = Net::IMAP::ResponseParser.new
109-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
110-
* 123 FETCH (RFC822 {5}
111-
foo
112-
)
113-
EOF
114-
assert_equal("foo\r\n", response.data.attr["RFC822"])
115-
response = parser.parse(<<EOF.gsub(/\n/, "\r\n"))
116-
* 123 FETCH (RFC822[] {5}
117-
foo
118-
)
119-
EOF
120-
assert_equal("foo\r\n", response.data.attr["RFC822"])
121-
end
122-
123-
def assert_parseable(s)
124-
parser = Net::IMAP::ResponseParser.new
125-
parser.parse(s.gsub(/\n/, "\r\n"))
126-
end
127-
12887
def test_enable
12988
parser = Net::IMAP::ResponseParser.new
13089
response = parser.parse("* ENABLED SMTPUTF8\r\n")
@@ -146,13 +105,6 @@ def test_status
146105
assert_equal(1234, response.data.attr["UIDVALIDITY"])
147106
end
148107

149-
# [Bug #10119]
150-
def test_msg_att_modseq_data
151-
parser = Net::IMAP::ResponseParser.new
152-
response = parser.parse("* 1 FETCH (FLAGS (\Seen) MODSEQ (12345) UID 5)\r\n")
153-
assert_equal(12345, response.data.attr["MODSEQ"])
154-
end
155-
156108
def test_continuation_request_without_response_text
157109
parser = Net::IMAP::ResponseParser.new
158110
response = parser.parse("+\r\n")

0 commit comments

Comments
 (0)