Skip to content

Commit

Permalink
Fixes #71. Properly concatenate the Podfile and Podfile.lock paths an…
Browse files Browse the repository at this point in the history
…d add unit tests.

Signed-off-by: Kyle Hammond <[email protected]>
  • Loading branch information
macblazer committed Oct 14, 2024
1 parent 4d463c3 commit cf09a3b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cyclonedx/cocoapods/podfile_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def load_one_plugin(plugin_name)
def validate_options(project_dir, options)
raise PodfileParsingError, "#{options[:path]} is not a valid directory." unless File.directory?(project_dir)

options[:podfile_path] = "#{project_dir}Podfile"
options[:podfile_path] = project_dir + 'Podfile'
unless File.exist?(options[:podfile_path])
raise PodfileParsingError, "Missing Podfile in #{project_dir}. Please use the --path option if " \
'not running from the CocoaPods project directory.'
end

options[:podfile_lock_path] = "#{project_dir}Podfile.lock"
options[:podfile_lock_path] = project_dir + 'Podfile.lock'
return if File.exist?(options[:podfile_lock_path])

raise PodfileParsingError, "Missing Podfile.lock, please run 'pod install' before generating BOM"
Expand Down Expand Up @@ -142,6 +142,8 @@ def dependencies_for_pod(podname_array, podfile, lockfile)
end

def initialize_cocoapods_config(project_dir)
# First, reset the ::Pod::Config instance in case we need to use this analyzer on multiple pods
::Pod::Config.instance = nil
::Pod::Config.instance.installation_root = project_dir
end

Expand Down
49 changes: 49 additions & 0 deletions spec/cyclonedx/cocoapods/podfile_analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,55 @@
@logger = Logger.new(@log)
end

context 'Calling ensure_podfile_and_lock_are_present' do
it 'with bad path should raise an error' do
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

options = {
path: 'bad_path_that_does_not_exist'
}
expect do
analyzer.ensure_podfile_and_lock_are_present(options)
end.to raise_error(CycloneDX::CocoaPods::PodfileParsingError,
'bad_path_that_does_not_exist is not a valid directory.')
end

it 'with SimplePod fixture should succeed' do
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

options = {
path: fixtures + 'SimplePod/'
}
podfile, lockfile = analyzer.ensure_podfile_and_lock_are_present(options)
expect(podfile).not_to be_nil
expect(lockfile).not_to be_nil
end

it 'with EmptyPodfile fixture should raise a "Missing Manifest.lock" error' do
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

options = {
path: fixtures + 'EmptyPodfile/'
}
expect do
analyzer.ensure_podfile_and_lock_are_present(options)
end.to raise_error(CycloneDX::CocoaPods::PodfileParsingError,
"Missing Manifest.lock, please run 'pod install' before generating BOM")
end

it 'with PluginPod fixture should log a warning when trying to load the plugin' do
analyzer = CycloneDX::CocoaPods::PodfileAnalyzer.new(logger: @logger)

options = {
path: fixtures + 'PluginPod/'
}
expect(@logger).to receive(:warn).with(/Failed to load plugin fake_plugin_that_does_not_exist./)
podfile, lockfile = analyzer.ensure_podfile_and_lock_are_present(options)
expect(podfile).not_to be_nil
expect(lockfile).not_to be_nil
end
end

context 'parsing pods' do
context 'when created with standard parameters' do
it 'should handle no pods correctly' do
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/PluginPod/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
platform :osx, '11.0'

plugin 'fake_plugin_that_does_not_exist'

target 'SampleProject' do
end
3 changes: 3 additions & 0 deletions spec/fixtures/PluginPod/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PODFILE CHECKSUM: ac84235e3de4f55461564bd177c404d01b1c09ee

COCOAPODS: 1.15.2
3 changes: 3 additions & 0 deletions spec/fixtures/PluginPod/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions spec/fixtures/SimplePod/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf09a3b

Please sign in to comment.