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

[regression][pilot] Fix upload using api_key_path + apple_id CLI options #18860

Merged
Merged
9 changes: 6 additions & 3 deletions pilot/lib/pilot/build_manager.rb
Expand Up @@ -14,6 +14,12 @@ def upload(options)
# Only need to login before upload if no apple_id was given
# 'login' will be deferred until before waiting for build processing
should_login_in_start = options[:apple_id].nil?

# see: https://github.com/fastlane/fastlane/issues/18767
# We will do App Store Connect API login, if needed on start and set the token to use JWT auth in the future.
# 'login' will happen only if token is not set and api-key or key-path is given
should_login_in_start = true if Spaceship::ConnectAPI.token.nil? && (options[:api_key_path] || options[:api_key])

start(options, should_login: should_login_in_start)

UI.user_error!("No ipa file given") unless config[:ipa]
Expand Down Expand Up @@ -366,9 +372,6 @@ def expire_previous_builds(build)
# If there are multiple teams, infer the provider from the selected team name.
# If there are fewer than two teams, don't infer the provider.
def transporter_for_selected_team(options)
# Ensure that user is authenticated
start(options)

# Use JWT auth
api_token = Spaceship::ConnectAPI.token
unless api_token.nil?
Expand Down
83 changes: 83 additions & 0 deletions pilot/spec/build_manager_spec.rb
Expand Up @@ -534,6 +534,89 @@

fake_build_manager.upload(upload_options)
end

shared_examples "performing the spaceship login for JWT auth by pilot" do
before(:each) do
expect(fake_build_manager).to(receive(:login))
end

it "performs the login using Manager.login" do
fake_build_manager.upload(upload_options)
end
end

shared_examples "skipping the spaceship login for JWT auth by pilot" do
before(:each) do
expect(fake_build_manager).not_to(receive(:login))
end

it "skips the login using Manager.login" do
fake_build_manager.upload(upload_options)
end
end

describe "what happens when spaceship token is nil" do
before(:each) do
allow(Spaceship::ConnectAPI).to receive(:token).and_return(nil)
end

context "when input options has NO api_key or api_key_path input" do
before(:each) do
upload_options[:api_key] = nil
upload_options[:api_key_path] = nil
end

it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end

context "when input options has api_key input" do
before(:each) do
upload_options[:api_key] = "fake api key"
end

it_behaves_like "performing the spaceship login for JWT auth by pilot"
end

context "when input options has api_key_path input" do
before(:each) do
upload_options[:api_key_path] = "./spaceship/spec/connect_api/fixtures/asc_key.json"
end

it_behaves_like "performing the spaceship login for JWT auth by pilot"
end
end

describe "what happens when spaceship token is already set" do
before(:each) do
fake_api_key_json_path = "./spaceship/spec/connect_api/fixtures/asc_key.json"
allow(Spaceship::ConnectAPI).to receive(:token).and_return(Spaceship::ConnectAPI::Token.from(filepath: fake_api_key_json_path))
end

context "when input options has NO api_key or api_key_path input" do
before(:each) do
upload_options[:api_key] = nil
upload_options[:api_key_path] = nil
end

it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end

context "when input options has api_key input" do
before(:each) do
upload_options[:api_key] = "fake api key"
end

it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end

context "when input options has api_key_path input" do
before(:each) do
upload_options[:api_key_path] = "./spaceship/spec/connect_api/fixtures/asc_key.json"
end

it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end
end
end
end

Expand Down