Skip to content

Commit 6ca08d2

Browse files
committed
Fix functional test
1 parent 1d6b2de commit 6ca08d2

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

test/functional/github_hook_controller_test.rb

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,21 @@ def project
6565
end
6666

6767
def setup
68+
Setting.sys_api_enabled = '1'
69+
Setting.sys_api_key = 'my_secret_key'
6870
Project.stubs(:find_by_identifier).with("github").returns(project)
6971

7072
# Make sure we don't run actual commands in test
7173
GithubHook::Updater.any_instance.expects(:system).never
7274
Repository.expects(:fetch_changesets).never
7375
end
7476

75-
def do_post
76-
post :index, :payload => json
77+
def teardown
78+
Setting.clear_cache
79+
end
80+
81+
def do_post(key: 'my_secret_key')
82+
post :index, :payload => json, :key => key
7783
end
7884

7985
def test_should_render_response_from_github_hook_when_done
@@ -83,6 +89,27 @@ def test_should_render_response_from_github_hook_when_done
8389
assert_match "GithubHook: Redmine repository updated", @response.body
8490
end
8591

92+
def test_should_render_response_from_github_hook_when_done_with_empty_sys_api_key
93+
GithubHook::Updater.any_instance.expects(:update_repository).returns(true)
94+
with_settings :sys_api_key => '' do
95+
do_post :key => 'wrong_key'
96+
end
97+
assert_response :success
98+
assert_match "GithubHook: Redmine repository updated", @response.body
99+
end
100+
101+
def test_disabled_ws_should_respond_with_403
102+
with_settings :sys_api_enabled => '0' do
103+
do_post
104+
assert_response 403
105+
end
106+
end
107+
108+
def test_wrong_key_should_respond_with_403
109+
do_post :key => 'wrong_key'
110+
assert_response 403
111+
end
112+
86113
def test_should_render_error_message
87114
GithubHook::Updater
88115
.any_instance
@@ -115,7 +142,12 @@ def test_exec_should_log_output_from_git_as_error_when_things_go_sour
115142
end
116143

117144
def test_should_respond_to_get
118-
get :index
145+
get :index, :key => 'my_secret_key'
119146
assert_response :success
120147
end
148+
149+
def test_wrong_key_should_respond_to_get_with_403
150+
get :index, :key => 'wrong_key'
151+
assert_response 403
152+
end
121153
end

0 commit comments

Comments
 (0)