Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
Validate channel name length
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Ascencio committed Jun 5, 2015
1 parent cf84e6d commit 8d898ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/slanger/api/request_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def validate_socket_id!(socket_id)
end

def validate_channel_id!(channel_id)
validate_with_regex!(/\A[\w@\-;_.=,]+\z/, channel_id, "channel_id")
validate_with_regex!(/\A[\w@\-;_.=,]{1,164}\z/, channel_id, "channel_id")
end

def validate_with_regex!(regex, value, name)
Expand Down
14 changes: 11 additions & 3 deletions spec/unit/request_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,30 @@
let(:body) { {socket_id: "1234.5678", channels: channels}.to_json }

context "with valid channels" do
let(:channels) { ["MY_CHANNEL", "presence-abcd", "foo-bar_1234@=,.;"] }
let(:channels) { ["MY_CHANNEL", "presence-abcd", "foo-bar_1234@=,.;", "a"*164] }

it "returns an array of valid channel_id values" do
rv = Slanger::Api::RequestValidation.new(body, {}, "")

expect(rv.channels).to eq ["MY_CHANNEL", "presence-abcd", "foo-bar_1234@=,.;"]
expect(rv.channels).to eq ["MY_CHANNEL", "presence-abcd", "foo-bar_1234@=,.;", "a"*164]
end
end

context "with invalid channels" do
context "with invalid characters" do
let(:channels) { ["MY_CHANNEL:presence-abcd", "presence-abcd"] }

it "rejects invalid channels" do
expect{ Slanger::Api::RequestValidation.new(body, {}, "")}.to raise_error Slanger::Api::InvalidRequest
end
end

context "with invalid channel length" do
let(:channels) { ["a"*165] }

it "rejects names longer than 164 characters" do
expect{ Slanger::Api::RequestValidation.new(body, {}, "")}.to raise_error Slanger::Api::InvalidRequest
end
end
end

describe "#socket_id" do
Expand Down

0 comments on commit 8d898ff

Please sign in to comment.