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 that Signed urls did not work with nth notation for groups as well as when using ~ in URLs #174

Merged
merged 2 commits into from
Jul 6, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Added
* Multi page conversion parameter (`save_in_group`) added to `DocumentConverter#convert` options.

### Fixed
* Fixed that signed URLs now work with ~ in the path. This also fixes signed URLs with grouped file URLs.

## 4.4.2 — 2024-05-29

### Fixed
Expand Down
9 changes: 7 additions & 2 deletions lib/uploadcare/signed_url_generators/akamai_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ def delimiter

def build_acl(uuid, acl, wildcard: false)
if wildcard
"/#{sanitized_string(uuid)}/*"
"/#{sanitized_delimiter_path(uuid)}/*"
else
"/#{sanitized_string(acl)}/"
"/#{sanitized_delimiter_path(acl)}/"
end
end

# Delimiter sanitization referenced from: https://github.com/uploadcare/pyuploadcare/blob/main/pyuploadcare/secure_url.py#L74
def sanitized_delimiter_path(path)
sanitized_string(path).gsub('~') { |escape_char| "%#{escape_char.ord.to_s(16).downcase}" }
end

def build_expire
(Time.now.to_i + ttl).to_s
end
Expand Down
18 changes: 18 additions & 0 deletions spec/uploadcare/signed_url_generators/akamai_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ module Uploadcare
expect(subject.generate_url(uuid, nil, wildcard: true)).to eq expected_url
end
end

context 'works with group' do
let(:uuid) { '83a8994a-e0b4-4091-9a10-5a847298e493~4' }

it 'returns correct url' do
expected_url = 'https://example.com/83a8994a-e0b4-4091-9a10-5a847298e493~4/?token=exp=1649343900~acl=/83a8994a-e0b4-4091-9a10-5a847298e493%7e4/*~hmac=f4d4c5da93324dffa2b5bb42d8a6cc693789077212cbdf599fe3220b9d37749d'
expect(subject.generate_url(uuid, nil, wildcard: true)).to eq expected_url
end
end

context 'works with nth file type notation for files within a group' do
let(:uuid) { '83a8994a-e0b4-4091-9a10-5a847298e493~4/nth/0/-/crop/250x250/1000,1000' }

it 'returns correct url' do
expected_url = 'https://example.com/83a8994a-e0b4-4091-9a10-5a847298e493~4/nth/0/-/crop/250x250/1000,1000/?token=exp=1649343900~acl=/83a8994a-e0b4-4091-9a10-5a847298e493%7e4/nth/0/-/crop/250x250/1000,1000/*~hmac=d483cfa64cffe617c1cc72d6f1d3287a74d27cb608bbf08dc07d3d61e29cd4be'
expect(subject.generate_url(uuid, nil, wildcard: true)).to eq expected_url
end
end
end
end
end
Loading