Skip to content

Commit fdd7282

Browse files
committed
♻️ Move CAPABILITY response[code] parser tests to yaml
Add new examples from RFC3501 as well.
1 parent 0f84982 commit fdd7282

File tree

2 files changed

+67
-20
lines changed

2 files changed

+67
-20
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
:tests:
3+
4+
test_capability_rfc3501_6.1.1_example_1:
5+
:response: "* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r\n"
6+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
7+
name: CAPABILITY
8+
data:
9+
- IMAP4REV1
10+
- STARTTLS
11+
- AUTH=GSSAPI
12+
- LOGINDISABLED
13+
raw_data: "* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r\n"
14+
15+
test_capability_rfc3501_6.1.1_example_2:
16+
:response: "* CAPABILITY IMAP4rev1 AUTH=GSSAPI AUTH=PLAIN\r\n"
17+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
18+
name: CAPABILITY
19+
data:
20+
- IMAP4REV1
21+
- AUTH=GSSAPI
22+
- AUTH=PLAIN
23+
raw_data: "* CAPABILITY IMAP4rev1 AUTH=GSSAPI AUTH=PLAIN\r\n"
24+
25+
test_invalid_capability_extra_space_at_end:
26+
:comment: |
27+
[Bug #8415]
28+
:quirky_server: Apple iCloud
29+
:response: "* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1
30+
SASL-IR AUTH=ATOKEN AUTH=PLAIN \r\n"
31+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
32+
name: CAPABILITY
33+
data:
34+
- ST11P00MM-ISCREAM009
35+
- 1Q49
36+
- XAPPLEPUSHSERVICE
37+
- IMAP4
38+
- IMAP4REV1
39+
- SASL-IR
40+
- AUTH=ATOKEN
41+
- AUTH=PLAIN
42+
raw_data: "* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1
43+
SASL-IR AUTH=ATOKEN AUTH=PLAIN \r\n"
44+
45+
test_capability_response_code_with_valid_atoms:
46+
:response: "* OK [CAPABILITY IMAP4rev1 SASL-IR 1234 NIL THIS+THAT + AUTH=PLAIN
47+
ID] IMAP4rev1 Hello\r\n"
48+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
49+
name: OK
50+
data: !ruby/struct:Net::IMAP::ResponseText
51+
code: !ruby/struct:Net::IMAP::ResponseCode
52+
name: CAPABILITY
53+
data:
54+
- IMAP4REV1
55+
- SASL-IR
56+
- '1234'
57+
- NIL
58+
- THIS+THAT
59+
- "+"
60+
- AUTH=PLAIN
61+
- ID
62+
text: IMAP4rev1 Hello
63+
raw_data: "* OK [CAPABILITY IMAP4rev1 SASL-IR 1234 NIL THIS+THAT + AUTH=PLAIN
64+
ID] IMAP4rev1 Hello\r\n"

test/net/imap/test_imap_response_parser.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def teardown
2727
############################################################################
2828
# Core IMAP, by RFC9051 section (w/obsolete in relative RFC3501 section):
2929

30+
# §7.2.2: CAPABILITY response
31+
generate_tests_from fixture_file: "capability_responses.yml"
32+
3033
# §7.3.2: NAMESPACE response (also RFC2342)
3134
generate_tests_from fixture_file: "namespace_responses.yml"
3235

@@ -129,26 +132,6 @@ def test_acl
129132
assert_equal("lrswickxteda", response.data[0].rights)
130133
end
131134

132-
# [Bug #8415]
133-
def test_capability
134-
parser = Net::IMAP::ResponseParser.new
135-
response = parser.parse("* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN\r\n")
136-
assert_equal("CAPABILITY", response.name)
137-
assert_equal("AUTH=PLAIN", response.data.last)
138-
response = parser.parse("* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN \r\n")
139-
assert_equal("CAPABILITY", response.name)
140-
assert_equal("AUTH=PLAIN", response.data.last)
141-
response = parser.parse("* OK [CAPABILITY IMAP4rev1 SASL-IR 1234 NIL THIS+THAT + AUTH=PLAIN ID] IMAP4rev1 Hello\r\n")
142-
assert_equal("OK", response.name)
143-
assert_equal("IMAP4rev1 Hello", response.data.text)
144-
code = response.data.code
145-
assert_equal("CAPABILITY", code.name)
146-
assert_equal(
147-
["IMAP4REV1", "SASL-IR", "1234", "NIL", "THIS+THAT", "+", "AUTH=PLAIN", "ID"],
148-
code.data
149-
)
150-
end
151-
152135
def test_enable
153136
parser = Net::IMAP::ResponseParser.new
154137
response = parser.parse("* ENABLED SMTPUTF8\r\n")

0 commit comments

Comments
 (0)