parent
e1cac818b1
commit
8a6e8ae128
9 changed files with 38 additions and 81 deletions
|
@ -1,7 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class OauthClientsControllerTest < ActionController::TestCase
|
||||
fixtures :users, :client_applications
|
||||
fixtures :users
|
||||
|
||||
##
|
||||
# test all routes which lead to this controller
|
||||
|
@ -38,6 +38,7 @@ class OauthClientsControllerTest < ActionController::TestCase
|
|||
|
||||
def test_index
|
||||
user = users(:public_user)
|
||||
create_list(:client_application, 2, :user => user)
|
||||
|
||||
get :index, :display_name => user.display_name
|
||||
assert_response :redirect
|
||||
|
@ -104,13 +105,14 @@ class OauthClientsControllerTest < ActionController::TestCase
|
|||
|
||||
def test_show
|
||||
user = users(:public_user)
|
||||
client = client_applications(:oauth_web_app)
|
||||
client = create(:client_application, :user => user)
|
||||
other_client = create(:client_application)
|
||||
|
||||
get :show, :display_name => user.display_name, :id => client.id
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => oauth_client_path(:display_name => user.display_name, :id => client.id))
|
||||
|
||||
get :show, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
|
||||
get :show, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
|
||||
assert_response :not_found
|
||||
assert_template "not_found"
|
||||
|
||||
|
@ -121,13 +123,14 @@ class OauthClientsControllerTest < ActionController::TestCase
|
|||
|
||||
def test_edit
|
||||
user = users(:public_user)
|
||||
client = client_applications(:oauth_web_app)
|
||||
client = create(:client_application, :user => user)
|
||||
other_client = create(:client_application)
|
||||
|
||||
get :edit, :display_name => user.display_name, :id => client.id
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => edit_oauth_client_path(:display_name => user.display_name, :id => client.id))
|
||||
|
||||
get :edit, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
|
||||
get :edit, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
|
||||
assert_response :not_found
|
||||
assert_template "not_found"
|
||||
|
||||
|
@ -147,12 +150,13 @@ class OauthClientsControllerTest < ActionController::TestCase
|
|||
|
||||
def test_update
|
||||
user = users(:public_user)
|
||||
client = client_applications(:oauth_web_app)
|
||||
client = create(:client_application, :user => user)
|
||||
other_client = create(:client_application)
|
||||
|
||||
put :update, :display_name => user.display_name, :id => client.id
|
||||
assert_response :forbidden
|
||||
|
||||
put :update, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
|
||||
put :update, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
|
||||
assert_response :not_found
|
||||
assert_template "not_found"
|
||||
|
||||
|
@ -181,7 +185,8 @@ class OauthClientsControllerTest < ActionController::TestCase
|
|||
|
||||
def test_destroy
|
||||
user = users(:public_user)
|
||||
client = client_applications(:oauth_web_app)
|
||||
client = create(:client_application, :user => user)
|
||||
other_client = create(:client_application)
|
||||
|
||||
assert_difference "ClientApplication.count", 0 do
|
||||
delete :destroy, :display_name => user.display_name, :id => client.id
|
||||
|
@ -189,7 +194,7 @@ class OauthClientsControllerTest < ActionController::TestCase
|
|||
assert_response :forbidden
|
||||
|
||||
assert_difference "ClientApplication.count", 0 do
|
||||
delete :destroy, { :display_name => user.display_name, :id => client_applications(:normal_user_app).id }, { :user => user }
|
||||
delete :destroy, { :display_name => user.display_name, :id => other_client.id }, { :user => user }
|
||||
end
|
||||
assert_response :not_found
|
||||
assert_template "not_found"
|
||||
|
|
|
@ -6,8 +6,8 @@ class SiteControllerTest < ActionController::TestCase
|
|||
##
|
||||
# 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
|
||||
|
|
6
test/factories/client_applications.rb
Normal file
6
test/factories/client_applications.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :client_application do
|
||||
sequence(:name) { |n| "Client application #{n}" }
|
||||
sequence(:url) { |n| "http://example.com/app/#{n}" }
|
||||
end
|
||||
end
|
50
test/fixtures/client_applications.yml
vendored
50
test/fixtures/client_applications.yml
vendored
|
@ -1,50 +0,0 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
oauth_web_app:
|
||||
name: Some OAuth Web App
|
||||
created_at: "2009-04-21 00:00:00"
|
||||
support_url: http://some.web.app.org/support
|
||||
updated_at: "2009-04-21 00:00:00"
|
||||
callback_url: http://some.web.app.org/callback
|
||||
url: http://some.web.app.org/
|
||||
user_id: 2
|
||||
secret: Ur1s9LWWJJuYBiV9cDi3za3OV8TGCoRgUvVXJ5zp7pc
|
||||
key: ewvENqsaTXFnZbMWmGDX2g
|
||||
allow_read_prefs: true
|
||||
allow_write_prefs: false
|
||||
allow_write_diary: false
|
||||
allow_write_api: true
|
||||
allow_read_gpx: true
|
||||
allow_write_gpx: false
|
||||
|
||||
oauth_desktop_app:
|
||||
name: Some OAuth Desktop App
|
||||
created_at: "2009-04-21 00:00:00"
|
||||
url: http://some.desktop.app.org/
|
||||
support_url: http://some.desktop.app.org/support
|
||||
updated_at: "2009-04-21 00:00:00"
|
||||
user_id: 2
|
||||
secret: V9DOm1H5qSdIG9IeCTiOkAcCx15bK8bkGxf7XEpF
|
||||
key: rlEdPM6Tp8lpLwvSyNJQ4w
|
||||
allow_read_prefs: true
|
||||
allow_write_prefs: false
|
||||
allow_write_diary: false
|
||||
allow_write_api: true
|
||||
allow_read_gpx: true
|
||||
allow_write_gpx: false
|
||||
|
||||
normal_user_app:
|
||||
name: Some OAuth Desktop App
|
||||
created_at: "2009-05-21 00:00:00"
|
||||
url: http://some.desktop.app.org/
|
||||
support_url: http://some.desktop.app.org/support
|
||||
updated_at: "2009-05-21 00:00:00"
|
||||
user_id: 1
|
||||
secret: jgYx43yx1FAMQbG6T0qZhvvFsKEf6Pgd5XfHr5kFgv4
|
||||
key: N6KVhfeaT626fhBt9aCMeA
|
||||
allow_read_prefs: true
|
||||
allow_write_prefs: false
|
||||
allow_write_diary: false
|
||||
allow_write_api: true
|
||||
allow_read_gpx: true
|
||||
allow_write_gpx: false
|
|
@ -1,7 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class ClientApplicationsTest < ActionDispatch::IntegrationTest
|
||||
fixtures :users, :client_applications
|
||||
fixtures :users
|
||||
|
||||
##
|
||||
# run through the procedure of creating a client application and checking
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class OAuthTest < ActionDispatch::IntegrationTest
|
||||
fixtures :users, :client_applications, :gpx_files
|
||||
fixtures :users, :gpx_files
|
||||
set_fixture_class :gpx_files => Trace
|
||||
|
||||
include OAuth::Helper
|
||||
|
@ -11,18 +11,18 @@ class OAuthTest < ActionDispatch::IntegrationTest
|
|||
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
|
||||
|
@ -32,18 +32,18 @@ class OAuthTest < ActionDispatch::IntegrationTest
|
|||
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
|
||||
|
@ -196,7 +196,7 @@ class OAuthTest < ActionDispatch::IntegrationTest
|
|||
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
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
require "test_helper"
|
||||
|
||||
class ClientApplicationTest < ActiveSupport::TestCase
|
||||
fixtures :client_applications
|
||||
|
||||
def test_url_valid
|
||||
ok = ["http://example.com/test", "https://example.com/test"]
|
||||
bad = ["", "ftp://example.com/test", "myapp://somewhere"]
|
||||
|
||||
ok.each do |url|
|
||||
app = client_applications(:normal_user_app).dup
|
||||
app = build(:client_application)
|
||||
app.url = url
|
||||
assert app.valid?, "#{url} is invalid, when it should be"
|
||||
end
|
||||
|
||||
bad.each do |url|
|
||||
app = client_applications(:normal_user_app)
|
||||
app = build(:client_application)
|
||||
app.url = url
|
||||
assert !app.valid?, "#{url} is valid when it shouldn't be"
|
||||
end
|
||||
|
@ -25,13 +23,13 @@ class ClientApplicationTest < ActiveSupport::TestCase
|
|||
bad = ["ftp://example.com/test", "myapp://somewhere", "gibberish"]
|
||||
|
||||
ok.each do |url|
|
||||
app = client_applications(:normal_user_app)
|
||||
app = build(:client_application)
|
||||
app.support_url = url
|
||||
assert app.valid?, "#{url} is invalid, when it should be"
|
||||
end
|
||||
|
||||
bad.each do |url|
|
||||
app = client_applications(:normal_user_app)
|
||||
app = build(:client_application)
|
||||
app.support_url = url
|
||||
assert !app.valid?, "#{url} is valid when it shouldn't be"
|
||||
end
|
||||
|
@ -42,13 +40,13 @@ class ClientApplicationTest < ActiveSupport::TestCase
|
|||
bad = ["gibberish"]
|
||||
|
||||
ok.each do |url|
|
||||
app = client_applications(:normal_user_app)
|
||||
app = build(:client_application)
|
||||
app.callback_url = url
|
||||
assert app.valid?, "#{url} is invalid, when it should be"
|
||||
end
|
||||
|
||||
bad.each do |url|
|
||||
app = client_applications(:normal_user_app)
|
||||
app = build(:client_application)
|
||||
app.callback_url = url
|
||||
assert !app.valid?, "#{url} is valid when it shouldn't be"
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ class OauthTokenTest < ActiveSupport::TestCase
|
|||
##
|
||||
# check that an authorized token is authorised and can be invalidated
|
||||
def test_token_authorisation
|
||||
tok = RequestToken.create(:client_application => client_applications(:oauth_web_app))
|
||||
tok = RequestToken.create(:client_application => create(:client_application))
|
||||
assert_equal false, tok.authorized?, "Token should be created unauthorised."
|
||||
tok.authorize!(users(:public_user))
|
||||
assert_equal true, tok.authorized?, "Token should now be authorised."
|
||||
|
|
|
@ -50,8 +50,6 @@ module ActiveSupport
|
|||
set_fixture_class :gps_points => Tracepoint
|
||||
set_fixture_class :gpx_file_tags => Tracetag
|
||||
|
||||
fixtures :client_applications
|
||||
|
||||
fixtures :redactions
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue