diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee index 54ebafca1..6cf1dd93b 100644 --- a/app/assets/javascripts/app/controllers/getting_started.js.coffee +++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee @@ -221,6 +221,7 @@ class Base extends App.ControllerContent url: url organization: organization ) + @$("input, select").first().focus() onLogoPick: (event) => reader = new FileReader() @@ -352,6 +353,7 @@ class ChannelEmail extends App.ControllerContent 'submit .js-inbound': 'probeInbound' 'change .js-outbound [name=adapter]': 'toggleOutboundAdapter' 'submit .js-outbound': 'probleOutbound' + 'click .js-back': 'goToSlide' constructor: -> super @@ -397,6 +399,7 @@ class ChannelEmail extends App.ControllerContent render: -> @html App.view('getting_started/email')() + @showSlide('js-intro') # outbound adapters = @@ -414,11 +417,10 @@ class ChannelEmail extends App.ControllerContent # inbound configureAttributesInbound = [ - { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'IMAP', pop3: 'POP3' } }, - { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, - { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, - { name: 'options::ssl', display: 'SSL', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' }, translate: true, default: true}, + { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { imap: 'IMAP', pop3: 'POP3' } }, + { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, + { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false }, + { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: false, autocapitalize: false, single: true }, ] new App.ControllerForm( el: @$('.base-inbound-settings'), @@ -437,11 +439,9 @@ class ChannelEmail extends App.ControllerContent adapter = @$('.js-outbound [name=adapter]').val() if adapter is 'smtp' configureAttributesOutbound = [ - { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['host']) }, - { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) }, - { name: 'options::password', display: 'Password', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['password']) }, - { name: 'options::ssl', display: 'SSL', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' } , translate: true, default: (channel_used['options']&&channel_used['options']['ssl']||true) }, - { name: 'options::port', display: 'Port', tag: 'input', type: 'text', limit: 5, null: false, class: 'span1', autocapitalize: false, default: ((channel_used['options']&&channel_used['options']['port']) || 25) }, + { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: false, autocapitalize: false, autofocus: true, default: (channel_used['options']&&channel_used['options']['host']) }, + { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false, default: (channel_used['options']&&channel_used['options']['user']) }, + { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false, single: true, default: (channel_used['options']&&channel_used['options']['password']) }, ] @form = new App.ControllerForm( el: @$('.base-outbound-settings') @@ -492,6 +492,8 @@ class ChannelEmail extends App.ControllerContent params = @formParam(e.target) @disable(e) + @showSlide('js-test') + @ajax( id: 'email_inbound' type: 'POST' @@ -509,9 +511,12 @@ class ChannelEmail extends App.ControllerContent @$('.js-outbound [name="options::password"]').val( @account['meta']['password'] ) else + @showSlide('js-inbound') @showAlert('js-inbound', data.message_human || data.message ) @enable(e) fail: => + @showSlide('js-inbound') + @showAlert('js-inbound', data.message_human || data.message ) @enable(e) ) @@ -523,6 +528,8 @@ class ChannelEmail extends App.ControllerContent params['email'] = @account['meta']['email'] @disable(e) + @showSlide('js-test') + @ajax( id: 'email_outbound' type: 'POST' @@ -537,9 +544,12 @@ class ChannelEmail extends App.ControllerContent @verify(@account) else + @showSlide('js-outbound') @showAlert('js-outbound', data.message_human || data.message ) @enable(e) fail: => + @showSlide('js-outbound') + @showAlert('js-outbound', data.message_human || data.message ) @enable(e) ) @@ -566,20 +576,24 @@ class ChannelEmail extends App.ControllerContent 2300 ) else - console.log('r', data, @account) if data.subject && @account @account.subject = data.subject @verify( @account, count + 1 ) - #@enable(e) fail: => - #@enable(e) + @showSlide('js-intro') + @showAlert('js-intro', 'Unable to verify sending and receiving. Please check your settings.' ) ) + goToSlide: (e) => + e.preventDefault() + slide = $(e.target).data('slide') + @showSlide(slide) showSlide: (name) => @hideAlert(name) @$('.setup.wizard').addClass('hide') @$(".setup.wizard.#{name}").removeClass('hide') + @$(".setup.wizard.#{name} input, .setup.wizard.#{name} select").first().focus() showAlert: (screen, message) => @$(".#{screen}").find('.alert').removeClass('hide').text( App.i18n.translateInline( message ) ) diff --git a/app/assets/javascripts/app/views/getting_started/email.jst.eco b/app/assets/javascripts/app/views/getting_started/email.jst.eco index bc57dabd4..53f004f2a 100644 --- a/app/assets/javascripts/app/views/getting_started/email.jst.eco +++ b/app/assets/javascripts/app/views/getting_started/email.jst.eco @@ -9,15 +9,15 @@
- +
- +
- +
@@ -39,6 +39,17 @@ +
+
+

