gem "autoprefixer-rails"
# Use image_optim to optimise images
-gem "image_optim", ">= 0.22.0"
+gem "image_optim_rails"
# Load rails plugins
-gem "rails-i18n", "~> 4.0.0"
-gem "dynamic_form"
-gem "rinku", ">= 1.2.2", :require => "rails_rinku"
-gem "oauth-plugin", ">= 0.5.1"
-gem "validates_email_format_of", ">= 1.5.1"
+gem "actionpack-page_caching"
gem "composite_primary_keys", "~> 8.1.0"
-gem "http_accept_language", "~> 2.0.0"
-gem "paperclip", "~> 4.0"
gem "deadlock_retry", ">= 1.2.0"
+gem "dynamic_form"
+gem "http_accept_language", "~> 2.0.0"
gem "i18n-js", ">= 3.0.0.rc10"
+gem "oauth-plugin", ">= 0.5.1"
+gem "paperclip", "~> 4.0"
gem "rack-cors"
-gem "actionpack-page_caching"
+gem "rails-i18n", "~> 4.0.0"
+gem "rinku", ">= 1.2.2", :require => "rails_rinku"
+gem "validates_email_format_of", ">= 1.5.1"
# Sanitise URIs
gem "rack-uri_sanitizer"
# Omniauth for authentication
gem "omniauth"
-gem "omniauth-openid"
-gem "omniauth-google-oauth2", ">= 0.2.7"
gem "omniauth-facebook"
-gem "omniauth-windowslive"
gem "omniauth-github"
+gem "omniauth-google-oauth2", ">= 0.2.7"
+gem "omniauth-mediawiki", ">= 0.0.3"
+gem "omniauth-openid"
+gem "omniauth-windowslive"
# Markdown formatting support
gem "redcarpet"
gem "libxml-ruby", ">= 2.0.5", :require => "libxml"
# Use for HTML sanitisation
-gem "sanitize"
gem "htmlentities"
+gem "sanitize"
# Load SystemTimer for implementing request timeouts
gem "SystemTimer", ">= 1.1.3", :require => "system_timer", :platforms => :ruby_18
# Load geoip for querying Maxmind GeoIP database
gem "geoip"
+# Load rotp to generate TOTP tokens
+gem "rotp"
+
# Load memcache client in case we are using it
gem "dalli"
gem "kgio"
# Gems needed for running tests
group :test do
- gem "rubocop"
- gem "timecop"
gem "minitest", "~> 5.1", :platforms => [:ruby_19, :ruby_20]
+ gem "minitest-stub_any_instance"
+ gem "rubocop"
+ gem "timecop"
+ gem "webmock"
end
# Needed in development as well so rake can see konacha tasks
group :development, :test do
+ gem "coveralls", :require => false
+ gem "factory_girl_rails"
gem "jshint"
gem "konacha"
gem "poltergeist"
- gem "factory_girl_rails"
- gem "coveralls", :require => false
end
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
- actionpack-page_caching (1.0.2)
- actionpack (>= 4.0.0, < 5)
+ actionpack-page_caching (1.1.0)
+ actionpack (>= 4.0.0, < 6)
actionview (4.2.7.1)
activesupport (= 4.2.7.1)
builder (~> 3.1)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
- addressable (2.4.0)
- arel (6.0.3)
+ addressable (2.5.0)
+ public_suffix (~> 2.0, >= 2.0.2)
+ arel (6.0.4)
ast (2.3.0)
- autoprefixer-rails (6.5.1)
+ autoprefixer-rails (6.7.2)
execjs
bigdecimal (1.1.0)
- builder (3.2.2)
- capybara (2.10.1)
+ builder (3.2.3)
+ capybara (2.12.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
- climate_control (0.0.3)
- activesupport (>= 3.0)
+ climate_control (0.1.0)
cliver (0.3.2)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coffee-script (2.4.1)
coffee-script-source
execjs
- coffee-script-source (1.10.0)
+ coffee-script-source (1.12.2)
colorize (0.8.1)
composite_primary_keys (8.1.4)
activerecord (~> 4.2.0)
- concurrent-ruby (1.0.2)
- coveralls (0.8.15)
+ concurrent-ruby (1.0.4)
+ coveralls (0.8.19)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
- tins (>= 1.6.0, < 2)
+ tins (~> 1.6)
+ crack (0.4.3)
+ safe_yaml (~> 1.0.0)
crass (1.0.2)
dalli (2.7.6)
deadlock_retry (1.2.0)
erubis (2.7.0)
execjs (2.7.0)
exifr (1.2.5)
- factory_girl (4.7.0)
+ factory_girl (4.8.0)
activesupport (>= 3.0.0)
- factory_girl_rails (4.7.0)
- factory_girl (~> 4.7.0)
+ factory_girl_rails (4.8.0)
+ factory_girl (~> 4.8.0)
railties (>= 3.0.0)
- faraday (0.9.2)
+ faraday (0.10.1)
multipart-post (>= 1.2, < 3)
fspath (3.0.1)
- geoip (1.6.2)
+ geoip (1.6.3)
globalid (0.3.7)
activesupport (>= 4.1.0)
+ hashdiff (0.3.2)
hashie (3.4.6)
htmlentities (4.3.4)
http_accept_language (2.0.5)
- i18n (0.7.0)
- i18n-js (3.0.0.rc14)
+ i18n (0.8.0)
+ i18n-js (3.0.0.rc15)
i18n (~> 0.6, >= 0.6.6)
- image_optim (0.24.0)
+ image_optim (0.24.1)
exifr (~> 1.2, >= 1.2.2)
fspath (~> 3.0)
- image_size (~> 1.3)
+ image_size (~> 1.5)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
- image_size (1.4.2)
+ image_optim_rails (0.2.0)
+ image_optim (~> 0.24.0)
+ rails
+ sprockets
+ image_size (1.5.0)
in_threads (1.3.1)
- jquery-rails (4.2.1)
+ jquery-rails (4.2.2)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
- jshint (1.4.0)
+ jshint (1.5.0)
execjs (>= 1.4.0)
multi_json (~> 1.0)
therubyracer (~> 0.12.1)
- json (1.8.3)
+ json (1.8.6)
jsonify (0.3.1)
multi_json (~> 1.0)
jsonify-rails (0.3.2)
actionpack
jsonify (< 0.4.0)
jwt (1.5.6)
- kgio (2.10.0)
+ kgio (2.11.0)
konacha (4.0.0)
actionpack (>= 4.1, < 5)
capybara
sprockets (>= 2, < 4)
sprockets-rails (>= 2, < 4)
tilt
- libv8 (3.16.14.15)
+ libv8 (3.16.14.17)
libxml-ruby (2.9.0)
logstash-event (1.2.02)
- logstasher (1.0.1)
+ logstasher (1.1.1)
activerecord (>= 4.0)
activesupport (>= 4.0)
logstash-event (~> 1.2.0)
mime-types-data (3.2016.0521)
mimemagic (0.3.0)
mini_portile2 (2.1.0)
- minitest (5.9.1)
+ minitest (5.10.1)
+ minitest-stub_any_instance (1.0.1)
multi_json (1.12.1)
- multi_xml (0.5.5)
+ multi_xml (0.6.0)
multipart-post (2.0.0)
- nokogiri (1.6.8.1)
+ nokogiri (1.7.0.1)
mini_portile2 (~> 2.1.0)
- nokogumbo (1.4.9)
+ nokogumbo (1.4.10)
nokogiri
oauth (0.4.7)
oauth-plugin (0.5.1)
oauth (~> 0.4.4)
oauth2 (>= 0.5.0)
rack
- oauth2 (1.2.0)
- faraday (>= 0.8, < 0.10)
+ oauth2 (1.3.0)
+ faraday (>= 0.8, < 0.11)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
- omniauth (1.3.1)
+ omniauth (1.3.2)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-facebook (4.0.0)
omniauth-oauth2 (~> 1.2)
- omniauth-github (1.1.2)
- omniauth (~> 1.0)
- omniauth-oauth2 (~> 1.1)
+ omniauth-github (1.2.0)
+ omniauth (~> 1.3.2)
+ omniauth-oauth2 (>= 1.4.0, < 2.0)
omniauth-google-oauth2 (0.4.1)
jwt (~> 1.5.2)
multi_json (~> 1.3)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.3.1)
+ omniauth-mediawiki (0.0.3)
+ jwt (~> 1.0)
+ omniauth-oauth (~> 1.0)
+ omniauth-oauth (1.1.0)
+ oauth
+ omniauth (~> 1.0)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
- parser (2.3.1.4)
+ parser (2.3.3.1)
ast (~> 2.2)
pg (0.19.0)
- poltergeist (1.11.0)
+ poltergeist (1.13.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
powerpack (0.1.1)
- progress (3.2.2)
- psych (2.1.1)
+ progress (3.3.0)
+ psych (2.2.2)
+ public_suffix (2.0.5)
r2 (0.2.6)
- rack (1.6.4)
- rack-cors (0.4.0)
+ rack (1.6.5)
+ rack-cors (0.4.1)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
- rails-dom-testing (1.0.7)
+ rails-dom-testing (1.0.8)
activesupport (>= 4.2.0.beta, < 5.0)
- nokogiri (~> 1.6.0)
+ nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
activesupport (= 4.2.7.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
- rainbow (2.1.0)
- rake (11.3.0)
- redcarpet (3.3.4)
+ rainbow (2.2.1)
+ rake (12.0.0)
+ redcarpet (3.4.0)
ref (2.0.0)
- request_store (1.3.1)
+ request_store (1.3.2)
rinku (2.0.2)
- rubocop (0.44.1)
- parser (>= 2.3.1.1, < 3.0)
+ rotp (3.3.0)
+ rubocop (0.47.1)
+ parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-openid (2.7.0)
ruby-progressbar (1.8.1)
+ safe_yaml (1.0.4)
sanitize (4.4.0)
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (~> 1.4.1)
- sass (3.4.22)
+ sass (3.4.23)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
- sprockets (3.7.0)
+ sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
sprockets (>= 3.0.0)
term-ansicolor (1.4.0)
tins (~> 1.0)
- therubyracer (0.12.2)
- libv8 (~> 3.16.14.0)
+ therubyracer (0.12.3)
+ libv8 (~> 3.16.14.15)
ref
- thor (0.19.1)
+ thor (0.19.4)
thread_safe (0.3.5)
- tilt (2.0.5)
+ tilt (2.0.6)
timecop (0.8.1)
- tins (1.12.0)
+ tins (1.13.2)
tzinfo (1.2.2)
thread_safe (~> 0.1)
- uglifier (3.0.2)
+ uglifier (3.0.4)
execjs (>= 0.3.0, < 3)
- unicode-display_width (1.1.1)
+ unicode-display_width (1.1.3)
validates_email_format_of (1.6.3)
i18n
vendorer (0.1.16)
- websocket-driver (0.6.4)
+ webmock (2.3.2)
+ addressable (>= 2.3.6)
+ crack (>= 0.3.2)
+ hashdiff
+ websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
htmlentities
http_accept_language (~> 2.0.0)
i18n-js (>= 3.0.0.rc10)
- image_optim (>= 0.22.0)
+ image_optim_rails
jquery-rails
jshint
json
libxml-ruby (>= 2.0.5)
logstasher
minitest (~> 5.1)
+ minitest-stub_any_instance
oauth-plugin (>= 0.5.1)
omniauth
omniauth-facebook
omniauth-github
omniauth-google-oauth2 (>= 0.2.7)
+ omniauth-mediawiki (>= 0.0.3)
omniauth-openid
omniauth-windowslive
paperclip (~> 4.0)
rails-i18n (~> 4.0.0)
redcarpet
rinku (>= 1.2.2)
+ rotp
rubocop
sanitize
sass-rails (~> 5.0)
uglifier (>= 1.3.0)
validates_email_format_of (>= 1.5.1)
vendorer
+ webmock
BUNDLED WITH
- 1.10.6
+ 1.12.5
end
def test_findgpx_by_id
- trace = gpx_files(:anon_trace_file)
+ trace = create(:trace, :visibility => "private", :user => users(:public_user))
amf_content "findgpx", "/1", [trace.id, "test@example.com:test"]
post :amf_read
def test_findrelations_by_tags
visible_relation = current_relations(:visible_relation)
+ create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
used_relation = current_relations(:used_relation)
+ create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes")
+ create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation")
amf_content "findrelations", "/1", ["yes"]
post :amf_read
def test_map
node = current_nodes(:used_node_1)
+ tag = create(:node_tag, :node => node)
# Need to split the min/max lat/lon out into their own variables here
# so that we can test they are returned later.
minlon = node.lon - 0.1
assert_select "bounds[minlon='#{minlon}'][minlat='#{minlat}'][maxlon='#{maxlon}'][maxlat='#{maxlat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
- assert_select "tag[k='test'][v='yes']"
+ assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
assert_select "way", :count => 2
assert_select "way[id='1']", :count => 1
# the same as the node we are looking at
def test_map_inclusive
node = current_nodes(:used_node_1)
+ tag = create(:node_tag, :node => node)
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
get :map, :bbox => bbox
assert_response :success, "The map call should have succeeded"
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic
- assert_select "tag[k='test'][v='yes']"
+ assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end
assert_select "way", :count => 2
assert_select "way[id='1']", :count => 1
end
def test_tracepoints
- point = gpx_files(:public_trace_file)
+ point = create(:trace, :visibility => "public", :latitude => 1, :longitude => 1) do |trace|
+ create(:tracepoint, :trace => trace, :latitude => 1 * GeoRecord::SCALE, :longitude => 1 * GeoRecord::SCALE)
+ end
minlon = point.longitude - 0.001
minlat = point.latitude - 0.001
maxlon = point.longitude + 0.001
end
def test_tracepoints_trackable
- point = gpx_files(:trackable_trace_file)
+ point = create(:trace, :visibility => "trackable", :latitude => 51.51, :longitude => -0.14) do |trace|
+ create(:tracepoint, :trace => trace, :trackid => 1, :latitude => (51.510 * GeoRecord::SCALE).to_i, :longitude => (-0.140 * GeoRecord::SCALE).to_i)
+ create(:tracepoint, :trace => trace, :trackid => 2, :latitude => (51.511 * GeoRecord::SCALE).to_i, :longitude => (-0.141 * GeoRecord::SCALE).to_i)
+ end
minlon = point.longitude - 0.002
minlat = point.latitude - 0.002
maxlon = point.longitude + 0.002
end
def test_tracepoints_identifiable
- point = gpx_files(:identifiable_trace_file)
+ point = create(:trace, :visibility => "identifiable", :latitude => 51.512, :longitude => 0.142) do |trace|
+ create(:tracepoint, :trace => trace, :latitude => (51.512 * GeoRecord::SCALE).to_i, :longitude => (0.142 * GeoRecord::SCALE).to_i)
+ end
minlon = point.longitude - 0.002
minlat = point.latitude - 0.002
maxlon = point.longitude + 0.002
##
# setup oauth keys
def setup
- Object.const_set("ID_KEY", client_applications(:oauth_web_app).key)
- Object.const_set("POTLATCH2_KEY", client_applications(:oauth_web_app).key)
+ Object.const_set("ID_KEY", create(:client_application).key)
+ Object.const_set("POTLATCH2_KEY", create(:client_application).key)
+
+ stub_hostip_requests
end
##
# Test editing a specific GPX trace
def test_edit_with_gpx
user = users(:public_user)
- gpx = gpx_files(:public_trace_file)
+ gpx = create(:trace, :latitude => 1, :longitude => 1)
get :edit, { :gpx => gpx.id }, { :user => user.id }
assert_response :success
class UserControllerTest < ActionController::TestCase
api_fixtures
+ def setup
+ stub_hostip_requests
+ end
+
##
# test all routes which lead to this controller
def test_routes
def test_confirm_success_no_token_no_referer
user = users(:inactive_user)
+ stub_gravatar_request(user.email)
confirm_string = user.tokens.create.token
@request.cookies["_osm_session"] = user.display_name
def test_confirm_success_good_token_no_referer
user = users(:inactive_user)
+ stub_gravatar_request(user.email)
confirm_string = user.tokens.create.token
token = user.tokens.create.token
def test_confirm_success_bad_token_no_referer
user = users(:inactive_user)
+ stub_gravatar_request(user.email)
confirm_string = user.tokens.create.token
token = users(:normal_user).tokens.create.token
def test_confirm_success_no_token_with_referer
user = users(:inactive_user)
+ stub_gravatar_request(user.email)
confirm_string = user.tokens.create(:referer => diary_new_path).token
@request.cookies["_osm_session"] = user.display_name
def test_confirm_success_good_token_with_referer
user = users(:inactive_user)
+ stub_gravatar_request(user.email)
confirm_string = user.tokens.create(:referer => diary_new_path).token
token = user.tokens.create.token
def test_confirm_success_bad_token_with_referer
user = users(:inactive_user)
+ stub_gravatar_request(user.email)
confirm_string = user.tokens.create(:referer => diary_new_path).token
token = users(:normal_user).tokens.create.token
def test_confirm_email_success
user = users(:second_public_user)
+ stub_gravatar_request(user.new_email)
confirm_string = user.tokens.create.token
post :confirm_email, :confirm_string => confirm_string
# this happens when the email is actually changed
# which is triggered by the confirmation mail
def test_gravatar_auto_enable
- with_http_stubs "gravatar" do
- # switch to email that has a gravatar
- user = users(:first_gravatar_user)
- confirm_string = user.tokens.create.token
- # precondition gravatar should be turned off
- assert !user.image_use_gravatar
- post :confirm_email, :confirm_string => confirm_string
- assert_response :redirect
- assert_redirected_to :action => :account, :display_name => user.display_name
- assert_match /Confirmed your change of email address/, flash[:notice]
- # gravatar use should now be enabled
- assert User.find(users(:first_gravatar_user).id).image_use_gravatar
- end
+ # switch to email that has a gravatar
+ user = users(:first_gravatar_user)
+ stub_gravatar_request(user.new_email, 200)
+ confirm_string = user.tokens.create.token
+ # precondition gravatar should be turned off
+ assert !user.image_use_gravatar
+ post :confirm_email, :confirm_string => confirm_string
+ assert_response :redirect
+ assert_redirected_to :action => :account, :display_name => user.display_name
+ assert_match /Confirmed your change of email address/, flash[:notice]
+ # gravatar use should now be enabled
+ assert User.find(users(:first_gravatar_user).id).image_use_gravatar
end
def test_gravatar_auto_disable
- with_http_stubs "gravatar" do
- # switch to email without a gravatar
- user = users(:second_gravatar_user)
- confirm_string = user.tokens.create.token
- # precondition gravatar should be turned on
- assert user.image_use_gravatar
- post :confirm_email, :confirm_string => confirm_string
- assert_response :redirect
- assert_redirected_to :action => :account, :display_name => user.display_name
- assert_match /Confirmed your change of email address/, flash[:notice]
- # gravatar use should now be disabled
- assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
- end
+ # switch to email without a gravatar
+ user = users(:second_gravatar_user)
+ stub_gravatar_request(user.new_email, 404)
+ confirm_string = user.tokens.create.token
+ # precondition gravatar should be turned on
+ assert user.image_use_gravatar
+ post :confirm_email, :confirm_string => confirm_string
+ assert_response :redirect
+ assert_redirected_to :action => :account, :display_name => user.display_name
+ assert_match /Confirmed your change of email address/, flash[:notice]
+ # gravatar use should now be disabled
+ assert !User.find(users(:second_gravatar_user).id).image_use_gravatar
end
def test_terms_new_user
assert_select "form#accountForm > fieldset > div.form-row > select#user_preferred_editor > option[selected]", false
# Changing to an uploaded image should work
- image = Rack::Test::UploadedFile.new("test/traces/1.gif", "image/gif")
+ image = Rack::Test::UploadedFile.new("test/traces/a.gif", "image/gif")
post :account, { :display_name => user.display_name, :image_action => "new", :user => user.attributes.merge(:image => image) }, { :user => user.id }
assert_response :success
assert_template :account
end
def test_api_gpx_files
+ trace1 = create(:trace, :user => users(:normal_user)) do |trace|
+ create(:tracetag, :trace => trace, :tag => "London")
+ end
+ trace2 = create(:trace, :user => users(:normal_user)) do |trace|
+ create(:tracetag, :trace => trace, :tag => "Birmingham")
+ end
# check that nothing is returned when not logged in
get :api_gpx_files
assert_response :unauthorized
assert_equal "text/xml", response.content_type
# check the data that is returned
- assert_select "gpx_file[id='1']", 1 do
+ assert_select "gpx_file[id='#{trace1.id}']", 1 do
assert_select "tag", "London"
end
- assert_select "gpx_file[id='4']", 1 do
+ assert_select "gpx_file[id='#{trace2.id}']", 1 do
assert_select "tag", "Birmingham"
end
end
get :list, :page => 3
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => 25
+ assert_select "table#user_list tr", :count => 26
end
def test_list_post_confirm
require "test_helper"
class OAuthTest < ActionDispatch::IntegrationTest
- fixtures :users, :gpx_files
- set_fixture_class :gpx_files => Trace
- fixtures :users, :client_applications
++ fixtures :users
include OAuth::Helper
+ def setup
+ stub_hostip_requests
+ end
+
def test_oauth10_web_app
- client = client_applications(:oauth_web_app)
+ client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true)
post_via_redirect "/login", :username => client.user.email, :password => "test"
assert_response :success
oauth10_without_callback(client)
- oauth10_with_callback(client, "http://another.web.app.org/callback")
+ oauth10_with_callback(client, "http://another.web.app.example.org/callback")
oauth10_refused(client)
end
def test_oauth10_desktop_app
- client = client_applications(:oauth_desktop_app)
+ client = create(:client_application, :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true)
post_via_redirect "/login", :username => client.user.email, :password => "test"
assert_response :success
end
def test_oauth10a_web_app
- client = client_applications(:oauth_web_app)
+ client = create(:client_application, :callback_url => "http://some.web.app.example.org/callback", :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true)
post_via_redirect "/login", :username => client.user.email, :password => "test"
assert_response :success
oauth10a_without_callback(client)
- oauth10a_with_callback(client, "http://another.web.app.org/callback")
+ oauth10a_with_callback(client, "http://another.web.app.example.org/callback")
oauth10a_refused(client)
end
def test_oauth10a_desktop_app
- client = client_applications(:oauth_desktop_app)
+ client = create(:client_application, :user => users(:public_user), :allow_read_prefs => true, :allow_write_api => true, :allow_read_gpx => true)
post_via_redirect "/login", :username => client.user.email, :password => "test"
assert_response :success
assert_nil token.invalidated_at
assert_allowed token, [:allow_write_api, :allow_read_gpx]
- signed_get "/api/0.6/gpx/2", :consumer => client, :token => token
+ trace = create(:trace, :user => users(:public_user))
+ signed_get "/api/0.6/gpx/#{trace.id}", :consumer => client, :token => token
assert_response :success
signed_get "/api/0.6/user/details", :consumer => client, :token => token
if client.callback_url
assert_response :redirect
verifier = parse_verifier(response)
- assert_redirected_to "http://some.web.app.org/callback?oauth_token=#{token.token}&oauth_verifier=#{verifier}"
+ assert_redirected_to "http://some.web.app.example.org/callback?oauth_token=#{token.token}&oauth_verifier=#{verifier}"
else
assert_response :success
assert_template :authorize_success
signed_get "/api/0.6/user/preferences", :consumer => client, :token => token
assert_response :success
- signed_get "/api/0.6/gpx/2", :consumer => client, :token => token
+ trace = create(:trace, :user => users(:public_user))
+ signed_get "/api/0.6/gpx/#{trace.id}", :consumer => client, :token => token
assert_response :forbidden
post "/oauth/revoke", :token => token.token
assert_nil token.invalidated_at
assert_allowed token, [:allow_write_api, :allow_read_gpx]
- signed_get "/api/0.6/gpx/2", :consumer => client, :token => token
+ trace = create(:trace, :user => users(:public_user))
+ signed_get "/api/0.6/gpx/#{trace.id}", :consumer => client, :token => token
assert_response :success
signed_get "/api/0.6/user/details", :consumer => client, :token => token
assert_not_nil token.created_at
assert_nil token.authorized_at
assert_nil token.invalidated_at
- assert_equal options[:oauth_callback], token.callback_url
+ assert_equal_allowing_nil options[:oauth_callback], token.callback_url
assert_allowed token, client.permissions
token
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
+require "webmock/minitest"
load "composite_primary_keys/fixtures.rb"
module ActiveSupport
def self.api_fixtures
# print "setting up the api_fixtures"
fixtures :users, :user_roles
- fixtures :changesets, :changeset_tags
+ fixtures :changesets
fixtures :current_nodes, :nodes
set_fixture_class :current_nodes => Node
set_fixture_class :nodes => OldNode
- fixtures :current_node_tags, :node_tags
- set_fixture_class :current_node_tags => NodeTag
- set_fixture_class :node_tags => OldNodeTag
-
fixtures :current_ways
set_fixture_class :current_ways => Way
- fixtures :current_way_nodes, :current_way_tags
+ fixtures :current_way_nodes
set_fixture_class :current_way_nodes => WayNode
- set_fixture_class :current_way_tags => WayTag
fixtures :ways
set_fixture_class :ways => OldWay
- fixtures :way_nodes, :way_tags
+ fixtures :way_nodes
set_fixture_class :way_nodes => OldWayNode
- set_fixture_class :way_tags => OldWayTag
fixtures :current_relations
set_fixture_class :current_relations => Relation
- fixtures :current_relation_members, :current_relation_tags
+ fixtures :current_relation_members
set_fixture_class :current_relation_members => RelationMember
- set_fixture_class :current_relation_tags => RelationTag
fixtures :relations
set_fixture_class :relations => OldRelation
- fixtures :relation_members, :relation_tags
+ fixtures :relation_members
set_fixture_class :relation_members => OldRelationMember
- set_fixture_class :relation_tags => OldRelationTag
-
- fixtures :client_applications
- fixtures :gpx_files, :gps_points, :gpx_file_tags
- set_fixture_class :gpx_files => Trace
- set_fixture_class :gps_points => Tracepoint
- set_fixture_class :gpx_file_tags => Tracetag
-
fixtures :redactions
end
end
end
+ ##
+ # work round minitest insanity that causes it to tell you
+ # to use assert_nil to test for nil, which is fine if you're
+ # comparing to a nil constant but not if you're comparing
+ # an expression that might be nil sometimes
+ def assert_equal_allowing_nil(exp, act, msg = nil)
+ if exp.nil?
+ assert_nil act, msg
+ else
+ assert_equal exp, act, msg
+ end
+ end
+
##
# for some reason assert_equal a, b fails when the relations are
# actually equal, so this method manually checks the fields...
##
# execute a block with a given set of HTTP responses stubbed
def with_http_stubs(stubs_file)
- http_client_save = OSM.http_client
+ stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__))
+ stubs.each do |url, response|
+ stub_request(:get, Regexp.new(Regexp.quote(url))).to_return(:status => response["code"], :body => response["body"])
+ end
- begin
- stubs = YAML.load_file(File.expand_path("../http/#{stubs_file}.yml", __FILE__))
-
- OSM.http_client = Faraday.new do |builder|
- builder.adapter :test do |stub|
- stubs.each do |url, response|
- stub.get(url) { |_env| [response["code"], {}, response["body"]] }
- end
- end
- end
+ yield
+ end
- yield
- ensure
- OSM.http_client = http_client_save
+ def stub_gravatar_request(email, status = 200, body = nil)
+ hash = Digest::MD5.hexdigest(email.downcase)
+ url = "https://www.gravatar.com/avatar/#{hash}?d=404"
+ stub_request(:get, url).and_return(:status => status, :body => body)
+ end
+
+ def stub_hostip_requests
+ # Controller tests and integration tests use different IPs
+ stub_request(:get, "http://api.hostip.info/country.php?ip=0.0.0.0")
+ stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1")
+ end
+
+ def email_text_parts(message)
+ message.parts.each_with_object([]) do |part, text_parts|
+ if part.content_type.start_with?("text/")
+ text_parts.push(part)
+ elsif part.multipart?
+ text_parts.concat(email_text_parts(part))
+ end
end
end
end