Skip to content
Merged
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
2 changes: 1 addition & 1 deletion app/models/user/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_bot!(attributes)

def authenticate_bot(bot_key)
bot_id, bot_token = bot_key.split("-")
active_bots.find_by(id: bot_id, bot_token: bot_token)
active_bots.find_by(id: bot_id, bot_token: bot_token) if bot_token.present?
end

def generate_bot_token
Expand Down
15 changes: 15 additions & 0 deletions test/models/user/bot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ class User::BotTest < ActiveSupport::TestCase
assert User.authenticate_bot(bot.bot_key)
end

test "authenticate rejects a key without a token" do
bot = User.create_bot!(name: "Bender")
bot.update_column(:bot_token, nil)

assert_nil User.authenticate_bot("#{bot.id}")
assert_nil User.authenticate_bot("#{bot.id}-")
end

test "authenticate rejects a key with an empty token" do
bot = User.create_bot!(name: "Bender")
bot.update_column(:bot_token, "")

assert_nil User.authenticate_bot("#{bot.id}--anything")
end

test "deliver message by webhook" do
WebMock.stub_request(:post, webhooks(:bender).url).to_return(status: 200)

Expand Down