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 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
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
13 changes: 9 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
version: "5.3.3"
version: "5.3.4"
changelog:
- date: 2024-04-29
version: v5.3.4
changes:
- type: bug
text: "Fix issue because of which client didn't encode App Context get all event `filter` query value."
- date: 2024-01-29
version: v5.3.3
changes:
Expand Down Expand Up @@ -571,7 +576,7 @@ sdks:
- x86-64
- distribution-type: package
distribution-repository: RubyGems
package-name: pubnub-5.3.3.gem
package-name: pubnub-5.3.4.gem
location: https://rubygems.org/gems/pubnub
requires:
- name: addressable
Expand Down Expand Up @@ -676,8 +681,8 @@ sdks:
- x86-64
- distribution-type: library
distribution-repository: GitHub release
package-name: pubnub-5.3.3.gem
location: https://github.com/pubnub/ruby/releases/download/v5.3.3/pubnub-5.3.3.gem
package-name: pubnub-5.3.4.gem
location: https://github.com/pubnub/ruby/releases/download/v5.3.4/pubnub-5.3.4.gem
requires:
- name: addressable
min-version: 2.0.0
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v5.3.4
April 29 2024

#### Fixed
- Fix issue because of which client didn't encode App Context get all event `filter` query value.

## v5.3.3
January 29 2024

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pubnub (5.3.3)
pubnub (5.3.4)
addressable (>= 2.0.0)
concurrent-ruby (~> 1.1.5)
concurrent-ruby-edge (~> 0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.3
5.3.4

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
2 changes: 1 addition & 1 deletion lib/pubnub/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Toplevel Pubnub module.
module Pubnub
VERSION = '5.3.3'.freeze
VERSION = '5.3.4'.freeze
end
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