Skip to content

Commit

Permalink
If the "force" option is specified, sigh should delete and recreate a…
Browse files Browse the repository at this point in the history
…ny matching profiles (even invalid ones) (#6518)
  • Loading branch information
icecrystal23 authored and Andrea Falcone committed Jan 13, 2017
1 parent cbd03b7 commit 169e30a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
14 changes: 5 additions & 9 deletions sigh/lib/sigh/runner.rb
Expand Up @@ -24,14 +24,10 @@ def run
profile = profiles.first

if Sigh.config[:force]
if profile_type == Spaceship.provisioning_profile::AppStore or profile_type == Spaceship.provisioning_profile::InHouse
UI.important "Updating the provisioning profile"
else
UI.important "Updating the profile to include all devices"
profile.devices = Spaceship.device.all_for_profile_type(profile.type)
end

profile = profile.update! # assign it, as it's a new profile
# Recreating the profile ensures it has all of the requested properties (cert, name, etc.)
UI.important "Recreating the profile"
profile.delete!
profile = create_profile!
end
else
UI.important "No existing profiles found, that match the certificates you have installed locally! Creating a new provisioning profile for you"
Expand Down Expand Up @@ -67,7 +63,7 @@ def fetch_profiles
UI.message "Fetching profiles..."
results = profile_type.find_by_bundle_id(Sigh.config[:app_identifier])
results = results.find_all do |current_profile|
if current_profile.valid?
if current_profile.valid? || Sigh.config[:force]
true
else
UI.message("Provisioning Profile '#{current_profile.name}' is not valid, skipping this one...")
Expand Down
20 changes: 20 additions & 0 deletions sigh/spec/manager_spec.rb
Expand Up @@ -14,5 +14,25 @@
expect(val).to eq(File.expand_path("./AppStore_com.krausefx.app.mobileprovision"))
File.delete(val)
end

it "Invalid profile not force run" do
sigh_stub_spaceship(valid_profile = false, expect_create = true)
options = { app_identifier: "com.krausefx.app", skip_install: true, skip_certificate_verification: true }
Sigh.config = FastlaneCore::Configuration.create(Sigh::Options.available_options, options)

val = Sigh::Manager.start
expect(val).to eq(File.expand_path("./AppStore_com.krausefx.app.mobileprovision"))
File.delete(val)
end

it "Invalid profile force run" do
sigh_stub_spaceship(valid_profile = false, expect_create = true, expect_delete = true)
options = { app_identifier: "com.krausefx.app", skip_install: true, skip_certificate_verification: true, force: true }
Sigh.config = FastlaneCore::Configuration.create(Sigh::Options.available_options, options)

val = Sigh::Manager.start
expect(val).to eq(File.expand_path("./AppStore_com.krausefx.app.mobileprovision"))
File.delete(val)
end
end
end
23 changes: 17 additions & 6 deletions sigh/spec/stubbing.rb
@@ -1,21 +1,32 @@
def sigh_stub_spaceship
def sigh_stub_spaceship(valid_profile = true, expect_create = false, expect_delete = false)
profile = "profile"
certificate = "certificate"

expect(Spaceship).to receive(:login).and_return(nil)
allow(Spaceship).to receive(:client).and_return("client")
expect(Spaceship).to receive(:select_team).and_return(nil)
expect(Spaceship.client).to receive(:in_house?).and_return(false)
allow(Spaceship.app).to receive(:find).and_return(true)
allow(Spaceship.provisioning_profile).to receive(:all).and_return([])

allow(profile).to receive(:valid?).and_return(true)
allow(profile).to receive(:valid?).and_return(valid_profile)
allow(profile.class).to receive(:pretty_type).and_return("pretty")
allow(profile).to receive(:download).and_return("FileContent")
allow(profile).to receive(:is_adhoc?).and_return(false)
allow(profile).to receive(:name).and_return("profile name")
if expect_delete
expect(profile).to receive(:delete!)
else
expect(profile).to_not receive(:delete!)
end

types = [Spaceship.provisioning_profile, Spaceship.provisioning_profile.app_store]
types.each do |current|
allow(current).to receive(:find_by_bundle_id).and_return([profile])
allow(current).to receive(:all).and_return([profile])
profile_type = Spaceship.provisioning_profile.app_store
allow(profile_type).to receive(:find_by_bundle_id).and_return([profile])
allow(profile_type).to receive(:all).and_return([profile])
if expect_create
expect(profile_type).to receive(:create!).and_return(profile)
else
expect(profile_type).to_not receive(:create!)
end

certs = [Spaceship.certificate.production]
Expand Down

0 comments on commit 169e30a

Please sign in to comment.