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

Fix filter value encoding for PAM #159

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ concurrency:
defaults:
run:
shell: bash
env:
SDK_PAM_SUB_KEY: ${{ secrets.SDK_PAM_SUB_KEY }}
SDK_PAM_PUB_KEY: ${{ secrets.SDK_PAM_PUB_KEY }}
SDK_PAM_SEC_KEY: ${{ secrets.SDK_PAM_SEC_KEY }}
SDK_SUB_KEY: ${{ secrets.SDK_SUB_KEY }}
SDK_PUB_KEY: ${{ secrets.SDK_PUB_KEY }}



jobs:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions lib/pubnub/event/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def super_admin_signature(http_method, body)

def variables_for_signature
unsorted_params = parameters(true)
sorted_keys = unsorted_params.sort_by {|k, v| k.to_s}
sorted_keys = unsorted_params.sort_by { |k, v| k.to_s }
sorted_keys.map do |k, v|
if %w[meta ortt].include?(k.to_s)
encoded_value = URI.encode_www_form_component(v.to_json).gsub('+', '%20')
if %w[meta ortt filter].include?(k.to_s)
value_for_encoding = v.is_a?(String) ? v : v.to_json
encoded_value = URI.encode_www_form_component(value_for_encoding).gsub('+', '%20')
"#{k}=#{encoded_value}"
elsif %w[t state filter-expr sort filter].include?(k.to_s)
elsif %w[t state filter-expr sort].include?(k.to_s)
"#{k}=#{v}"
else
"#{k}=#{URI.encode_www_form_component(v.to_s).gsub('+', '%20')}"
Expand Down
7 changes: 4 additions & 3 deletions lib/pubnub/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ def parse_json(string)
def params_hash_to_url_params(hash)
params = ''
hash.sort_by { |k, _v| k.to_s }.to_h.each do |key, value|
if %w[meta ortt].include?(key.to_s)
encoded_value = URI.encode_www_form_component(value.to_json).gsub('+', '%20')
if %w[meta ortt filter].include?(key.to_s)
value_for_encoding = value.is_a?(String) ? value : value.to_json
encoded_value = URI.encode_www_form_component(value_for_encoding).gsub('+', '%20')
params << "#{key}=#{encoded_value}&"
elsif %w[t state filter filter-expr].include?(key.to_s)
elsif %w[t state filter-expr].include?(key.to_s)
params << "#{key}=#{value}&"
else
params << "#{key}=#{URI.encode_www_form_component(value).gsub('+', '%20')}&"
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/events/channel_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@
end
end

it "get_all_channels_metadata_with_filter_and_secret" do
VCR.use_cassette("lib/events/get_all_channels_metadata_with_filter_and_secret", record: :once) do
Pubnub::GetAllChannelsMetadata.any_instance.stub(:current_time).and_return "1714133102"
pubnub = Pubnub.new(
:subscribe_key => 'sub-a-mock-key', # ENV['SDK_PAM_SUB_KEY'],
:publish_key => 'sub-a-mock-key', # ENV['SDK_PAM_PUB_KEY'],
:secret_key => 'sec-a-mock-key', # ENV['SDK_PAM_SEC_KEY'],
:user_id => "ruby-test-uuid",
)

pubnub.set_channel_metadata(
channel: "rb_channel",
metadata: { name: "some_name", custom: { XXX: "YYYY" } },
include: { custom: true },
http_sync: true
)

envelope = pubnub.get_all_channels_metadata(
limit: 5,
include: { custom: true },
filter: '(name=="some_name")',
http_sync: true
)

expect(envelope.result).to satisfies_schema Pubnub::Schemas::Envelope::ResultSchema.new
expect(envelope.status).to satisfies_schema Pubnub::Schemas::Envelope::StatusSchema.new
end
end

it "remove_channel_metadata_works" do
VCR.use_cassette("lib/events/remove_channel_metadata", record: :once) do
envelope = @pubnub.remove_channel_metadata(channel: "rb_channel").value
Expand Down
Loading