From 0d04724fa1cd670124b8ad9a3860bfa476c50f99 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 18 Nov 2016 10:00:40 +0100 Subject: More coverage on service level --- spec/requests/api/services_spec.rb | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'spec/requests') diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 2aadab3cbe1..fb234ab8ed1 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -88,4 +88,50 @@ describe API::API, api: true do end end end + + describe 'POST /projects/:id/services/:slug/trigger' do + let!(:project) { create(:empty_project) } + let(:service_name) { 'mattermost_command' } + + context 'no service is available' do + it 'returns a not found message' do + post api("/projects/#{project.id}/services/mattermost_command/trigger") + + expect(response).to have_http_status(404) + end + end + + context 'the service exists' do + context 'the service is not active' do + let!(:inactive_service) do + project.create_mattermost_command_service( + active: false, + properties: { token: 'token' } + ) + end + + it 'when the service is inactive' do + post api("/projects/#{project.id}/services/mattermost_command/trigger") + + expect(response).to have_http_status(404) + end + end + + context 'the service is active' do + let!(:active_service) do + project.create_mattermost_command_service( + active: true, + properties: { token: 'token' } + ) + end + let(:params) { { token: 'token' } } + + it 'retusn status 200' do + post api("/projects/#{project.id}/services/mattermost_command/trigger"), params + + expect(response).to have_http_status(200) + end + end + end + end end -- cgit v1.2.3 From f749fb7fe0574d07eeb38561b9af62754e518281 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 18 Nov 2016 11:38:54 +0100 Subject: Improve style, add more tests --- spec/requests/api/services_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'spec/requests') diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index fb234ab8ed1..765d662e52b 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -102,6 +102,8 @@ describe API::API, api: true do end context 'the service exists' do + let(:params) { { token: 'token' } } + context 'the service is not active' do let!(:inactive_service) do project.create_mattermost_command_service( @@ -124,7 +126,6 @@ describe API::API, api: true do properties: { token: 'token' } ) end - let(:params) { { token: 'token' } } it 'retusn status 200' do post api("/projects/#{project.id}/services/mattermost_command/trigger"), params @@ -132,6 +133,15 @@ describe API::API, api: true do expect(response).to have_http_status(200) end end + + context 'when the project can not be found' do + it 'returns a generic 404' do + post api("/projects/404/services/mattermost_command/trigger"), params + + expect(response).to have_http_status(404) + expect(json_response["message"]).to eq '404 Not Found' + end + end end end end -- cgit v1.2.3 From dd826a5f20837f33263c658e41a4def0fc932069 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 18 Nov 2016 12:08:30 +0100 Subject: Return a consistent not found message This prevents leakage of project names on an endpoint which is unauthenticated and thus open to the world. --- spec/requests/api/services_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'spec/requests') diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 765d662e52b..782d76db318 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -95,9 +95,10 @@ describe API::API, api: true do context 'no service is available' do it 'returns a not found message' do - post api("/projects/#{project.id}/services/mattermost_command/trigger") + post api("/projects/#{project.id}/services/idonotexist/trigger") expect(response).to have_http_status(404) + expect(json_response["message"]).to eq("404 Service Not Found") end end @@ -139,7 +140,7 @@ describe API::API, api: true do post api("/projects/404/services/mattermost_command/trigger"), params expect(response).to have_http_status(404) - expect(json_response["message"]).to eq '404 Not Found' + expect(json_response["message"]).to eq("404 Service Not Found") end end end -- cgit v1.2.3 From 1db1896ed2375481d53f74f7900d259fe068ef64 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 18 Nov 2016 16:16:45 +0100 Subject: Rename mattermost_command to mattermost_slash_commands --- spec/requests/api/services_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/requests') diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 782d76db318..ce9c96ace21 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -91,7 +91,7 @@ describe API::API, api: true do describe 'POST /projects/:id/services/:slug/trigger' do let!(:project) { create(:empty_project) } - let(:service_name) { 'mattermost_command' } + let(:service_name) { 'mattermost_slash_commands' } context 'no service is available' do it 'returns a not found message' do @@ -107,14 +107,14 @@ describe API::API, api: true do context 'the service is not active' do let!(:inactive_service) do - project.create_mattermost_command_service( + project.create_mattermost_slash_commands_service( active: false, properties: { token: 'token' } ) end it 'when the service is inactive' do - post api("/projects/#{project.id}/services/mattermost_command/trigger") + post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger") expect(response).to have_http_status(404) end @@ -122,14 +122,14 @@ describe API::API, api: true do context 'the service is active' do let!(:active_service) do - project.create_mattermost_command_service( + project.create_mattermost_slash_commands_service( active: true, properties: { token: 'token' } ) end it 'retusn status 200' do - post api("/projects/#{project.id}/services/mattermost_command/trigger"), params + post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params expect(response).to have_http_status(200) end @@ -137,7 +137,7 @@ describe API::API, api: true do context 'when the project can not be found' do it 'returns a generic 404' do - post api("/projects/404/services/mattermost_command/trigger"), params + post api("/projects/404/services/mattermost_slash_commands/trigger"), params expect(response).to have_http_status(404) expect(json_response["message"]).to eq("404 Service Not Found") -- cgit v1.2.3