Skip to content

Commit 56c6ea5

Browse files
committed
Encode X-Goog-Upload-File-Name header on binary upload
1 parent b8f1353 commit 56c6ea5

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lib/fastlane/plugin/firebase_app_distribution/client/firebase_app_distribution_api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def upload_binary(app_name, binary_path, platform, timeout)
3737
request.headers[AUTHORIZATION] = "Bearer " + @auth_token
3838
request.headers[CONTENT_TYPE] = APPLICATION_OCTET_STREAM
3939
request.headers[CLIENT_VERSION] = client_version_header_value
40-
request.headers["X-Goog-Upload-File-Name"] = File.basename(binary_path)
40+
request.headers["X-Goog-Upload-File-Name"] = CGI.escape(File.basename(binary_path))
4141
request.headers["X-Goog-Upload-Protocol"] = "raw"
4242
end
4343

spec/firebase_app_distribution_api_client_spec.rb

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
describe Fastlane::Client::FirebaseAppDistributionApiClient do
22
let(:project_number) { 1_234_567_890 }
3-
let(:app_id) { "1:1234567890:android:321abc456def7890" }
4-
let(:api_client) { Fastlane::Client::FirebaseAppDistributionApiClient.new("auth_token") }
5-
let(:headers) { { 'Authorization' => 'Bearer auth_token' } }
3+
let(:app_id) { '1:1234567890:android:321abc456def7890' }
4+
let(:app_name) { '1234567890/apps/1:1234567890:android:321abc456def7890' }
5+
let(:binary_path) { '/path/to/β.ipa' }
6+
let(:binary_file) { StringIO.new('binary_file') }
7+
let(:api_client) { Fastlane::Client::FirebaseAppDistributionApiClient.new('auth_token') }
8+
let(:upload_headers) { { 'Authorization' => 'Bearer auth_token', 'X-Goog-Upload-File-Name' => '%CE%B2.ipa' } }
9+
let(:udid_headers) { { 'Authorization' => 'Bearer auth_token' } }
610
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
711
let(:conn) do
8-
Faraday.new(url: "https://firebaseappdistribution.googleapis.com") do |b|
12+
Faraday.new(url: 'https://firebaseappdistribution.googleapis.com') do |b|
913
b.response(:json, parser_options: { symbolize_names: true })
1014
b.response(:raise_error)
1115
b.adapter(:test, stubs)
@@ -22,6 +26,25 @@
2226
Faraday.default_connection = nil
2327
end
2428

29+
describe '#upload_binary' do
30+
let(:upload) do
31+
app_name
32+
end
33+
34+
it 'returns the long-running operation name when the upload call is successful' do
35+
allow(File).to receive(:open).with(binary_path, 'rb').and_return(binary_file)
36+
stubs.post("/upload/v1/#{app_name}/releases:upload", 'binary_file', upload_headers) do |_|
37+
[
38+
200,
39+
{}, # response headers
40+
{ name: 'lro-name' }
41+
]
42+
end
43+
result = api_client.upload_binary(app_name, binary_path, 'ios', 0)
44+
expect(result).to eq('lro-name')
45+
end
46+
end
47+
2548
describe '#get_udids' do
2649
let(:udids) do
2750
[
@@ -31,7 +54,7 @@
3154
end
3255

3356
it 'returns the list of UDIDs when the get call is successful' do
34-
stubs.get("/v1alpha/apps/#{app_id}/testers:getTesterUdids", headers) do |_|
57+
stubs.get("/v1alpha/apps/#{app_id}/testers:getTesterUdids", udid_headers) do |_|
3558
[
3659
200,
3760
{}, # response headers
@@ -43,7 +66,7 @@
4366
end
4467

4568
it 'returns an empty list UDIDs when there are no udids' do
46-
stubs.get("/v1alpha/apps/#{app_id}/testers:getTesterUdids", headers) do |_|
69+
stubs.get("/v1alpha/apps/#{app_id}/testers:getTesterUdids", udid_headers) do |_|
4770
[
4871
200,
4972
{}, # response headers

0 commit comments

Comments
 (0)