@@ -776,6 +776,91 @@ def test_id
776776 end
777777 end
778778
779+ test "#authenticate doesn't send initial response by default" do
780+ [ true , false ] . each do |server_support |
781+ with_fake_server (
782+ preauth : false , cleartext_auth : true , sasl_ir : server_support
783+ ) do |server , imap |
784+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" )
785+ cmd , cont = 2 . times . map { server . commands . pop }
786+ assert_equal %w[ AUTHENTICATE PLAIN ] , [ cmd . name , *cmd . args ]
787+ assert_equal ( [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ,
788+ cont [ :continuation ] . strip )
789+ assert_empty server . commands
790+ end
791+ end
792+ end
793+
794+ test "#authenticate(sasl_ir: false) doesn't send initial response " do
795+ [ true , false ] . each do |server_support |
796+ with_fake_server (
797+ preauth : false , cleartext_auth : true , sasl_ir : server_support
798+ ) do |server , imap |
799+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" , sasl_ir : false )
800+ cmd , cont = 2 . times . map { server . commands . pop }
801+ assert_equal %w[ AUTHENTICATE PLAIN ] , [ cmd . name , *cmd . args ]
802+ assert_equal ( [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ,
803+ cont [ :continuation ] . strip )
804+ assert_empty server . commands
805+ end
806+ end
807+ end
808+
809+ test "#authenticate(sasl_ir: :auto) doesn't send if server isn't capable" do
810+ with_fake_server (
811+ preauth : false , cleartext_auth : true , sasl_ir : false
812+ ) do |server , imap |
813+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" , sasl_ir : :auto )
814+ cmd , cont = 2 . times . map { server . commands . pop }
815+ assert_equal %w[ AUTHENTICATE PLAIN ] , [ cmd . name , *cmd . args ]
816+ assert_equal ( [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ,
817+ cont [ :continuation ] . strip )
818+ assert_empty server . commands
819+ end
820+ end
821+
822+ test "#authenticate(sasl_ir: :auto) sends if server is capable" do
823+ with_fake_server (
824+ preauth : false , cleartext_auth : true , sasl_ir : true
825+ ) do |server , imap |
826+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" , sasl_ir : true )
827+ cmd = server . commands . pop
828+ assert_equal "AUTHENTICATE" , cmd . name
829+ assert_equal ( [ "PLAIN" , [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ] ,
830+ cmd . args )
831+ assert_empty server . commands
832+ end
833+ end
834+
835+ test "#authenticate(sasl_ir: true) sends initial response" do
836+ [ true , false ] . each do |server_support |
837+ with_fake_server (
838+ preauth : false , cleartext_auth : true , sasl_ir : server_support
839+ ) do |server , imap |
840+ imap . authenticate ( "PLAIN" , "test_user" , "test-password" , sasl_ir : true )
841+ cmd = server . commands . pop
842+ assert_equal "AUTHENTICATE" , cmd . name
843+ assert_equal ( [ "PLAIN" , [ "\x00 test_user\x00 test-password" ] . pack ( "m0" ) ] ,
844+ cmd . args )
845+ assert_empty server . commands
846+ end
847+ end
848+ end
849+
850+ test "#authenticate(sasl_ir: true) doesn't send IR for incapable mechanism" do
851+ with_fake_server (
852+ preauth : false , cleartext_auth : true , sasl_ir : true
853+ ) do |server , imap |
854+ begin
855+ imap . authenticate ( "DIGEST-MD5" , "test_user" , "test-password" ,
856+ sasl_ir : true , warn_deprecation : false )
857+ rescue Net ::IMAP ::NoResponseError
858+ end
859+ cmd = server . commands . pop
860+ assert_equal %w[ AUTHENTICATE DIGEST-MD5 ] , [ cmd . name , *cmd . args ]
861+ end
862+ end
863+
779864 def test_uidplus_uid_expunge
780865 with_fake_server ( select : "INBOX" ,
781866 extensions : %i[ UIDPLUS ] ) do |server , imap |
0 commit comments