<%- @T('Email Account') %>

+
+

+ <%- @T('Verifying...') %> +

+
+
+
+

<%- @T('Email Account') %>

@@ -59,7 +70,7 @@
- <%- @T('Go Back') %> + <%- @T('Go Back') %>
@@ -74,7 +85,7 @@
- <%- @T('Go Back') %> + <%- @T('Go Back') %>
diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index b23b7691b..7e10fe1ee 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -187,7 +187,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} domains = [domain] mail_exchangers = mxers(domain) if mail_exchangers && mail_exchangers[0] - puts "MX #{mail_exchangers} - #{mail_exchangers[0][0]}" + logger.info "MX for #{domain}: #{mail_exchangers} - #{mail_exchangers[0][0]}" end if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0] domains.push mail_exchangers[0][0] @@ -352,9 +352,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} settings = {} success = false inboundMap.each {|config| - puts "PROBE: #{config.inspect}" + logger.info "INBOUND PROBE: #{config.inspect}" result = email_probe_inbound( config ) - puts "RESULT: #{result.inspect}" + logger.info "INBOUND RESULT: #{result.inspect}" if result[:result] == 'ok' success = true settings[:inbound] = config @@ -501,9 +501,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} success = false outboundMap.each {|config| - puts "PROBE: #{config.inspect}" + logger.info "OUTBOUND PROBE: #{config.inspect}" result = email_probe_outbound( config, params[:email] ) - puts "RESULT: #{result.inspect}" + logger.info "OUTBOUND RESULT: #{result.inspect}" if result[:result] == 'ok' success = true settings[:outbound] = config @@ -576,15 +576,25 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} end result = email_probe_outbound( params[:outbound], params[:meta][:email], subject ) - (1..7).each {|loop| - sleep 7 + (1..5).each {|loop| + sleep 10 # fetch mailbox found = nil - if params[:inbound][:adapter] =~ /^imap$/i - found = Channel::IMAP.new.fetch( { :options => params[:inbound][:options] }, 'verify', subject ) - else - found = Channel::POP3.new.fetch( { :options => params[:inbound][:options] }, 'verify', subject ) + + begin + if params[:inbound][:adapter] =~ /^imap$/i + found = Channel::IMAP.new.fetch( { :options => params[:inbound][:options] }, 'verify', subject ) + else + found = Channel::POP3.new.fetch( { :options => params[:inbound][:options] }, 'verify', subject ) + end + rescue Exception => e + render :json => { + :result => 'invalid', + :message => e.to_s, + :subject => subject, + } + return end if found && found == 'verify ok' @@ -646,7 +656,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} end } - # check dilivery for 30 sek. + # check delivery for 30 sek. render :json => { :result => 'invalid', :message => 'Verification Email not found in mailbox.', @@ -687,11 +697,21 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} # test connection translationMap = { 'authentication failed' => 'Authentication failed!', + 'Incorrect username' => 'Authentication failed!', 'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!', 'No route to host' => 'No route to host!', 'Connection refused' => 'Connection refused!', } if params[:adapter] =~ /^smtp$/i + + # in case, fill missing params + if !params[:options].has_key?(:port) + params[:options][:port] = 25 + end + if !params[:options].has_key?(:ssl) + params[:options][:ssl] = true + end + begin Channel::SMTP.new.send( mail, @@ -773,11 +793,13 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} # connection test translationMap = { 'authentication failed' => 'Authentication failed!', + 'Incorrect username' => 'Authentication failed!', 'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!', 'No route to host' => 'No route to host!', 'Connection refused' => 'Connection refused!', } if params[:adapter] =~ /^imap$/i + begin Channel::IMAP.new.fetch( { :options => params[:options] }, 'check' ) rescue Exception => e diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index f39bbc31e..0d3fc7cd8 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -5,11 +5,11 @@ require 'net/imap' class Channel::IMAP < Channel::EmailParser def fetch (channel, check_type = '', verify_string = '') - ssl = false - port = 143 - if channel[:options][:ssl].to_s == 'true' - ssl = true - port = 993 + ssl = true + port = 993 + if channel[:options].has_key?(:ssl) && channel[:options][:ssl].to_s == 'false' + ssl = false + port = 143 end puts "fetching imap (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})" @@ -26,15 +26,15 @@ class Channel::IMAP < Channel::EmailParser end - # try LOGIN, if not - try plain - begin - @imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] ) - rescue Exception => e - if e.to_s !~ /unsupported\s(authenticate|authentication)\smechanism/i - raise e - end - @imap.login( channel[:options][:user], channel[:options][:password] ) + # try LOGIN, if not - try plain + begin + @imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] ) + rescue Exception => e + if e.to_s !~ /unsupported\s(authenticate|authentication)\smechanism/i + raise e end + @imap.login( channel[:options][:user], channel[:options][:password] ) + end if !channel[:options][:folder] || channel[:options][:folder].empty? @imap.select('INBOX') diff --git a/app/models/channel/pop3.rb b/app/models/channel/pop3.rb index 8324410a2..6a36704d9 100644 --- a/app/models/channel/pop3.rb +++ b/app/models/channel/pop3.rb @@ -5,11 +5,11 @@ require 'net/pop' class Channel::POP3 < Channel::EmailParser def fetch (channel, check_type = '', verify_string = '') - ssl = false - port = 110 - if channel[:options][:ssl].to_s == 'true' - ssl = true - port = 995 + ssl = true + port = 995 + if channel[:options].has_key?(:ssl) && channel[:options][:ssl].to_s == 'false' + ssl = false + port = 110 end puts "fetching pop3 (#{channel[:options][:host]}/#{channel[:options][:user]} port=#{port},ssl=#{ssl})" diff --git a/test/browser/aaa_getting_started_test.rb b/test/browser/aaa_getting_started_test.rb index e2d050e36..72f49f1ed 100644 --- a/test/browser/aaa_getting_started_test.rb +++ b/test/browser/aaa_getting_started_test.rb @@ -2,8 +2,13 @@ require 'browser_test_helper' class AaaGettingStartedTest < TestCase - def test_getting_started - tests = [ + def test_a_getting_started + if !ENV['MAILBOX_INIT'] + raise "Need MAILBOX_INIT as ENV variable like export MAILBOX_INIT='unittest01@znuny.com:somepass'" + end + mailbox_user = ENV['MAILBOX_INIT'].split(':')[0] + mailbox_password = ENV['MAILBOX_INIT'].split(':')[1] + tests = [ { :name => 'start', :instance => browser_instance, @@ -138,12 +143,12 @@ class AaaGettingStartedTest < TestCase { :execute => 'set', :css => '.js-intro input[name="email"]', - :value => 'otest01@znuny.com', + :value => mailbox_user, }, { :execute => 'set', :css => '.js-intro input[name="password"]', - :value => 'otest0142', + :value => mailbox_password, }, { :execute => 'click', @@ -153,16 +158,19 @@ class AaaGettingStartedTest < TestCase :execute => 'watch_for', :area => 'body', :value => 'testing', + :timeout => 60, }, { :execute => 'watch_for', :area => 'body', :value => 'verify', + :timeout => 70, }, { :execute => 'watch_for', :area => 'body', :value => 'invite', + :timeout => 60, }, { :execute => 'check', @@ -234,4 +242,199 @@ class AaaGettingStartedTest < TestCase ] browser_single_test(tests) end + + def test_b_accounts_auto + if !ENV['MAILBOX_AUTO1'] + raise "Need MAILBOX_AUTO1 as ENV variable like export MAILBOX_AUTO1='nicole.braun2015@gmail.com:somepass'" + end + mailbox_user = ENV['MAILBOX_AUTO1'].split(':')[0] + mailbox_password = ENV['MAILBOX_AUTO1'].split(':')[1] + accounts = [ + { + :realname => 'gmail', + :email => mailbox_user, + :password => mailbox_password, + }, + ] + accounts.each {|account| + tests = [ + { + :name => 'getting started - auto mail', + :action => [ + { + :execute => 'navigate', + :to => browser_url + '/#getting_started/channel', + }, + { + :execute => 'click', + :css => '.js-channel .email .provider_name', + }, + { + :execute => 'set', + :css => '.js-intro input[name="realname"]', + :value => account[:realname], + }, + { + :execute => 'set', + :css => '.js-intro input[name="email"]', + :value => account[:email], + }, + { + :execute => 'set', + :css => '.js-intro input[name="password"]', + :value => account[:password], + }, + { + :execute => 'click', + :css => '.js-intro .btn--primary', + }, + { + :execute => 'watch_for', + :area => 'body', + :value => 'testing', + }, + { + :execute => 'watch_for', + :area => 'body', + :value => 'verify', + :timeout => 80, + }, + { + :execute => 'watch_for', + :area => 'body', + :value => 'invite', + }, + { + :execute => 'check', + :element => :url, + :result => '#getting_started/agents', + }, + ], + }, + ] + browser_signle_test_with_login(tests, { :username => 'master@example.com' }) + } + end + + def test_b_accounts_manual + if !ENV['MAILBOX_MANUAL1'] + raise "Need MAILBOX_AUTO1 as ENV variable like export MAILBOX_MANUAL1='nicole.bauer2015@yahoo.de:somepass:imap.mail.yahoo.com:smtp.mail.yahoo.com'" + end + mailbox_user = ENV['MAILBOX_MANUAL1'].split(':')[0] + mailbox_password = ENV['MAILBOX_MANUAL1'].split(':')[1] + mailbox_inbound = ENV['MAILBOX_MANUAL1'].split(':')[2] + mailbox_outbound = ENV['MAILBOX_MANUAL1'].split(':')[3] + + accounts = [ + { + :realname => 'yahoo', + :email => mailbox_user, + :password => mailbox_password, + :inbound => { + 'options::host' => mailbox_inbound, + }, + :outbound => { + 'options::host' => mailbox_outbound, + }, + }, + ] + accounts.each {|account| + tests = [ + { + :name => 'getting started - manual mail', + :action => [ + { + :execute => 'navigate', + :to => browser_url + '/#getting_started/channel', + }, + { + :execute => 'click', + :css => '.js-channel .email .provider_name', + }, + { + :execute => 'set', + :css => '.js-intro input[name="realname"]', + :value => account[:realname], + }, + { + :execute => 'set', + :css => '.js-intro input[name="email"]', + :value => account[:email], + }, + { + :execute => 'set', + :css => '.js-intro input[name="password"]', + :value => account[:password], + }, + { + :execute => 'click', + :css => '.js-intro .btn--primary', + }, + { + :execute => 'watch_for', + :area => '.js-probe', + :value => 'testing', + }, + { + :execute => 'watch_for', + :area => '.js-inbound h2', + :value => 'inbound', + :timeout => 220, + }, + { + :execute => 'watch_for', + :area => '.js-inbound', + :value => 'manual', + }, + { + :execute => 'set', + :css => '.js-inbound input[name="options::host"]', + :value => account[:inbound]['options::host'], + }, + { + :execute => 'click', + :css => '.js-inbound .btn--primary', + }, + { + :execute => 'watch_for', + :area => '.js-outbound h2', + :value => 'outbound', + }, + { + :execute => 'select', + :css => '.js-outbound select[name="adapter"]', + :value => 'SMTP - configure your own outgoing SMTP settings', + }, + { + :execute => 'set', + :css => '.js-outbound input[name="options::host"]', + :value => account[:outbound]['options::host'], + }, + { + :execute => 'click', + :css => '.js-outbound .btn--primary', + }, + { + :execute => 'watch_for', + :area => 'body', + :value => 'verify', + }, + { + :execute => 'watch_for', + :area => 'body', + :value => 'invite', + :timeout => 190, + }, + { + :execute => 'check', + :element => :url, + :result => '#getting_started/agents', + }, + ], + }, + ] + browser_signle_test_with_login(tests, { :username => 'master@example.com' }) + } + end + end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 85239e7ad..2775e3ac6 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -254,7 +254,7 @@ class TestCase < Test::Unit::TestCase if action[:timeout] timeout = action[:timeout] end - loops = timeout / 0.33 + loops = (timeout / 0.5).to_i text = '' (1..loops).each { |loop| element = instance.find_element( { :css => action[:area] } ) @@ -266,7 +266,7 @@ class TestCase < Test::Unit::TestCase return end end - sleep 0.33 + sleep 0.5 } assert( false, "(#{test[:name]}) '#{action[:value]}' found in '#{text}'" ) return