##// END OF EJS Templates
Test cleanup....
Jean-Philippe Lang -
r8358:6b5f75bb1d9c
parent child
Show More
@@ -20,94 +20,41 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest
20 Setting.login_required = '0'
20 Setting.login_required = '0'
21 end
21 end
22
22
23 # Using the NewsController because it's a simple API.
23 def test_with_a_valid_api_token
24 context "get /news with the API disabled" do
25
26 context "in :xml format" do
27 context "with a valid api token" do
28 setup do
29 @user = User.generate_with_protected!
24 @user = User.generate_with_protected!
30 @token = Token.generate!(:user => @user, :action => 'api')
25 @token = Token.generate!(:user => @user, :action => 'api')
31 get "/news.xml?key=#{@token.value}"
32 end
33
34 should_respond_with :unauthorized
35 should_respond_with_content_type :xml
36 should "not login as the user" do
37 assert_equal User.anonymous, User.current
38 end
39 end
40
41 context "with a valid HTTP authentication" do
42 setup do
43 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
44 get "/news.xml", nil, credentials(@user.login, 'my_password')
45 end
46
26
47 should_respond_with :unauthorized
27 get "/news.xml?key=#{@token.value}"
48 should_respond_with_content_type :xml
28 assert_response :unauthorized
49 should "not login as the user" do
50 assert_equal User.anonymous, User.current
29 assert_equal User.anonymous, User.current
51 end
52 end
53
54 context "with a valid HTTP authentication using the API token" do
55 setup do
56 @user = User.generate_with_protected!
57 @token = Token.generate!(:user => @user, :action => 'api')
58 get "/news.xml", nil, credentials(@token.value, 'X')
59 end
60
30
61 should_respond_with :unauthorized
31 get "/news.json?key=#{@token.value}"
62 should_respond_with_content_type :xml
32 assert_response :unauthorized
63 should "not login as the user" do
64 assert_equal User.anonymous, User.current
33 assert_equal User.anonymous, User.current
65 end
34 end
66 end
67 end
68
35
69 context "in :json format" do
36 def test_with_valid_username_password_http_authentication
70 context "with a valid api token" do
37 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
71 setup do
72 @user = User.generate_with_protected!
73 @token = Token.generate!(:user => @user, :action => 'api')
74 get "/news.json?key=#{@token.value}"
75 end
76
38
77 should_respond_with :unauthorized
39 get "/news.xml", nil, credentials(@user.login, 'my_password')
78 should_respond_with_content_type :json
40 assert_response :unauthorized
79 should "not login as the user" do
80 assert_equal User.anonymous, User.current
41 assert_equal User.anonymous, User.current
81 end
82 end
83
42
84 context "with a valid HTTP authentication" do
85 setup do
86 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
87 get "/news.json", nil, credentials(@user.login, 'my_password')
43 get "/news.json", nil, credentials(@user.login, 'my_password')
88 end
44 assert_response :unauthorized
89
90 should_respond_with :unauthorized
91 should_respond_with_content_type :json
92 should "not login as the user" do
93 assert_equal User.anonymous, User.current
45 assert_equal User.anonymous, User.current
94 end
46 end
95 end
96
47
97 context "with a valid HTTP authentication using the API token" do
48 def test_with_valid_token_http_authentication
98 setup do
99 @user = User.generate_with_protected!
49 @user = User.generate_with_protected!
100 @token = Token.generate!(:user => @user, :action => 'api')
50 @token = Token.generate!(:user => @user, :action => 'api')
101 get "/news.json", nil, credentials(@token.value, 'DoesNotMatter')
102 end
103
51
104 should_respond_with :unauthorized
52 get "/news.xml", nil, credentials(@token.value, 'X')
105 should_respond_with_content_type :json
53 assert_response :unauthorized
106 should "not login as the user" do
107 assert_equal User.anonymous, User.current
54 assert_equal User.anonymous, User.current
108 end
109 end
110
55
111 end
56 get "/news.json", nil, credentials(@token.value, 'X')
57 assert_response :unauthorized
58 assert_equal User.anonymous, User.current
112 end
59 end
113 end
60 end
General Comments 0
You need to be logged in to leave comments. Login now