@@ -65,15 +65,21 @@ def project
65
65
end
66
66
67
67
def setup
68
+ Setting . sys_api_enabled = '1'
69
+ Setting . sys_api_key = 'my_secret_key'
68
70
Project . stubs ( :find_by_identifier ) . with ( "github" ) . returns ( project )
69
71
70
72
# Make sure we don't run actual commands in test
71
73
GithubHook ::Updater . any_instance . expects ( :system ) . never
72
74
Repository . expects ( :fetch_changesets ) . never
73
75
end
74
76
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
77
83
end
78
84
79
85
def test_should_render_response_from_github_hook_when_done
@@ -83,6 +89,27 @@ def test_should_render_response_from_github_hook_when_done
83
89
assert_match "GithubHook: Redmine repository updated" , @response . body
84
90
end
85
91
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
+
86
113
def test_should_render_error_message
87
114
GithubHook ::Updater
88
115
. any_instance
@@ -115,7 +142,12 @@ def test_exec_should_log_output_from_git_as_error_when_things_go_sour
115
142
end
116
143
117
144
def test_should_respond_to_get
118
- get :index
145
+ get :index , :key => 'my_secret_key'
119
146
assert_response :success
120
147
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
121
153
end
0 commit comments