mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-31 05:05:18 +01:00
Removed outer tracks directory.
This commit is contained in:
parent
649f4a44a4
commit
20940ff348
2274 changed files with 0 additions and 0 deletions
76
test/integration/context_xml_api_test.rb
Normal file
76
test/integration/context_xml_api_test.rb
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'contexts_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ContextsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ContextXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users, :contexts
|
||||
|
||||
@@context_name = "@newcontext"
|
||||
@@valid_postdata = "<request><context><name>#{@@context_name}</name></context></request>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_context_create @@valid_postdata, 'nobody', 'nohow'
|
||||
assert_401_unauthorized
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format
|
||||
authenticated_post_xml_to_context_create "<foo></bar>"
|
||||
assert_equal 500, @integration_session.status
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format2
|
||||
authenticated_post_xml_to_context_create "<request><context></context></request>"
|
||||
assert_404_invalid_xml
|
||||
end
|
||||
|
||||
def test_xml_simple_param_parsing
|
||||
authenticated_post_xml_to_context_create
|
||||
assert @controller.params.has_key?(:request)
|
||||
assert @controller.params[:request].has_key?(:context)
|
||||
assert @controller.params[:request][:context].has_key?(:name)
|
||||
assert_equal @@context_name, @controller.params[:request][:context][:name]
|
||||
end
|
||||
|
||||
def test_fails_with_too_long_name
|
||||
invalid_with_long_name_postdata = "<request><context><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></context></request>"
|
||||
authenticated_post_xml_to_context_create invalid_with_long_name_postdata
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, 'Name context name must be less than 256 characters'
|
||||
end
|
||||
end
|
||||
|
||||
def test_fails_with_comma_in_name
|
||||
authenticated_post_xml_to_context_create "<request><context><name>foo,bar</name></context></request>"
|
||||
assert_response 409
|
||||
assert_xml_select 'errors' do
|
||||
assert_select 'error', 1, 'Name cannot contain the comma (\',\') character'
|
||||
end
|
||||
end
|
||||
|
||||
def test_creates_new_context
|
||||
assert_difference Context, :count do
|
||||
authenticated_post_xml_to_context_create
|
||||
assert_response 201
|
||||
end
|
||||
context1 = Context.find_by_name(@@context_name)
|
||||
assert_not_nil context1, "expected context '#{@@context_name}' to be created"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticated_post_xml_to_context_create(postdata = @@valid_postdata, user = users(:other_user).login, password = 'sesame')
|
||||
authenticated_post_xml "/contexts", user, password, postdata
|
||||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 400, "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>."
|
||||
end
|
||||
|
||||
end
|
||||
132
test/integration/feed_smoke_test.rb
Normal file
132
test/integration/feed_smoke_test.rb
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'projects_controller'
|
||||
require 'contexts_controller'
|
||||
require 'todos_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ProjectsController; def rescue_action(e) raise e end; end
|
||||
class ContextsController; def rescue_action(e) raise e end; end
|
||||
class TodosController; def rescue_action(e) raise e end; end
|
||||
|
||||
class FeedSmokeTest < ActionController::IntegrationTest
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :notes
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
def test_last_15_actions_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
||||
def test_last_15_actions_atom
|
||||
assert_success "/todos.atom?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
||||
def test_last_15_actions_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
||||
def test_last_15_actions_ical
|
||||
assert_success "/todos.ics?token=#{ users(:admin_user).token }&limit=15"
|
||||
end
|
||||
|
||||
def test_all_actions_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_ical
|
||||
assert_success "/todos.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_in_context_rss
|
||||
assert_success "/contexts/1/todos.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_in_context_txt
|
||||
assert_success "/contexts/1/todos.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_in_context_ical
|
||||
assert_success "/contexts/1/todos.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_in_project_rss
|
||||
assert_success "/projects/1/todos.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_in_project_txt
|
||||
assert_success "/projects/1/todos.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_in_project_ical
|
||||
assert_success "/projects/1/todos.ics?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_actions_due_today_or_earlier_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }&due=0"
|
||||
end
|
||||
|
||||
def test_all_actions_due_today_or_earlier_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }&due=0"
|
||||
end
|
||||
|
||||
def test_all_actions_due_today_or_earlier_ical
|
||||
assert_success "/todos.ics?token=#{ users(:admin_user).token }&due=0"
|
||||
end
|
||||
|
||||
def test_all_actions_due_in_7_days_or_earlier_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }&due=6"
|
||||
end
|
||||
|
||||
def test_all_actions_due_in_7_days_or_earlier_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }&due=6"
|
||||
end
|
||||
|
||||
def test_all_actions_due_in_7_days_or_earlier_ical
|
||||
assert_success "/todos.ics?token=#{ users(:admin_user).token }&due=6"
|
||||
end
|
||||
|
||||
def test_all_actions_completed_in_last_7_days_rss
|
||||
assert_success "/todos.rss?token=#{ users(:admin_user).token }&done=7"
|
||||
end
|
||||
|
||||
def test_all_actions_completed_in_last_7_days_txt
|
||||
assert_success "/todos.txt?token=#{ users(:admin_user).token }&done=7"
|
||||
end
|
||||
|
||||
def test_all_contexts_rss
|
||||
assert_success "/contexts.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_contexts_txt
|
||||
assert_success "/contexts.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_projects_rss
|
||||
assert_success "/projects.rss?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_projects_txt
|
||||
assert_success "/projects.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
def test_all_projects_txt_with_hidden_project
|
||||
p = projects(:timemachine)
|
||||
p.hide!
|
||||
assert_success "/projects.txt?token=#{ users(:admin_user).token }"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_success(url)
|
||||
get url
|
||||
assert_response :success
|
||||
#puts @response.body
|
||||
end
|
||||
|
||||
end
|
||||
145
test/integration/ldap_auth_test.rb
Executable file
145
test/integration/ldap_auth_test.rb
Executable file
|
|
@ -0,0 +1,145 @@
|
|||
require "#{File.dirname(__FILE__)}/../test_helper"
|
||||
require 'tempfile'
|
||||
|
||||
module Tracks
|
||||
class Config
|
||||
def self.salt
|
||||
"change-me"
|
||||
end
|
||||
def self.auth_schemes
|
||||
['database','ldap']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class LdapAuthTest < ActionController::IntegrationTest
|
||||
|
||||
fixtures :users
|
||||
|
||||
RUN_LDAP_TESTS = ENV['RUN_TRACKS_LDAP_TESTS'] || false
|
||||
SLAPD_BIN = "/usr/libexec/slapd" #You may need to adjust this
|
||||
SLAPD_SCHEMA_DIR = "/etc/openldap/schema/" #You may need to adjust this
|
||||
SLAPD_TEST_PORT = 10389
|
||||
OUTPUT_DEBUG_INFO = false
|
||||
|
||||
begin
|
||||
require 'net/ldap' #requires ruby-net-ldap gem be installed
|
||||
require 'simple_ldap_authenticator'
|
||||
end if RUN_LDAP_TESTS
|
||||
|
||||
SimpleLdapAuthenticator.ldap_library = 'net/ldap'
|
||||
SimpleLdapAuthenticator.servers = %w'localhost'
|
||||
SimpleLdapAuthenticator.use_ssl = false
|
||||
SimpleLdapAuthenticator.login_format = 'cn=%s,dc=lukemelia,dc=com'
|
||||
SimpleLdapAuthenticator.port = 10389
|
||||
SimpleLdapAuthenticator.logger = RAILS_DEFAULT_LOGGER
|
||||
|
||||
def setup
|
||||
assert_equal "test", ENV['RAILS_ENV']
|
||||
assert_equal "change-me", Tracks::Config.salt
|
||||
|
||||
if RUN_LDAP_TESTS
|
||||
setup_ldap_server_conf
|
||||
start_ldap_server
|
||||
end
|
||||
end
|
||||
|
||||
def teardown
|
||||
stop_ldap_server if RUN_LDAP_TESTS
|
||||
end
|
||||
|
||||
def test_authenticate_against_ldap
|
||||
add_ldap_user_to_ldap_repository
|
||||
assert SimpleLdapAuthenticator.valid?('john', 'deere')
|
||||
user = User.authenticate('john', 'deere')
|
||||
assert_not_nil(user)
|
||||
assert_equal user.login, 'john'
|
||||
end
|
||||
|
||||
private :test_authenticate_against_ldap unless RUN_LDAP_TESTS
|
||||
|
||||
def setup_ldap_server_conf
|
||||
@slapd_conf = create_slapd_conf()
|
||||
open(@slapd_conf.path) { |f| f.read }
|
||||
unless File.exist?(SLAPD_BIN)
|
||||
assert false, "slapd could not be found at #{SLAPD_BIN}. Adjust the path in #{__FILE__}"
|
||||
end
|
||||
end
|
||||
|
||||
def start_ldap_server
|
||||
t = Thread.new(@slapd_conf.path) do |slapd_conf_path|
|
||||
puts "starting slapd..." if OUTPUT_DEBUG_INFO
|
||||
run_cmd %Q{/usr/libexec/slapd -f #{slapd_conf_path} -h "ldap://127.0.0.1:10389/" -d0}
|
||||
end
|
||||
sleep(2)
|
||||
run_cmd %Q{ldapsearch -H "ldap://127.0.0.1:10389/" -x -b '' -s base '(objectclass=*)' namingContexts}
|
||||
end
|
||||
|
||||
def add_ldap_user_to_ldap_repository
|
||||
ldif_file = create_ldif()
|
||||
run_cmd %Q{ldapadd -H "ldap://127.0.0.1:10389/" -f #{ldif_file.path} -cxv -D "cn=Manager,dc=lukemelia,dc=com" -w secret}
|
||||
puts `cat #{ldif_file.path}` if OUTPUT_DEBUG_INFO
|
||||
end
|
||||
|
||||
def stop_ldap_server
|
||||
pid = open(get_pid_file_path(@slapd_conf)) { |f| f.read }
|
||||
run_cmd "kill -TERM #{pid}"
|
||||
end
|
||||
|
||||
def create_slapd_conf
|
||||
slapd_conf = Tempfile.new("slapd.conf")
|
||||
slapd_conf.path
|
||||
data_dir = slapd_conf.path + '-data'
|
||||
pid_file = get_pid_file_path(slapd_conf)
|
||||
Dir.mkdir(data_dir)
|
||||
encrypted_password = `slappasswd -s secret`
|
||||
open(slapd_conf.path, 'w') do |f|
|
||||
f.puts %Q{include #{SLAPD_SCHEMA_DIR}core.schema
|
||||
pidfile #{pid_file}
|
||||
database ldbm
|
||||
suffix "dc=lukemelia,dc=com"
|
||||
rootdn "cn=Manager,dc=lukemelia,dc=com"
|
||||
rootpw #{encrypted_password}
|
||||
directory #{data_dir}
|
||||
|
||||
access to *
|
||||
by self write
|
||||
by users read
|
||||
by anonymous auth
|
||||
}
|
||||
end
|
||||
puts `cat #{slapd_conf.path}` if OUTPUT_DEBUG_INFO
|
||||
slapd_conf
|
||||
end
|
||||
|
||||
def create_ldif
|
||||
ldif_file = Tempfile.new("ldap_user.ldif")
|
||||
encrypted_password = `slappasswd -s deere`
|
||||
open(ldif_file.path, 'w') do |f|
|
||||
f.puts %Q{dn: dc=lukemelia,dc=com
|
||||
objectclass: dcObject
|
||||
objectclass: organization
|
||||
o: Luke Melia DotCom
|
||||
dc: lukemelia
|
||||
|
||||
dn: cn=john,dc=lukemelia,dc=com
|
||||
cn: john
|
||||
sn: john
|
||||
objectclass: person
|
||||
userPassword: #{encrypted_password}
|
||||
}
|
||||
end
|
||||
ldif_file
|
||||
end
|
||||
|
||||
def run_cmd(cmd)
|
||||
puts cmd if OUTPUT_DEBUG_INFO
|
||||
cmd_out = `#{cmd}`
|
||||
puts cmd_out if OUTPUT_DEBUG_INFO
|
||||
end
|
||||
|
||||
def get_pid_file_path(tempfile)
|
||||
tempfile.path + '.pid'
|
||||
end
|
||||
|
||||
end
|
||||
70
test/integration/project_xml_api_test.rb
Normal file
70
test/integration/project_xml_api_test.rb
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'projects_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class ProjectsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ProjectXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users, :projects
|
||||
|
||||
@@project_name = "My New Project"
|
||||
@@valid_postdata = "<request><project><name>#{@@project_name}</name></project></request>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_project_create @@valid_postdata, 'nobody', 'nohow'
|
||||
assert_401_unauthorized
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format
|
||||
authenticated_post_xml_to_project_create "<foo></bar>"
|
||||
assert_equal 500, @integration_session.status
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format2
|
||||
authenticated_post_xml_to_project_create "<request><project></project></request>"
|
||||
assert_404_invalid_xml
|
||||
end
|
||||
|
||||
def test_xml_simple_param_parsing
|
||||
authenticated_post_xml_to_project_create
|
||||
assert @controller.params.has_key?(:request)
|
||||
assert @controller.params[:request].has_key?(:project)
|
||||
assert @controller.params[:request][:project].has_key?(:name)
|
||||
assert_equal @@project_name, @controller.params[:request][:project][:name]
|
||||
end
|
||||
|
||||
def test_fails_with_too_long_name
|
||||
invalid_with_long_name_postdata = "<request><project><name>foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo barfoobarfoobarfoobarfoobarfoobarfoobar</name></project></request>"
|
||||
authenticated_post_xml_to_project_create invalid_with_long_name_postdata
|
||||
assert_response_and_body 404, "Name project name must be less than 256 characters"
|
||||
end
|
||||
|
||||
def test_fails_with_comma_in_name
|
||||
authenticated_post_xml_to_project_create "<request><project><name>foo,bar</name></project></request>"
|
||||
assert_response_and_body 404, "Name cannot contain the comma (',') character"
|
||||
end
|
||||
|
||||
def test_creates_new_project
|
||||
assert_difference Project, :count do
|
||||
authenticated_post_xml_to_project_create
|
||||
assert_response :created
|
||||
end
|
||||
project1 = Project.find_by_name(@@project_name)
|
||||
assert_not_nil project1, "expected project '#{@@project_name}' to be created"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authenticated_post_xml_to_project_create(postdata = @@valid_postdata, user = users(:other_user).login, password = 'sesame')
|
||||
authenticated_post_xml "/projects", user, password, postdata
|
||||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 404, "Expected post format is valid xml like so: <request><project><name>project name</name></project></request>."
|
||||
end
|
||||
|
||||
end
|
||||
80
test/integration/stories_test.rb
Normal file
80
test/integration/stories_test.rb
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
require "#{File.dirname(__FILE__)}/../test_helper"
|
||||
|
||||
class StoriesTest < ActionController::IntegrationTest
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos, :notes
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
# ####################################################
|
||||
# Testing login and signup by different kinds of users
|
||||
# ####################################################
|
||||
def test_signup_new_user_by_admin
|
||||
admin = new_session_as(:admin_user,"abracadabra")
|
||||
admin.goes_to_signup
|
||||
admin.signs_up_with(:user => {:login => "newbie",
|
||||
:password => "newbiepass",
|
||||
:password_confirmation => "newbiepass"})
|
||||
end
|
||||
|
||||
def test_signup_new_user_by_nonadmin
|
||||
other_user = new_session_as(:other_user,"sesame")
|
||||
other_user.goes_to_signup_as_nonadmin
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
module CustomAssertions
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def logs_in_as(user,plain_pass)
|
||||
@user = users(user)
|
||||
post "/login", :user_login => @user.login,
|
||||
:user_password => plain_pass,
|
||||
:user_noexpiry => 'n'
|
||||
assert_response :redirect
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
assert_template "todos/index"
|
||||
end
|
||||
|
||||
def goes_to_login
|
||||
get "/login"
|
||||
assert_response :success
|
||||
assert_template "login/login"
|
||||
end
|
||||
|
||||
def goes_to_signup
|
||||
get "/signup"
|
||||
assert_response :success
|
||||
assert_template "users/new"
|
||||
end
|
||||
|
||||
def goes_to_signup_as_nonadmin
|
||||
get "/signup"
|
||||
assert_response :success
|
||||
assert_template "users/nosignup"
|
||||
end
|
||||
|
||||
def signs_up_with(options)
|
||||
post "/users", options
|
||||
assert_response :redirect
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
assert_template "todos/index"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def new_session_as(user,plainpass)
|
||||
open_session do |sess|
|
||||
sess.extend(CustomAssertions)
|
||||
sess.goes_to_login
|
||||
sess.logs_in_as(user,plainpass)
|
||||
yield sess if block_given?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
106
test/integration/users_xml_api_test.rb
Normal file
106
test/integration/users_xml_api_test.rb
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'users_controller'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class UsersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class UsersXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users
|
||||
|
||||
@@foobar_postdata = "<request><login>foo</login><password>bar</password></request>"
|
||||
@@johnny_postdata = "<request><login>johnny</login><password>barracuda</password></request>"
|
||||
|
||||
def setup
|
||||
assert_test_environment_ok
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_authorized_user
|
||||
authenticated_post_xml_to_user_create @@foobar_postdata, 'nobody', 'nohow'
|
||||
assert_401_unauthorized_admin
|
||||
end
|
||||
|
||||
def test_fails_with_401_if_not_admin_user
|
||||
authenticated_post_xml_to_user_create @@foobar_postdata, users(:other_user).login, 'sesame'
|
||||
assert_401_unauthorized_admin
|
||||
end
|
||||
|
||||
def test_content_type_must_be_xml
|
||||
authenticated_post_xml_to_user_create @@foobar_postdata, users(:admin_user).login, 'abracadabra', {'CONTENT_TYPE' => "application/x-www-form-urlencoded"}
|
||||
assert_404_invalid_xml
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format
|
||||
authenticated_post_xml_to_user_create "<foo></bar>"
|
||||
assert_equal 500, @integration_session.status
|
||||
end
|
||||
|
||||
def test_fails_with_invalid_xml_format2
|
||||
authenticated_post_xml_to_user_create "<request><username>foo</username></request>"
|
||||
assert_404_invalid_xml
|
||||
end
|
||||
|
||||
def test_xml_simple_param_parsing
|
||||
authenticated_post_xml_to_user_create
|
||||
assert @controller.params.has_key?(:request)
|
||||
assert @controller.params[:request].has_key?(:login)
|
||||
assert @controller.params[:request].has_key?(:password)
|
||||
assert_equal 'foo', @controller.params[:request][:login]
|
||||
assert_equal 'bar', @controller.params[:request][:password]
|
||||
end
|
||||
|
||||
def test_fails_with_too_short_password
|
||||
authenticated_post_xml_to_user_create
|
||||
assert_response_and_body 404, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>\n <error>Password is too short (minimum is 5 characters)</error>\n</errors>\n"
|
||||
end
|
||||
|
||||
def test_fails_with_nonunique_login
|
||||
existing_login = users(:other_user).login
|
||||
authenticated_post_xml_to_user_create "<request><login>#{existing_login}</login><password>barracuda</password></request>"
|
||||
assert_response_and_body 404, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>\n <error>Login has already been taken</error>\n</errors>\n"
|
||||
end
|
||||
|
||||
def test_creates_new_user
|
||||
initial_count = User.count
|
||||
authenticated_post_xml_to_user_create @@johnny_postdata
|
||||
assert_response_and_body 200, "User created."
|
||||
assert_equal initial_count + 1, User.count
|
||||
johnny1 = User.find_by_login('johnny')
|
||||
assert_not_nil johnny1, "expected user johnny to be created"
|
||||
johnny2 = User.authenticate('johnny','barracuda')
|
||||
assert_not_nil johnny2, "expected user johnny to be created"
|
||||
end
|
||||
|
||||
def test_fails_with_get_verb
|
||||
authenticated_get_xml "/users", users(:admin_user).login, 'abracadabra', {}
|
||||
end
|
||||
|
||||
def test_get_users_as_xml
|
||||
get '/users.xml', {}, basic_auth_headers()
|
||||
assert_response :success
|
||||
assert_tag :tag => "users",
|
||||
:children => { :count => 3, :only => { :tag => "user" } }
|
||||
assert_no_tag :tag => "password"
|
||||
end
|
||||
|
||||
def test_get_user_as_xml
|
||||
get "/users/#{users(:other_user).login}.xml", {}, basic_auth_headers()
|
||||
assert_response :success
|
||||
assert_tag :tag => "user"
|
||||
assert_no_tag :tag => "password"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def basic_auth_headers(username = users(:admin_user).login, password = 'abracadabra')
|
||||
{'AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}") }
|
||||
end
|
||||
|
||||
def authenticated_post_xml_to_user_create(postdata = @@foobar_postdata, user = users(:admin_user).login, password = 'abracadabra', headers = {})
|
||||
authenticated_post_xml "/users", user, password, postdata, headers
|
||||
end
|
||||
|
||||
def assert_404_invalid_xml
|
||||
assert_response_and_body 404, "Expected post format is valid xml like so: <request><login>username</login><password>abc123</password></request>."
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue