14812: Fixing up integration tests
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Fri, 28 Jun 2019 21:24:01 +0000 (17:24 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Mon, 1 Jul 2019 16:23:38 +0000 (12:23 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

13 files changed:
apps/workbench/app/controllers/jobs_controller.rb
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/models/arvados_api_client.rb
apps/workbench/app/views/jobs/_show_log.html.erb
apps/workbench/app/views/layouts/application.html.erb
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/config/application.default.yml
apps/workbench/config/arvados_config.rb
apps/workbench/lib/config_validators.rb
apps/workbench/test/integration/application_layout_test.rb
apps/workbench/test/integration/link_account_test.rb
apps/workbench/test/integration/user_profile_test.rb
apps/workbench/test/test_helper.rb

index 1701052c29ef0f47a7cd59e5badc8de9e5dc8e89..4f7bfcee53e5f11acceefc5c2a0d1707287143c1 100644 (file)
@@ -67,7 +67,7 @@ class JobsController < ApplicationController
 
   def logs
     @logs = @object.
-      stderr_log_query(Rails.configuration.RunningJobLogRecordsToFetch).
+      stderr_log_query(Rails.configuration.Workbench.RunningJobLogRecordsToFetch).
       map { |e| e.serializable_hash.merge({ 'prepend' => true }) }
     respond_to do |format|
       format.json { render json: @logs }
index 099189811a1b1fb199b5b1e265667383d00ef8d2..b27482c4cc47351bd474244205c8f60ea634f8ea 100644 (file)
@@ -202,7 +202,7 @@ class UsersController < ApplicationController
     respond_to do |format|
       if current_user.andand.is_admin
         setup_params = {}
-        setup_params[:send_notification_email] = "#{Rails.configuration.Users.SendUserSetupNotificationEmail}"
+        setup_params[:send_notification_email] = "#{Rails.configuration.Mail.SendUserSetupNotificationEmail}"
         if params['user_uuid'] && params['user_uuid'].size>0
           setup_params[:uuid] = params['user_uuid']
         end
index 3f619c9740387d94a5493830f6c933b12b3e9bd6..6be15c698746d0c073fe3394451ad03aedad1952 100644 (file)
@@ -235,15 +235,13 @@ class ArvadosApiClient
   end
 
   def arvados_login_url(params={})
-    if Rails.configuration.respond_to? :arvados_login_base
-      uri = Rails.configuration.Services.Controller.ExternalURL.to_s + "/login"
+    uri = URI.parse(Rails.configuration.Services.Controller.ExternalURL.to_s)
+    if Rails.configuration.testing_override_login_url
+      uri = URI(Rails.configuration.testing_override_login_url)
     end
-    if params.size > 0
-      uri += '?' << params.collect { |k,v|
-        CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s)
-      }.join('&')
-    end
-    uri
+    uri.path = "/login"
+    uri.query = URI.encode_www_form(params)
+    uri.to_s
   end
 
   def arvados_logout_url(params={})
@@ -251,7 +249,11 @@ class ArvadosApiClient
   end
 
   def arvados_v1_base
-    Rails.configuration.Services.Controller.ExternalURL.to_s + "/arvados/v1"
+    # workaround Ruby 2.3 bug, can't duplicate URI objects
+    # https://github.com/httprb/http/issues/388
+    u = URI.parse(Rails.configuration.Services.Controller.ExternalURL.to_s)
+    u.path = "/arvados/v1"
+    u.to_s
   end
 
   def discovery
index 10b7fa1c4eec3090c47a7ce60bacaf87b22ec8b8..237259fc1c936f4c6ad4d710711be65f7ebb7311 100644 (file)
@@ -80,6 +80,7 @@ var makeFilter = function() {
     load_log();
 
     function load_log() {
+        //console.log("fetching "+logcollection_url+" with "+ajax_opts);
         $.ajax(logcollection_url, ajax_opts).done(done).fail(fail);
     }
     function done(data, status, jqxhr) {
index df95b92f6f80479a6336ae9ca20fd7e49fa54ecd..bd3afbb681f098a1f3fe726e7d9bc49f671240ac 100644 (file)
@@ -20,7 +20,7 @@ SPDX-License-Identifier: AGPL-3.0 %>
   <meta name="author" content="">
   <% if current_user %>
     <% content_for :js do %>
-      window.defaultSession = <%=raw({baseURL: Rails.configuration.Services.Controller.ExternalURL, token: Thread.current[:arvados_api_token], user: current_user}.to_json)%>
+      window.defaultSession = <%=raw({baseURL: Rails.configuration.Services.Controller.ExternalURL.to_s, token: Thread.current[:arvados_api_token], user: current_user}.to_json)%>
     <% end %>
   <% end %>
   <% if current_user and $arvados_api_client.discovery[:websocketUrl] %>
index b20f16595b169617bebc271e246f6fb522cabab1..9da55cbeb3fedd36a3add088ab8a9d0e29607ed1 100644 (file)
@@ -72,9 +72,9 @@ SPDX-License-Identifier: AGPL-3.0 %>
                 </li>
                 <% if current_user.is_active %>
                 <li role="menuitem"><a href="/projects/<%=current_user.uuid%>" role="menuitem"><i class="fa fa-lg fa-home fa-fw"></i> Home project </a></li>
-                  <% if Rails.configuration.Services.Composer.ExternalURL %>
+                  <% if Rails.configuration.Services.Composer.ExternalURL != URI("") %>
                     <li role="menuitem">
-                     <form action="<%= Rails.configuration.Services.Composer.ExternalURL %>" method="GET">
+                     <form action="<%= Rails.configuration.Services.Composer.ExternalURL.to_s %>" method="GET">
                        <input type="hidden" name="api_token" value="<%= Thread.current[:arvados_api_token] %>" />
                        <button role="menuitem" type="submit">
                          <i class="fa fa-lg fa-share-alt fa-fw"></i> Workflow Composer
index d38742248b52fac025d72bf95f89c86e91c29380..2fa8442391a413ab53ca329620252e4a1ed67b03 100644 (file)
@@ -147,6 +147,7 @@ common:
   secret_key_base: false
   default_openid_prefix: https://www.google.com/accounts/o8/id
   send_user_setup_notification_email: true
+  testing_override_login_url: false
 
   # Scratch directory used by the remote repository browsing
   # feature. If it doesn't exist, it (and any missing parents) will be
index 914c3097bf260a2380b2f133d64cf8291e2b1266..c942884c1fd3ff8ea2aeeed9a6c0966b89b53379 100644 (file)
@@ -16,6 +16,7 @@
 # /etc/arvados/config.yml, you will be able to delete application.yml.
 
 require 'config_loader'
+require 'config_validators'
 
 begin
   # If secret_token.rb exists here, we need to load it first.
@@ -180,4 +181,5 @@ ArvadosWorkbench::Application.configure do
   ConfigLoader.copy_into_config $arvados_config, config
   ConfigLoader.copy_into_config $remaining_config, config
   secrets.secret_key_base = $arvados_config["Workbench"]["SecretKeyBase"]
+  ConfigValidators.validate_wb2_url_config()
 end
index ec769168c28ac2d6cdfb6ff77c5221c1bf557038..54f4b6db8c311c1827acc7edd2943f37db862f12 100644 (file)
@@ -5,24 +5,18 @@
 require 'uri'
 
 module ConfigValidators
-    def validate_wb2_url_config
-        if Rails.configuration.workbench2_url
-            begin
-                if !URI.parse(Rails.configuration.workbench2_url).is_a?(URI::HTTP)
-                    Rails.logger.warn("workbench2_url config is not an HTTP URL: #{Rails.configuration.workbench2_url}")
-                    Rails.configuration.workbench2_url = false
-                elsif /.*[\/]{2,}$/.match(Rails.configuration.workbench2_url)
-                    Rails.logger.warn("workbench2_url config shouldn't have multiple trailing slashes: #{Rails.configuration.workbench2_url}")
-                    Rails.configuration.workbench2_url = false
-                else
-                    return true
-                end
-            rescue URI::InvalidURIError
-                Rails.logger.warn("workbench2_url config invalid URL: #{Rails.configuration.workbench2_url}")
-                Rails.configuration.workbench2_url = false
-            end
+    def self.validate_wb2_url_config
+        if Rails.configuration.Services.Workbench2.ExternalURL != URI("")
+          if !Rails.configuration.Services.Workbench2.ExternalURL.is_a?(URI::HTTP)
+            Rails.logger.warn("workbench2_url config is not an HTTP URL: #{Rails.configuration.Services.Workbench2.ExternalURL}")
+            Rails.configuration.Services.Workbench2.ExternalURL = URI("")
+          elsif /.*[\/]{2,}$/.match(Rails.configuration.Services.Workbench2.ExternalURL.to_s)
+            Rails.logger.warn("workbench2_url config shouldn't have multiple trailing slashes: #{Rails.configuration.Services.Workbench2.ExternalURL}")
+            Rails.configuration.Services.Workbench2.ExternalURL = URI("")
+          else
+            return true
+          end
         end
         return false
     end
 end
-
index 0909157a9b1cb3f0ef7a2a6546b5d7634b8f5ca2..4ca146e680dee9b3d9ff1a2d3887ab0ae2670cca 100644 (file)
@@ -142,7 +142,7 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
   end
 
   [
-    [false, false],
+    ["", false],
     ['http://wb2.example.org//', false],
     ['ftp://wb2.example.org', false],
     ['wb2.example.org', false],
@@ -153,7 +153,7 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
   ].each do |wb2_url_config, wb2_menu_appear|
     test "workbench2_url=#{wb2_url_config} should#{wb2_menu_appear ? '' : ' not'} show WB2 menu" do
       Rails.configuration.Services.Workbench2.ExternalURL = URI(wb2_url_config)
-      assert_equal wb2_menu_appear, ConfigValidators::validate_wb2_url_config()
+      assert_equal wb2_menu_appear, ConfigValidators.validate_wb2_url_config()
 
       visit page_with_token('active')
       within('.navbar-fixed-top') do
@@ -213,7 +213,7 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
   end
 
   test "test arvados_public_data_doc_url config unset" do
-    Rails.configuration.Workbench.ArvadosPublicDataDocURL = false
+    Rails.configuration.Workbench.ArvadosPublicDataDocURL = ""
 
     visit page_with_token('active')
     within '.navbar-fixed-top' do
index 624ae13e476efff0234baf3f1078b7ce91074d92..53c7ec85532be6022d2dc89b35e09def57653f2b 100644 (file)
@@ -10,6 +10,10 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
     need_javascript
   end
 
+  teardown do
+    Rails.configuration.testing_override_login_url = false
+  end
+
   def start_sso_stub token
     port = available_port('sso_stub')
 
@@ -38,8 +42,7 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
 
   test "Add another login to this account" do
     visit page_with_token('active_trustedclient')
-    stub = start_sso_stub(api_fixture('api_client_authorizations')['project_viewer_trustedclient']['api_token'])
-    Rails.configuration.Services.Controller.ExternalURL = URI(stub)
+    Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['project_viewer_trustedclient']['api_token'])
 
     find("#notifications-menu").click
     assert_text "active-user@arvados.local"
@@ -58,8 +61,7 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
 
   test "Use this login to access another account" do
     visit page_with_token('project_viewer_trustedclient')
-    stub = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
-    Rails.configuration.Services.Controller.ExternalURL = URI(stub)
+    Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
 
     find("#notifications-menu").click
     assert_text "project-viewer@arvados.local"
@@ -78,8 +80,7 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
 
   test "Link login of inactive user to this account" do
     visit page_with_token('active_trustedclient')
-    stub = start_sso_stub(api_fixture('api_client_authorizations')['inactive_uninvited_trustedclient']['api_token'])
-    Rails.configuration.Services.Controller.ExternalURL = URI(stub)
+    Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['inactive_uninvited_trustedclient']['api_token'])
 
     find("#notifications-menu").click
     assert_text "active-user@arvados.local"
@@ -98,8 +99,7 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
 
   test "Cannot link to inactive user" do
     visit page_with_token('active_trustedclient')
-    stub = start_sso_stub(api_fixture('api_client_authorizations')['inactive_uninvited_trustedclient']['api_token'])
-    Rails.configuration.Services.Controller.ExternalURL = URI(stub)
+    Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['inactive_uninvited_trustedclient']['api_token'])
 
     find("#notifications-menu").click
     assert_text "active-user@arvados.local"
