Skip to content

Commit

Permalink
[match] Fixes missing job-token error in GitLab storage mode (#21520)
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyfrey committed Sep 18, 2023
1 parent f06aa50 commit 27dc84d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
8 changes: 8 additions & 0 deletions match/lib/match/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ def self.available_options
default_value: 'https://gitlab.com',
description: "GitLab Host (i.e. 'https://gitlab.com')",
optional: true),
FastlaneCore::ConfigItem.new(key: :job_token,
env_name: "CI_JOB_TOKEN",
description: "GitLab CI_JOB_TOKEN",
optional: true),
FastlaneCore::ConfigItem.new(key: :private_token,
env_name: "PRIVATE_TOKEN",
description: "GitLab Access Token",
optional: true),

# Keychain
FastlaneCore::ConfigItem.new(key: :keychain_name,
Expand Down
61 changes: 61 additions & 0 deletions match/spec/storage/gitlab_secure_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,65 @@
end
end
end

describe 'Runner Configuration' do
let(:available_options) { Match::Options.available_options }
let(:base_options) {
{
storage_mode: 'gitlab_secure_files',
gitlab_project: 'test/project',
readonly: true,
skip_provisioning_profiles: true,
app_identifier: 'fake-app-identifier'
}
}
let(:configuration) {
FastlaneCore::Configuration.create(available_options, base_options)
}
let(:runner) {
Match::Runner.new.run(configuration)
}

before do
allow_any_instance_of(Match::Runner).to receive(:fetch_certificate)
expect(Match::Storage::GitLab::Client).to receive_message_chain(:new, :prompt_for_access_token)
expect(Match::Storage::GitLab::Client).to receive_message_chain(:new, :files).and_return([])
end

it 'allows the optional job_token param' do
base_options[:job_token] = 'foo'

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to eq('foo')
expect(configuration.fetch(:private_token)).to be nil
end

it 'allows the optional private_token param' do
base_options[:private_token] = 'bar'

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to be nil
expect(configuration.fetch(:private_token)).to eq('bar')
end

it 'uses the PRIVATE_TOKEN ENV variable when supplied' do
stub_const('ENV', ENV.to_hash.merge('PRIVATE_TOKEN' => 'env-private'))

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to be nil
expect(configuration.fetch(:private_token)).to eq('env-private')
end

it 'uses the CI_JOB_TOKEN ENV variable when supplied' do
stub_const('ENV', ENV.to_hash.merge('CI_JOB_TOKEN' => 'env-job'))

expect(runner).to be true
expect(configuration.fetch(:storage_mode)).to eq('gitlab_secure_files')
expect(configuration.fetch(:job_token)).to eq('env-job')
expect(configuration.fetch(:private_token)).to be nil
end
end
end

0 comments on commit 27dc84d

Please sign in to comment.