@@ -20,94 +20,41 class ApiTest::DisabledRestApiTest < ActionController::IntegrationTest | |||
|
20 | 20 | Setting.login_required = '0' |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | # Using the NewsController because it's a simple API. | |
|
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 | |
|
23 | def test_with_a_valid_api_token | |
|
29 | 24 |
|
|
30 | 25 |
|
|
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 | |
|
48 | should_respond_with_content_type :xml | |
|
49 | should "not login as the user" do | |
|
27 | get "/news.xml?key=#{@token.value}" | |
|
28 | assert_response :unauthorized | |
|
50 | 29 |
|
|
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 | |
|
62 | should_respond_with_content_type :xml | |
|
63 | should "not login as the user" do | |
|
31 | get "/news.json?key=#{@token.value}" | |
|
32 | assert_response :unauthorized | |
|
64 | 33 |
|
|
65 | 34 |
|
|
66 | end | |
|
67 | end | |
|
68 | 35 | |
|
69 | context "in :json format" do | |
|
70 | context "with a valid api token" do | |
|
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 | |
|
36 | def test_with_valid_username_password_http_authentication | |
|
37 | @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password') | |
|
76 | 38 | |
|
77 | should_respond_with :unauthorized | |
|
78 | should_respond_with_content_type :json | |
|
79 | should "not login as the user" do | |
|
39 | get "/news.xml", nil, credentials(@user.login, 'my_password') | |
|
40 | assert_response :unauthorized | |
|
80 | 41 |
|
|
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 | 43 |
|
|
88 | end | |
|
89 | ||
|
90 | should_respond_with :unauthorized | |
|
91 | should_respond_with_content_type :json | |
|
92 | should "not login as the user" do | |
|
44 | assert_response :unauthorized | |
|
93 | 45 |
|
|
94 | 46 |
|
|
95 | end | |
|
96 | 47 | |
|
97 | context "with a valid HTTP authentication using the API token" do | |
|
98 | setup do | |
|
48 | def test_with_valid_token_http_authentication | |
|
99 | 49 |
|
|
100 | 50 |
|
|
101 | get "/news.json", nil, credentials(@token.value, 'DoesNotMatter') | |
|
102 | end | |
|
103 | 51 | |
|
104 | should_respond_with :unauthorized | |
|
105 | should_respond_with_content_type :json | |
|
106 | should "not login as the user" do | |
|
52 | get "/news.xml", nil, credentials(@token.value, 'X') | |
|
53 | assert_response :unauthorized | |
|
107 | 54 |
|
|
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 | 59 | end |
|
113 | 60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now