@@ -122,8 +122,7 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
 
   test "Inactive user can link to active account" do
     visit page_with_token('inactive_uninvited_trustedclient')
-    stub = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
-    Rails.configuration.Services.Controller.ExternalURL = URI(stub)
+    Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
 
     find("#notifications-menu").click
     assert_text "inactive-uninvited-user@arvados.local"
@@ -147,8 +146,7 @@ class LinkAccountTest < ActionDispatch::IntegrationTest
 
   test "Admin cannot link to non-admin" do
     visit page_with_token('admin_trustedclient')
-    stub = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
-    Rails.configuration.Services.Controller.ExternalURL = URI(stub)
+    Rails.configuration.testing_override_login_url = start_sso_stub(api_fixture('api_client_authorizations')['active_trustedclient']['api_token'])
 
     find("#notifications-menu").click
     assert_text "admin@arvados.local"
index 655cddf4e4f32f74a587c350b498d5c5b8b62905..9151b2ac4db9429f5cb401231152929235295158 100644 (file)
@@ -20,7 +20,7 @@ class UserProfileTest < ActionDispatch::IntegrationTest
     if !user
       assert_text('Please log in')
     elsif user['is_active']
-      if profile_config && !has_profile
+      if !profile_config.empty? && !has_profile
         assert_text('Save profile')
         add_profile user
       else
