@@ -1,62 +1,79 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
2 |
|
19 | |||
3 | class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base |
|
20 | class Redmine::ApiTest::DisabledRestApiTest < Redmine::ApiTest::Base | |
4 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
5 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
6 | :projects_trackers, |
|
23 | :projects_trackers, | |
7 | :roles, |
|
24 | :roles, | |
8 | :member_roles, |
|
25 | :member_roles, | |
9 | :members, |
|
26 | :members, | |
10 | :enabled_modules, |
|
27 | :enabled_modules, | |
11 | :workflows |
|
28 | :workflows | |
12 |
|
29 | |||
13 | def setup |
|
30 | def setup | |
14 | Setting.rest_api_enabled = '0' |
|
31 | Setting.rest_api_enabled = '0' | |
15 | Setting.login_required = '1' |
|
32 | Setting.login_required = '1' | |
16 | end |
|
33 | end | |
17 |
|
34 | |||
18 | def teardown |
|
35 | def teardown | |
19 | Setting.rest_api_enabled = '1' |
|
36 | Setting.rest_api_enabled = '1' | |
20 | Setting.login_required = '0' |
|
37 | Setting.login_required = '0' | |
21 | end |
|
38 | end | |
22 |
|
39 | |||
23 | def test_with_a_valid_api_token |
|
40 | def test_with_a_valid_api_token | |
24 | @user = User.generate! |
|
41 | @user = User.generate! | |
25 | @token = Token.create!(:user => @user, :action => 'api') |
|
42 | @token = Token.create!(:user => @user, :action => 'api') | |
26 |
|
43 | |||
27 | get "/news.xml?key=#{@token.value}" |
|
44 | get "/news.xml?key=#{@token.value}" | |
28 | assert_response :unauthorized |
|
45 | assert_response :unauthorized | |
29 | assert_equal User.anonymous, User.current |
|
46 | assert_equal User.anonymous, User.current | |
30 |
|
47 | |||
31 | get "/news.json?key=#{@token.value}" |
|
48 | get "/news.json?key=#{@token.value}" | |
32 | assert_response :unauthorized |
|
49 | assert_response :unauthorized | |
33 | assert_equal User.anonymous, User.current |
|
50 | assert_equal User.anonymous, User.current | |
34 | end |
|
51 | end | |
35 |
|
52 | |||
36 | def test_with_valid_username_password_http_authentication |
|
53 | def test_with_valid_username_password_http_authentication | |
37 | @user = User.generate! do |user| |
|
54 | @user = User.generate! do |user| | |
38 | user.password = 'my_password' |
|
55 | user.password = 'my_password' | |
39 | end |
|
56 | end | |
40 |
|
57 | |||
41 | get "/news.xml", nil, credentials(@user.login, 'my_password') |
|
58 | get "/news.xml", nil, credentials(@user.login, 'my_password') | |
42 | assert_response :unauthorized |
|
59 | assert_response :unauthorized | |
43 | assert_equal User.anonymous, User.current |
|
60 | assert_equal User.anonymous, User.current | |
44 |
|
61 | |||
45 | get "/news.json", nil, credentials(@user.login, 'my_password') |
|
62 | get "/news.json", nil, credentials(@user.login, 'my_password') | |
46 | assert_response :unauthorized |
|
63 | assert_response :unauthorized | |
47 | assert_equal User.anonymous, User.current |
|
64 | assert_equal User.anonymous, User.current | |
48 | end |
|
65 | end | |
49 |
|
66 | |||
50 | def test_with_valid_token_http_authentication |
|
67 | def test_with_valid_token_http_authentication | |
51 | @user = User.generate! |
|
68 | @user = User.generate! | |
52 | @token = Token.create!(:user => @user, :action => 'api') |
|
69 | @token = Token.create!(:user => @user, :action => 'api') | |
53 |
|
70 | |||
54 | get "/news.xml", nil, credentials(@token.value, 'X') |
|
71 | get "/news.xml", nil, credentials(@token.value, 'X') | |
55 | assert_response :unauthorized |
|
72 | assert_response :unauthorized | |
56 | assert_equal User.anonymous, User.current |
|
73 | assert_equal User.anonymous, User.current | |
57 |
|
74 | |||
58 | get "/news.json", nil, credentials(@token.value, 'X') |
|
75 | get "/news.json", nil, credentials(@token.value, 'X') | |
59 | assert_response :unauthorized |
|
76 | assert_response :unauthorized | |
60 | assert_equal User.anonymous, User.current |
|
77 | assert_equal User.anonymous, User.current | |
61 | end |
|
78 | end | |
62 | end |
|
79 | end |
@@ -1,38 +1,55 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
2 |
|
19 | |||
3 | class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base |
|
20 | class Redmine::ApiTest::HttpBasicLoginTest < Redmine::ApiTest::Base | |
4 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
5 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
6 | :projects_trackers, |
|
23 | :projects_trackers, | |
7 | :roles, |
|
24 | :roles, | |
8 | :member_roles, |
|
25 | :member_roles, | |
9 | :members, |
|
26 | :members, | |
10 | :enabled_modules, |
|
27 | :enabled_modules, | |
11 | :workflows |
|
28 | :workflows | |
12 |
|
29 | |||
13 | def setup |
|
30 | def setup | |
14 | Setting.rest_api_enabled = '1' |
|
31 | Setting.rest_api_enabled = '1' | |
15 | Setting.login_required = '1' |
|
32 | Setting.login_required = '1' | |
16 | end |
|
33 | end | |
17 |
|
34 | |||
18 | def teardown |
|
35 | def teardown | |
19 | Setting.rest_api_enabled = '0' |
|
36 | Setting.rest_api_enabled = '0' | |
20 | Setting.login_required = '0' |
|
37 | Setting.login_required = '0' | |
21 | end |
|
38 | end | |
22 |
|
39 | |||
23 | # Using the NewsController because it's a simple API. |
|
40 | # Using the NewsController because it's a simple API. | |
24 | context "get /news" do |
|
41 | context "get /news" do | |
25 | setup do |
|
42 | setup do | |
26 | project = Project.find('onlinestore') |
|
43 | project = Project.find('onlinestore') | |
27 | EnabledModule.create(:project => project, :name => 'news') |
|
44 | EnabledModule.create(:project => project, :name => 'news') | |
28 | end |
|
45 | end | |
29 |
|
46 | |||
30 | context "in :xml format" do |
|
47 | context "in :xml format" do | |
31 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml") |
|
48 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.xml") | |
32 | end |
|
49 | end | |
33 |
|
50 | |||
34 | context "in :json format" do |
|
51 | context "in :json format" do | |
35 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json") |
|
52 | should_allow_http_basic_auth_with_username_and_password(:get, "/projects/onlinestore/news.json") | |
36 | end |
|
53 | end | |
37 | end |
|
54 | end | |
38 | end |
|
55 | end |
@@ -1,34 +1,51 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
2 |
|
19 | |||
3 | class Redmine::ApiTest::HttpBasicLoginWithApiTokenTest < Redmine::ApiTest::Base |
|
20 | class Redmine::ApiTest::HttpBasicLoginWithApiTokenTest < Redmine::ApiTest::Base | |
4 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
5 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
6 | :projects_trackers, |
|
23 | :projects_trackers, | |
7 | :roles, |
|
24 | :roles, | |
8 | :member_roles, |
|
25 | :member_roles, | |
9 | :members, |
|
26 | :members, | |
10 | :enabled_modules, |
|
27 | :enabled_modules, | |
11 | :workflows |
|
28 | :workflows | |
12 |
|
29 | |||
13 | def setup |
|
30 | def setup | |
14 | Setting.rest_api_enabled = '1' |
|
31 | Setting.rest_api_enabled = '1' | |
15 | Setting.login_required = '1' |
|
32 | Setting.login_required = '1' | |
16 | end |
|
33 | end | |
17 |
|
34 | |||
18 | def teardown |
|
35 | def teardown | |
19 | Setting.rest_api_enabled = '0' |
|
36 | Setting.rest_api_enabled = '0' | |
20 | Setting.login_required = '0' |
|
37 | Setting.login_required = '0' | |
21 | end |
|
38 | end | |
22 |
|
39 | |||
23 | # Using the NewsController because it's a simple API. |
|
40 | # Using the NewsController because it's a simple API. | |
24 | context "get /news" do |
|
41 | context "get /news" do | |
25 |
|
42 | |||
26 | context "in :xml format" do |
|
43 | context "in :xml format" do | |
27 | should_allow_http_basic_auth_with_key(:get, "/news.xml") |
|
44 | should_allow_http_basic_auth_with_key(:get, "/news.xml") | |
28 | end |
|
45 | end | |
29 |
|
46 | |||
30 | context "in :json format" do |
|
47 | context "in :json format" do | |
31 | should_allow_http_basic_auth_with_key(:get, "/news.json") |
|
48 | should_allow_http_basic_auth_with_key(:get, "/news.json") | |
32 | end |
|
49 | end | |
33 | end |
|
50 | end | |
34 | end |
|
51 | end |
@@ -1,33 +1,50 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
1 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
2 |
|
19 | |||
3 | class Redmine::ApiTest::TokenAuthenticationTest < Redmine::ApiTest::Base |
|
20 | class Redmine::ApiTest::TokenAuthenticationTest < Redmine::ApiTest::Base | |
4 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
5 | :enumerations, :users, :issue_categories, |
|
22 | :enumerations, :users, :issue_categories, | |
6 | :projects_trackers, |
|
23 | :projects_trackers, | |
7 | :roles, |
|
24 | :roles, | |
8 | :member_roles, |
|
25 | :member_roles, | |
9 | :members, |
|
26 | :members, | |
10 | :enabled_modules, |
|
27 | :enabled_modules, | |
11 | :workflows |
|
28 | :workflows | |
12 |
|
29 | |||
13 | def setup |
|
30 | def setup | |
14 | Setting.rest_api_enabled = '1' |
|
31 | Setting.rest_api_enabled = '1' | |
15 | Setting.login_required = '1' |
|
32 | Setting.login_required = '1' | |
16 | end |
|
33 | end | |
17 |
|
34 | |||
18 | def teardown |
|
35 | def teardown | |
19 | Setting.rest_api_enabled = '0' |
|
36 | Setting.rest_api_enabled = '0' | |
20 | Setting.login_required = '0' |
|
37 | Setting.login_required = '0' | |
21 | end |
|
38 | end | |
22 |
|
39 | |||
23 | # Using the NewsController because it's a simple API. |
|
40 | # Using the NewsController because it's a simple API. | |
24 | context "get /news" do |
|
41 | context "get /news" do | |
25 | context "in :xml format" do |
|
42 | context "in :xml format" do | |
26 | should_allow_key_based_auth(:get, "/news.xml") |
|
43 | should_allow_key_based_auth(:get, "/news.xml") | |
27 | end |
|
44 | end | |
28 |
|
45 | |||
29 | context "in :json format" do |
|
46 | context "in :json format" do | |
30 | should_allow_key_based_auth(:get, "/news.json") |
|
47 | should_allow_key_based_auth(:get, "/news.json") | |
31 | end |
|
48 | end | |
32 | end |
|
49 | end | |
33 | end |
|
50 | end |
General Comments 0
You need to be logged in to leave comments.
Login now