-
Notifications
You must be signed in to change notification settings - Fork 71
secure pipeline command #1370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
secure pipeline command #1370
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
071cabd
hardcode perm for managing pipelines
3f13064
pipeline command tests
5bfb024
add comment to hardcoded permission
9b6f5aa
test fixes
6f37436
add some comments about the scope of results
09ff6bf
dry up the pipeline list command a bit
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| defmodule Cog.Test.Pipeline.InfoTest do | ||
| use Cog.CommandCase, command_module: Cog.Commands.Pipeline.Info, | ||
| command_tag: "pipeline_info" | ||
|
|
||
| alias Cog.Repository.PipelineHistory | ||
| import Cog.Support.ModelUtilities, only: [user: 1, | ||
| with_permission: 2] | ||
|
|
||
| setup do | ||
| user = user("pipelineuser") | ||
| other_user = user("otherpipelineuser") | ||
| admin_user = user("adminpipelineuser") | ||
| |> with_permission("operable:manage_user_pipeline") | ||
|
|
||
| pipeline = PipelineHistory.new(%{id: "fakeid", | ||
| text: "Some text", | ||
| room_name: "FakeRoom", | ||
| room_id: "fakeroomid", | ||
| provider: "test", | ||
| count: 1, | ||
| state: "running", | ||
| user_id: user.id}) | ||
|
|
||
| {:ok, %{user: user, | ||
| other_user: other_user, | ||
| admin_user: admin_user, | ||
| pipeline: pipeline}} | ||
| end | ||
|
|
||
| test "pipeline info", %{user: user, pipeline: pipeline} do | ||
| response = new_req(args: [pipeline.id], user: user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert([%{id: "fakeid", | ||
| room: "FakeRoom", | ||
| state: "running", | ||
| text: "Some text", | ||
| user: "pipelineuser"}] = response) | ||
| end | ||
|
|
||
| test "other user can't see pipeline info without permission", | ||
| %{other_user: other_user, | ||
| pipeline: pipeline} do | ||
|
|
||
| response = new_req(args: [pipeline.id], user: other_user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert([] = response) | ||
| end | ||
|
|
||
| test "can see pipeline info for other's pipelines with permission", | ||
| %{admin_user: admin_user, | ||
| pipeline: pipeline} do | ||
|
|
||
| response = new_req(args: [pipeline.id], user: admin_user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert([%{id: "fakeid", | ||
| room: "FakeRoom", | ||
| state: "running", | ||
| text: "Some text", | ||
| user: "pipelineuser"}] = response) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| defmodule Cog.Test.Pipeline.KillTest do | ||
| use Cog.CommandCase, command_module: Cog.Commands.Pipeline.Kill, | ||
| command_tag: "pipeline_kill" | ||
|
|
||
| alias Cog.Repository.PipelineHistory | ||
| import Cog.Support.ModelUtilities, only: [user: 1, | ||
| with_permission: 2] | ||
|
|
||
| setup do | ||
| user = user("pipelineuser") | ||
| other_user = user("otherpipelineuser") | ||
| admin_user = user("adminpipelineuser") | ||
| |> with_permission("operable:manage_user_pipeline") | ||
|
|
||
| {:ok, task} = Task.start_link(fn -> Process.sleep(:infinity) end) | ||
|
|
||
| pipeline = PipelineHistory.new(%{id: "fakeid", | ||
| text: "Some text", | ||
| room_name: "FakeRoom", | ||
| room_id: "fakeroomid", | ||
| provider: "test", | ||
| count: 1, | ||
| pid: task, | ||
| state: "running", | ||
| user_id: user.id}) | ||
|
|
||
| {:ok, %{user: user, | ||
| other_user: other_user, | ||
| admin_user: admin_user, | ||
| pipeline: pipeline}} | ||
| end | ||
|
|
||
| test "a user can kill their own pipeline", | ||
| %{user: user, pipeline: pipeline} do | ||
|
|
||
| response = new_req(args: [pipeline.id], user: user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert(%{killed: ["fakeid"], | ||
| killed_text: "fakeid"} = response) | ||
| end | ||
|
|
||
| test "a user cannot kill other user's pipelines", | ||
| %{other_user: other_user, pipeline: pipeline} do | ||
|
|
||
| response = new_req(args: [pipeline.id], user: other_user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert(%{killed: [], killed_text: "none"} = response) | ||
| end | ||
|
|
||
| test "a user can kill othe user's pipelines with the correct permission", | ||
| %{admin_user: admin_user, pipeline: pipeline} do | ||
|
|
||
| response = new_req(args: [pipeline.id], user: admin_user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert(%{killed: ["fakeid"], | ||
| killed_text: "fakeid"} = response) | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| defmodule Cog.Test.Pipeline.ListTest do | ||
| use Cog.CommandCase, command_module: Cog.Commands.Pipeline.List, | ||
| command_tag: "pipeline_list" | ||
|
|
||
| alias Cog.Repository.PipelineHistory | ||
| import Cog.Support.ModelUtilities, only: [user: 1, | ||
| with_permission: 2] | ||
|
|
||
| setup do | ||
| user = user("pipelineuser") | ||
| other_user = user("otherpipelineuser") | ||
| admin_user = user("adminpipelineuser") | ||
| |> with_permission("operable:manage_user_pipeline") | ||
|
|
||
| for n <- 1..5 do | ||
| PipelineHistory.new(%{id: "fakeid#{n}", | ||
| text: "Some text", | ||
| room_name: "FakeRoom", | ||
| room_id: "fakeroomid", | ||
| provider: "test", | ||
| count: n, | ||
| state: "running", | ||
| user_id: user.id}) | ||
| end | ||
|
|
||
| {:ok, %{user: user, other_user: other_user, admin_user: admin_user}} | ||
| end | ||
|
|
||
| test "listing pipelines", %{user: user} do | ||
| response = new_req(user: user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert(%{pipeline_count: 5, | ||
| pipelines: [%{id: "fakeid5"}, | ||
| %{id: "fakeid4"}, | ||
| %{id: "fakeid3"}, | ||
| %{id: "fakeid2"}, | ||
| %{id: "fakeid1"}]} = response) | ||
| end | ||
|
|
||
| test "Can't list other user's pipelines without permission", | ||
| %{user: user, other_user: other_user} do | ||
|
|
||
| response = new_req(options: %{"user" => user.username}, user: other_user) | ||
| |> send_req() | ||
| |> unwrap_error() | ||
|
|
||
| assert("You must have the operable:manage_user_pipeline permission to view pipeline history for other users." = response) | ||
| end | ||
|
|
||
| test "Can list other user's pipelines with permission", %{user: user, admin_user: admin_user} do | ||
| response = new_req(options: %{"user" => user.username}, user: admin_user) | ||
| |> send_req() | ||
| |> unwrap() | ||
|
|
||
| assert(%{pipeline_count: 5, | ||
| pipelines: [%{id: "fakeid5"}, | ||
| %{id: "fakeid4"}, | ||
| %{id: "fakeid3"}, | ||
| %{id: "fakeid2"}, | ||
| %{id: "fakeid1"}]} = response) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we consolidate some of this? Seems like it's doing the same kind of checks as in other places in this PR (e.g.
if has_perm? || entry.user.id == req_user.id do...)