1 require 'integration_helper'
3 class AnonymousAccessTest < ActionDispatch::IntegrationTest
4 # These tests don't do state-changing API calls. Save some time by
5 # skipping the database reset.
6 reset_api_fixtures :after_each_test, false
7 reset_api_fixtures :after_suite, true
13 def verify_homepage_anonymous_enabled user, is_active, has_profile
17 assert_text 'Unrestricted public data'
18 assert_selector 'a', text: 'Projects'
20 assert_text 'All required fields must be completed before you can proceed'
23 assert_text 'indicate that you have read and accepted the user agreement'
25 within('.navbar-fixed-top') do
26 assert_no_text 'You are viewing public data'
27 assert_selector 'a', text: "#{user['email']}"
28 find('a', text: "#{user['email']}").click
29 within('.dropdown-menu') do
30 assert_selector 'a', text: 'Log out'
34 assert_text 'Unrestricted public data'
35 within('.navbar-fixed-top') do
36 assert_text 'You are viewing public data'
37 anonymous_user = api_fixture('users')['anonymous']
38 assert_selector 'a', "#{anonymous_user['email']}"
39 find('a', text: "#{anonymous_user['email']}").click
40 within('.dropdown-menu') do
41 assert_selector 'a', text: 'Log out'
42 #assert_selector 'a', 'Log in'
49 [nil, nil, false, false],
50 ['inactive', api_fixture('users')['inactive'], false, false],
51 ['active', api_fixture('users')['active'], true, true],
52 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
53 ['admin', api_fixture('users')['admin'], true, true],
54 ].each do |token, user, is_active, has_profile|
55 test "visit public project as user #{token} when anonymous browsing is enabled" do
56 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
58 path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
63 visit page_with_token(token, path)
65 verify_homepage_anonymous_enabled user, is_active, has_profile
71 ['active', api_fixture('users')['active']],
72 ].each do |token, user, is_active|
73 test "visit public project as user #{token} when anonymous browsing is not enabled" do
74 Rails.configuration.anonymous_user_token = false
76 path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
80 visit page_with_token(token, path)
84 assert_text 'Unrestricted public data'
86 assert_text 'Please log in'
91 test "visit non-public project as anonymous when anonymous browsing is enabled and expect page not found" do
92 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
93 visit "/projects/#{api_fixture('groups')['aproject']['uuid']}/?public_data=true"
94 assert_text 'Not Found'