##// END OF EJS Templates
Added an Admin setting to enable/disable the REST web service. (#3920)...
Eric Davis -
r3106:bfcd5039f288
parent child
Show More
@@ -0,0 +1,8
1 <% form_tag({:action => 'edit', :tab => 'integration'}) do %>
2
3 <div class="box tabular settings">
4 <p><%= setting_check_box :rest_api_enabled %></p>
5 </div>
6
7 <%= submit_tag l(:button_save) %>
8 <% end %>
@@ -0,0 +1,110
1 require "#{File.dirname(__FILE__)}/../test_helper"
2
3 class DisabledRestApi < ActionController::IntegrationTest
4 fixtures :all
5
6 def setup
7 Setting.rest_api_enabled = '0'
8 Setting.login_required = '1'
9 end
10
11 def teardown
12 Setting.rest_api_enabled = '1'
13 Setting.login_required = '0'
14 end
15
16 # Using the NewsController because it's a simple API.
17 context "get /news with the API disabled" do
18
19 context "in :xml format" do
20 context "with a valid api token" do
21 setup do
22 @user = User.generate_with_protected!
23 @token = Token.generate!(:user => @user, :action => 'api')
24 get "/news.xml?key=#{@token.value}"
25 end
26
27 should_respond_with :unauthorized
28 should_respond_with_content_type :xml
29 should "not login as the user" do
30 assert_equal User.anonymous, User.current
31 end
32 end
33
34 context "with a valid HTTP authentication" do
35 setup do
36 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
37 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password')
38 get "/news.xml", nil, :authorization => @authorization
39 end
40
41 should_respond_with :unauthorized
42 should_respond_with_content_type :xml
43 should "not login as the user" do
44 assert_equal User.anonymous, User.current
45 end
46 end
47
48 context "with a valid HTTP authentication using the API token" do
49 setup do
50 @user = User.generate_with_protected!
51 @token = Token.generate!(:user => @user, :action => 'api')
52 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X')
53 get "/news.xml", nil, :authorization => @authorization
54 end
55
56 should_respond_with :unauthorized
57 should_respond_with_content_type :xml
58 should "not login as the user" do
59 assert_equal User.anonymous, User.current
60 end
61 end
62 end
63
64 context "in :json format" do
65 context "with a valid api token" do
66 setup do
67 @user = User.generate_with_protected!
68 @token = Token.generate!(:user => @user, :action => 'api')
69 get "/news.json?key=#{@token.value}"
70 end
71
72 should_respond_with :unauthorized
73 should_respond_with_content_type :json
74 should "not login as the user" do
75 assert_equal User.anonymous, User.current
76 end
77 end
78
79 context "with a valid HTTP authentication" do
80 setup do
81 @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password')
82 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'my_password')
83 get "/news.json", nil, :authorization => @authorization
84 end
85
86 should_respond_with :unauthorized
87 should_respond_with_content_type :json
88 should "not login as the user" do
89 assert_equal User.anonymous, User.current
90 end
91 end
92
93 context "with a valid HTTP authentication using the API token" do
94 setup do
95 @user = User.generate_with_protected!
96 @token = Token.generate!(:user => @user, :action => 'api')
97 @authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'DoesNotMatter')
98 get "/news.json", nil, :authorization => @authorization
99 end
100
101 should_respond_with :unauthorized
102 should_respond_with_content_type :json
103 should "not login as the user" do
104 assert_equal User.anonymous, User.current
105 end
106 end
107
108 end
109 end
110 end
@@ -70,7 +70,7 class ApplicationController < ActionController::Base
70 elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
70 elsif params[:format] == 'atom' && params[:key] && accept_key_auth_actions.include?(params[:action])
71 # RSS key authentication does not start a session
71 # RSS key authentication does not start a session
72 User.find_by_rss_key(params[:key])
72 User.find_by_rss_key(params[:key])
73 elsif ['xml', 'json'].include?(params[:format]) && accept_key_auth_actions.include?(params[:action])
73 elsif Setting.rest_api_enabled? && ['xml', 'json'].include?(params[:format]) && accept_key_auth_actions.include?(params[:action])
74 if params[:key].present?
74 if params[:key].present?
75 # Use API key
75 # Use API key
76 User.find_by_api_key(params[:key])
76 User.find_by_api_key(params[:key])
@@ -24,7 +24,8 module SettingsHelper
24 {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
24 {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
25 {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
25 {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
26 {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
26 {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
27 {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
27 {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural},
28 {:name => 'integration', :partial => 'settings/integration', :label => :label_integration}
28 ]
29 ]
29 end
30 end
30
31
@@ -324,6 +324,7 en:
324 setting_issue_done_ratio_issue_field: Use the issue field
324 setting_issue_done_ratio_issue_field: Use the issue field
325 setting_issue_done_ratio_issue_status: Use the issue status
325 setting_issue_done_ratio_issue_status: Use the issue status
326 setting_start_of_week: Start calendars on
326 setting_start_of_week: Start calendars on
327 setting_rest_api_enabled: Enable REST web service
327
328
328 permission_add_project: Create project
329 permission_add_project: Create project
329 permission_edit_project: Edit project
330 permission_edit_project: Edit project
@@ -735,6 +736,7 en:
735 label_api_access_key: API access key
736 label_api_access_key: API access key
736 label_missing_api_access_key: Missing an API access key
737 label_missing_api_access_key: Missing an API access key
737 label_api_access_key_created_on: "API access key created {{value}} ago"
738 label_api_access_key_created_on: "API access key created {{value}} ago"
739 label_integration: Integration
738
740
739 button_login: Login
741 button_login: Login
740 button_submit: Submit
742 button_submit: Submit
@@ -176,3 +176,5 gravatar_default:
176 default: ''
176 default: ''
177 start_of_week:
177 start_of_week:
178 default: ''
178 default: ''
179 rest_api_enabled:
180 default: 0
@@ -4,10 +4,12 class ApiTokenLoginTest < ActionController::IntegrationTest
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 Setting.rest_api_enabled = '1'
7 Setting.login_required = '1'
8 Setting.login_required = '1'
8 end
9 end
9
10
10 def teardown
11 def teardown
12 Setting.rest_api_enabled = '0'
11 Setting.login_required = '0'
13 Setting.login_required = '0'
12 end
14 end
13
15
@@ -4,10 +4,12 class HttpBasicLoginTest < ActionController::IntegrationTest
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 Setting.rest_api_enabled = '1'
7 Setting.login_required = '1'
8 Setting.login_required = '1'
8 end
9 end
9
10
10 def teardown
11 def teardown
12 Setting.rest_api_enabled = '0'
11 Setting.login_required = '0'
13 Setting.login_required = '0'
12 end
14 end
13
15
@@ -4,10 +4,12 class HttpBasicLoginWithApiTokenTest < ActionController::IntegrationTest
4 fixtures :all
4 fixtures :all
5
5
6 def setup
6 def setup
7 Setting.rest_api_enabled = '1'
7 Setting.login_required = '1'
8 Setting.login_required = '1'
8 end
9 end
9
10
10 def teardown
11 def teardown
12 Setting.rest_api_enabled = '0'
11 Setting.login_required = '0'
13 Setting.login_required = '0'
12 end
14 end
13
15
General Comments 0
You need to be logged in to leave comments. Login now