@@ -84,6 +84,58 @@ class IMAPAuthenticateTest < Net::IMAP::TestCase
8484 end
8585 end
8686
87+ test ( "#authenticate without cached capabilities never sends initial response " \
88+ "when config.sasl_ir: :when_capabilities_cached" ) do
89+ [ true , false ] . each do |server_support |
90+ with_fake_server (
91+ preauth : false , cleartext_auth : true , sasl_ir : server_support ,
92+ greeting_capabilities : false ,
93+ ) do |server , imap |
94+ imap . config . sasl_ir = :when_capabilities_cached
95+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" )
96+ cmd , cont = 2 . times . map { server . commands . pop }
97+ assert_equal %w[ AUTHENTICATE PLAIN ] , [ cmd . name , *cmd . args ]
98+ assert_equal ( [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ,
99+ cont [ :continuation ] . strip )
100+ assert_empty server . commands
101+ end
102+ end
103+ end
104+
105+ test ( "#authenticate with cached capabilities sends an initial response " \
106+ "when config.sasl_ir: :when_capabilities_cached " \
107+ "and supported by both the mechanism and the server" ) do
108+ with_fake_server (
109+ preauth : false , cleartext_auth : true , sasl_ir : true ,
110+ greeting_capabilities : true ,
111+ ) do |server , imap |
112+ imap . config . sasl_ir = :when_capabilities_cached
113+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" )
114+ cmd = server . commands . pop
115+ assert_equal "AUTHENTICATE" , cmd . name
116+ assert_equal ( [ "PLAIN" , [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ] ,
117+ cmd . args )
118+ assert_empty server . commands
119+ end
120+ end
121+
122+ test ( "#authenticate with cached capabilities doesn't send initial response " \
123+ "when config.sasl_ir: :when_capabilities_cached " \
124+ "and not supported by the server" ) do
125+ with_fake_server (
126+ preauth : false , cleartext_auth : true , sasl_ir : false ,
127+ greeting_capabilities : true ,
128+ ) do |server , imap |
129+ imap . config . sasl_ir = :when_capabilities_cached
130+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" )
131+ cmd , cont = 2 . times . map { server . commands . pop }
132+ assert_equal %w[ AUTHENTICATE PLAIN ] , [ cmd . name , *cmd . args ]
133+ assert_equal ( [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ,
134+ cont [ :continuation ] . strip )
135+ assert_empty server . commands
136+ end
137+ end
138+
87139 test ( "#authenticate never sends an initial response " \
88140 "when config.sasl_ir: false" ) do
89141 [ true , false ] . each do |server_support |
0 commit comments