Skip to content

Commit

Permalink
fix(pam): fix filter value encoding for PAM
Browse files Browse the repository at this point in the history
Fix issue because of which client didn't encoded App Context get all event `filter` query value.
  • Loading branch information
parfeon committed Apr 26, 2024
1 parent f7bf448 commit 6aed9d8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 7 deletions.
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 => ENV['SDK_PAM_SUB_KEY'] || 'sub-a-mock-key',
:publish_key => ENV['SDK_PAM_PUB_KEY'] || 'sub-a-mock-key',
:secret_key => ENV['SDK_PAM_SEC_KEY'] || 'sec-a-mock-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

0 comments on commit 6aed9d8

Please sign in to comment.