annotate test/integration/api_token_login_test.rb @ 1:cca12e1c1fd4

* Update to Redmine trunk (SVN revisions 3860-3892)
author Chris Cannam
date Wed, 28 Jul 2010 12:08:28 +0100
parents 513646585e45
children
rev   line source
Chris@0 1 require "#{File.dirname(__FILE__)}/../test_helper"
Chris@0 2
Chris@0 3 class ApiTokenLoginTest < ActionController::IntegrationTest
Chris@0 4 fixtures :all
Chris@0 5
Chris@0 6 def setup
Chris@0 7 Setting.rest_api_enabled = '1'
Chris@0 8 Setting.login_required = '1'
Chris@0 9 end
Chris@0 10
Chris@0 11 def teardown
Chris@0 12 Setting.rest_api_enabled = '0'
Chris@0 13 Setting.login_required = '0'
Chris@0 14 end
Chris@0 15
Chris@0 16 # Using the NewsController because it's a simple API.
Chris@0 17 context "get /news" do
Chris@0 18
Chris@0 19 context "in :xml format" do
Chris@0 20 context "with a valid api token" do
Chris@0 21 setup do
Chris@0 22 @user = User.generate_with_protected!
Chris@0 23 @token = Token.generate!(:user => @user, :action => 'api')
Chris@0 24 get "/news.xml?key=#{@token.value}"
Chris@0 25 end
Chris@0 26
Chris@0 27 should_respond_with :success
Chris@0 28 should_respond_with_content_type :xml
Chris@0 29 should "login as the user" do
Chris@0 30 assert_equal @user, User.current
Chris@0 31 end
Chris@0 32 end
Chris@0 33
Chris@0 34 context "with an invalid api token" do
Chris@0 35 setup do
Chris@0 36 @user = User.generate_with_protected!
Chris@0 37 @token = Token.generate!(:user => @user, :action => 'feeds')
Chris@0 38 get "/news.xml?key=#{@token.value}"
Chris@0 39 end
Chris@0 40
Chris@0 41 should_respond_with :unauthorized
Chris@0 42 should_respond_with_content_type :xml
Chris@0 43 should "not login as the user" do
Chris@0 44 assert_equal User.anonymous, User.current
Chris@0 45 end
Chris@0 46 end
Chris@0 47 end
Chris@0 48
Chris@0 49 context "in :json format" do
Chris@0 50 context "with a valid api token" do
Chris@0 51 setup do
Chris@0 52 @user = User.generate_with_protected!
Chris@0 53 @token = Token.generate!(:user => @user, :action => 'api')
Chris@0 54 get "/news.json?key=#{@token.value}"
Chris@0 55 end
Chris@0 56
Chris@0 57 should_respond_with :success
Chris@0 58 should_respond_with_content_type :json
Chris@0 59 should "login as the user" do
Chris@0 60 assert_equal @user, User.current
Chris@0 61 end
Chris@0 62 end
Chris@0 63
Chris@0 64 context "with an invalid api token" do
Chris@0 65 setup do
Chris@0 66 @user = User.generate_with_protected!
Chris@0 67 @token = Token.generate!(:user => @user, :action => 'feeds')
Chris@0 68 get "/news.json?key=#{@token.value}"
Chris@0 69 end
Chris@0 70
Chris@0 71 should_respond_with :unauthorized
Chris@0 72 should_respond_with_content_type :json
Chris@0 73 should "not login as the user" do
Chris@0 74 assert_equal User.anonymous, User.current
Chris@0 75 end
Chris@0 76 end
Chris@0 77 end
Chris@0 78
Chris@0 79 end
Chris@0 80 end