Skip to content

Commit

Permalink
Merge pull request #1382 from bgeuken/add_proxy_test
Browse files Browse the repository at this point in the history
Add tests for check_user action, which also covers the proxy use case
  • Loading branch information
bgeuken committed Dec 1, 2015
2 parents d470e9f + 0025a9a commit 77cd7f1
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 100 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -10,7 +10,6 @@ env:
- TEST_SUITE=rubocop
- TEST_SUITE=api
- TEST_SUITE=webui
- TEST_SUITE=proxy_mode
matrix:
fast_finish: true
notifications:
Expand Down
6 changes: 0 additions & 6 deletions dist/ci/obs_testsuite_travis.sh
Expand Up @@ -25,12 +25,6 @@ if test -z "$SUBTEST"; then
webui)
bundle exec rake test:webui
;;
proxy_mode)
grep -v proxy_auth_mode config/options.yml > config/options.yml.tmp
echo "proxy_auth_mode: :on" >> config/options.yml.tmp
mv config/options.yml.tmp config/options.yml
bundle exec rake test:proxy_mode
;;
rubocop)
bundle exec rake rubocop
;;
Expand Down
20 changes: 0 additions & 20 deletions dist/obs-server.spec
Expand Up @@ -505,26 +505,6 @@ if ! bundle exec rake test:api test:webui ; then
kill $(cat memcached.pid)
exit 1
fi
# modify config to simulate login proxy
grep -v proxy_auth_mode config/options.yml > config/options.yml.tmp
echo "proxy_auth_mode: :on" >> config/options.yml.tmp
mv config/options.yml.tmp config/options.yml
mv log/test.log{,.old}
if ! bundle exec rake test:proxy_mode ; then
cat log/test.log
kill $(cat memcached.pid)
exit 1
fi
# modify config to simulate login proxy
grep -v proxy_auth_mode config/options.yml > config/options.yml.tmp
echo "proxy_auth_mode: :on" >> config/options.yml.tmp
mv config/options.yml.tmp config/options.yml
mv log/test.log{,.old}
if ! bundle exec rake test:proxy_mode ; then
cat log/test.log
kill $(cat memcached.pid)
exit 1
fi
kill $(cat memcached.pid) || :
popd

Expand Down
13 changes: 0 additions & 13 deletions src/api/app/middleware/proxy_mode_faker.rb

This file was deleted.

4 changes: 0 additions & 4 deletions src/api/config/environments/development.rb
Expand Up @@ -41,10 +41,6 @@
# rubocop:disable Metrics/LineLength
config.secret_key_base = '92b2ed725cb4d68cc5fbf86d6ba204f1dec4172086ee7eac8f083fb62ef34057f1b770e0722ade7b298837be7399c6152938627e7d15aca5fcda7a4faef91fc7'
# rubocop:enable Metrics/LineLength
if CONFIG['proxy_auth_mode'] == :on
CONFIG['proxy_auth_logout_page'] = '/'
config.middleware.use ProxyModeFaker
end
end

CONFIG['extended_backend_log'] = true
Expand Down
4 changes: 0 additions & 4 deletions src/api/config/environments/test.rb
Expand Up @@ -38,10 +38,6 @@
# rubocop:enable Metrics/LineLength

config.action_dispatch.rescue_responses.merge!('ActionController::InvalidAuthenticityToken' => 950 )
if CONFIG['proxy_auth_mode'] == :on
CONFIG['proxy_auth_logout_page'] = '/'
config.middleware.use ProxyModeFaker
end
end

CONFIG['source_host'] = "localhost"
Expand Down
8 changes: 0 additions & 8 deletions src/api/lib/tasks/test_webui.rake
Expand Up @@ -17,14 +17,6 @@ end

Rake::TestTask.new do |t|
t.libs << "test"
filelist = filelist.exclude("/proxy_mode/")
t.test_files = filelist
t.name = 'test:webui'
end

Rake::TestTask.new do |t|
t.libs << "test"
proxy_mode_files = FileList.new
t.test_files = proxy_mode_files.include("test/functional/**/*proxy_mode*")
t.name = 'test:proxy_mode'
end
30 changes: 23 additions & 7 deletions src/api/test/functional/webui/login_test.rb
Expand Up @@ -32,14 +32,30 @@ def change_user_real_name new_name
end

def test_login_as_user
# pretty useless actually :)
login_Iggy
logout
end
use_js

def test_login_as_second_user
login_tom
logout
# Login via login page
visit user_login_path
fill_in "Username", with: "tom"
fill_in "Password", with: "buildservice"
click_button("Log In")

assert_equal "tom", find('#link-to-user-home').text

within("div#subheader") do
click_link("Logout")
end
assert_not page.has_css?("a#link-to-user-home")

# Login via widget, and different user
click_link("Log In")
within("div#login-form") do
fill_in "Username", with: "king"
fill_in "Password", with: "sunflower"
click_button("Log In")
end

assert_equal "king", find('#link-to-user-home').text
end

def test_login_invalid_entry
Expand Down
37 changes: 0 additions & 37 deletions src/api/test/functional/webui/proxy_mode_test.rb

This file was deleted.

41 changes: 41 additions & 0 deletions src/api/test/functional/webui/webui_controller_test.rb
@@ -0,0 +1,41 @@
require_relative '../../test_helper'

class Webui::WebuiControllerTest < Webui::IntegrationTest
setup do
@before = CONFIG['proxy_auth_mode']
# Fake proxy mode
CONFIG['proxy_auth_mode'] = :on
end

teardown do
CONFIG['proxy_auth_mode'] = @before
end

def test_check_user_in_proxy
use_js

# No user set by proxy
visit search_path
page.must_have_text "Log In"

# Existing OBS user
page.driver.add_header('X_USERNAME', 'tom')

visit search_path
assert_equal "tom", find('#link-to-user-home').text, "Should log in existing users"

# New OBS user
page.driver.add_header('X_USERNAME', 'new_user')
page.driver.add_header('X_EMAIL', 'new_user@obs.com')
page.driver.add_header('X_FIRSTNAME', 'Bob')
page.driver.add_header('X_LASTNAME', 'Geldof')

visit search_path

user = User.find_by(login: "new_user")
assert user, "Should create a new user"
assert_equal "Bob Geldof", user.realname
assert_equal "new_user@obs.com", user.email
assert_equal "new_user", find('#link-to-user-home').text, "Should log in new user"
end
end

0 comments on commit 77cd7f1

Please sign in to comment.