require "test_helper"
class OauthClientsControllerTest < ActionController::TestCase
- fixtures :users, :client_applications
+ fixtures :users
##
# test all routes which lead to this controller
def test_index
user = users(:public_user)
+ create_list(:client_application, 2, :user => user)
get :index, :display_name => user.display_name
assert_response :redirect
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"
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"
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"
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
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"
##
# 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
--- /dev/null
+FactoryGirl.define do
+ factory :client_application do
+ sequence(:name) { |n| "Client application #{n}" }
+ sequence(:url) { |n| "http://example.com/app/#{n}" }
+ end
+end
+++ /dev/null
-# 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
require "test_helper"
class ClientApplicationsTest < ActionDispatch::IntegrationTest
- fixtures :users, :client_applications
+ fixtures :users
##
# run through the procedure of creating a client application and checking
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
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
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
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
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
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
##
# 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."
set_fixture_class :gps_points => Tracepoint
set_fixture_class :gpx_file_tags => Tracetag
- fixtures :client_applications
-
fixtures :redactions
end