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

Check that slack token isn't empty before using it #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/smart_todo/dispatchers/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Slack < Base
class << self
def validate_options!(options)
options[:slack_token] ||= ENV.fetch("SMART_TODO_SLACK_TOKEN") { raise(ArgumentError, "Missing :slack_token") }
raise(ArgumentError, "Missing :slack_token") if options[:slack_token].empty?

options.fetch(:fallback_channel) { raise(ArgumentError, "Missing :fallback_channel") }
end
Expand Down
21 changes: 21 additions & 0 deletions test/smart_todo/dispatchers/slack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ def test_validate_options_when_all_mandatory_options_are_passed
Slack.validate_options!(slack_token: "123", fallback_channel: "#general")
end

def test_validate_options_when_token_option_passed_is_empty_string
error = assert_raises(ArgumentError) do
Slack.validate_options!(slack_token: "", fallback_channel: "#general")
end

assert_equal("Missing :slack_token", error.message)
ensure
ENV.delete("SMART_TODO_SLACK_TOKEN")
end

def test_validate_options_when_token_option_is_missing
error = assert_raises(ArgumentError) do
Slack.validate_options!(fallback_channel: "#general")
Expand All @@ -128,6 +138,17 @@ def test_validate_options_when_token_option_is_missing
assert_equal("Missing :slack_token", error.message)
end

def test_validate_options_when_token_option_env_is_empty_string
ENV["SMART_TODO_SLACK_TOKEN"] = ""
error = assert_raises(ArgumentError) do
Slack.validate_options!(fallback_channel: "#general")
end

assert_equal("Missing :slack_token", error.message)
ensure
ENV.delete("SMART_TODO_SLACK_TOKEN")
end

def test_when_slack_token_option_is_in_the_environment
ENV["SMART_TODO_SLACK_TOKEN"] = "123"
options = { fallback_channel: "#general" }
Expand Down
Loading