@@ -62,7 +62,7 @@ class UserProfileTest < ActionDispatch::IntegrationTest
             assert_selector('a', text: 'Current token')
             assert_selector('a', text: 'SSH keys')
 
-            if profile_config
+            if !profile_config.empty?
               assert_selector('a', text: 'Manage profile')
             else
               assert_no_selector('a', text: 'Manage profile')
@@ -142,7 +142,7 @@ class UserProfileTest < ActionDispatch::IntegrationTest
     [true, false].each do |profile_required|
       test "visit #{token} home page when profile is #{'not ' if !profile_required}configured" do
         if !profile_required
-          Rails.configuration.Workbench.UserProfileFormFields = false
+          Rails.configuration.Workbench.UserProfileFormFields = []
         else
           # Our test config enabled profile by default. So, no need to update config
         end
index 6d8474edae1935981ecf7957030c795bbc4c78ad..1d26deefa38bbe7c593d07d47dfe0d7d409cf49d 100644 (file)
@@ -64,7 +64,7 @@ class ActiveSupport::TestCase
     # Restore configuration settings changed during tests
     ConfigLoader.copy_into_config $arvados_config, Rails.configuration
     ConfigLoader.copy_into_config $remaining_config, Rails.configuration
-    Rails.configuration.Services.Controller.ExternalURL = "https://#{ENV['ARVADOS_API_HOST']}"
+    Rails.configuration.Services.Controller.ExternalURL = URI("https://#{ENV['ARVADOS_API_HOST']}")
     Rails.configuration.TLS.Insecure = true
   end
 end