-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marlon Pina Tojal <[email protected]>
- Loading branch information
Marlon Pina Tojal
committed
Dec 19, 2023
1 parent
b01ea7a
commit f929110
Showing
5 changed files
with
130 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,12 +253,27 @@ | |
end | ||
end | ||
|
||
|
||
RSpec.describe CycloneDX::CocoaPods::BOMBuilder do | ||
context 'when generating a BOM' do | ||
let(:pods) { { | ||
'Alamofire' => '5.4.2', 'FirebaseAnalytics' => '7.10.0', 'RxSwift' => '5.1.2', 'Realm' => '5.5.1' | ||
}.map { |name, version| CycloneDX::CocoaPods::Pod.new(name: name, version: version) } } | ||
let(:pods) do | ||
{ | ||
'Alamofire' => '5.6.2', | ||
'FirebaseAnalytics' => '7.10.0', | ||
'RxSwift' => '5.1.2', | ||
'Realm' => '5.5.1', | ||
'MSAL' => '1.2.1', | ||
'MSAL/app-lib' => '1.2.1' | ||
}.map { |name, version| CycloneDX::CocoaPods::Pod.new(name: name, version: version) } | ||
end | ||
let(:dependencies) do | ||
{ | ||
'pkg:cocoapods/[email protected]' => [], | ||
'pkg:cocoapods/[email protected]' => ['pkg:cocoapods/[email protected]#app-lib'], | ||
'pkg:cocoapods/[email protected]#app-lib' => [], | ||
'pkg:cocoapods/[email protected]#app-lib' => [], | ||
'pkg:cocoapods/[email protected]#app-lib' => [] | ||
} | ||
end | ||
|
||
shared_examples "bom_generator" do | ||
context 'with an incorrect version' do | ||
|
@@ -328,7 +343,7 @@ | |
it 'should generate component metadata when a component is available' do | ||
if bom_builder.component | ||
component_metadata = Nokogiri::XML(Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| | ||
xml.metadata('xmlns': described_class::NAMESPACE) do | ||
xml.metadata(xmlns: described_class::NAMESPACE) do | ||
component.add_to_bom(xml) | ||
end | ||
end.to_xml).at('metadata/component') | ||
|
@@ -348,13 +363,35 @@ | |
components_generated_from_bom_builder = xml.at('bom/components') | ||
|
||
components = Nokogiri::XML(Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| | ||
xml.components('xmlns': described_class::NAMESPACE) do | ||
xml.components(xmlns: described_class::NAMESPACE) do | ||
bom_builder.pods.each { |pod| pod.add_to_bom(xml) } | ||
end | ||
end.to_xml).at('components') | ||
|
||
expect(components_generated_from_bom_builder).to be_equivalent_to(components) | ||
end | ||
|
||
it 'should generate a child dependencies node' do | ||
expect(xml.at('bom/dependencies')).not_to be_nil | ||
end | ||
|
||
it 'shoudl properly set dependencies node' do | ||
dependencies_generated_from_bom_builder = xml.at('bom/dependencies') | ||
|
||
dependencies = Nokogiri::XML(Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| | ||
xml.dependencies(xmlns: described_class::NAMESPACE) do | ||
bom_builder.dependencies.to_a.map do |key, array| | ||
xml.dependency(ref: key) do | ||
array.each do |value| | ||
xml.dependency(ref: value) | ||
end | ||
end | ||
end | ||
end | ||
end.to_xml).at('dependencies') | ||
|
||
expect(dependencies_generated_from_bom_builder).to be_equivalent_to(dependencies) | ||
end | ||
end | ||
end | ||
|
||
|
@@ -366,7 +403,7 @@ | |
|
||
context 'with a component' do | ||
let(:component) { CycloneDX::CocoaPods::Component.new(name: 'Application', version: '1.3.5', type: 'application') } | ||
let(:bom_builder) { described_class.new(component: component, pods: pods) } | ||
let(:bom_builder) { described_class.new(component: component, pods: pods, dependencies: dependencies) } | ||
|
||
it_behaves_like "bom_generator" | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
|
||
require 'cyclonedx/cocoapods/podfile_analyzer' | ||
require 'rspec' | ||
|
||
RSpec.describe CycloneDX::CocoaPods::PodfileAnalyzer do | ||
let(:fixtures) { Pathname.new(File.expand_path('../../../fixtures/', __FILE__)) } | ||
let(:empty_podfile) { 'EmptyPodfile/Podfile' } | ||
|
@@ -46,10 +45,12 @@ | |
lock_file = ::Pod::Lockfile.from_file(fixtures + (empty_podfile + '.lock')) | ||
expect(lock_file).not_to be_nil | ||
|
||
included_pods = analyzer.parse_pods(pod_file, lock_file) | ||
included_pods, dependencies = analyzer.parse_pods(pod_file, lock_file) | ||
|
||
pod_names = included_pods.map(&:name) | ||
expect(pod_names).to eq([]) | ||
expect(dependencies).to eq({}) | ||
expect(pod_names.length).to eq(dependencies.length) | ||
end | ||
|
||
it 'should find all simple pods' do | ||
|
@@ -60,10 +61,16 @@ | |
lock_file = ::Pod::Lockfile.from_file(fixtures + (simple_pod + '.lock')) | ||
expect(lock_file).not_to be_nil | ||
|
||
included_pods = analyzer.parse_pods(pod_file, lock_file) | ||
included_pods, dependencies = analyzer.parse_pods(pod_file, lock_file) | ||
|
||
pod_names = included_pods.map(&:name) | ||
expect(pod_names).to eq(['Alamofire', 'MSAL', 'MSAL/app-lib']) | ||
expect(dependencies).to eq({ | ||
'pkg:cocoapods/[email protected]' => [], | ||
'pkg:cocoapods/[email protected]' => ['pkg:cocoapods/[email protected]#app-lib'], | ||
'pkg:cocoapods/[email protected]#app-lib' => [] | ||
}) | ||
expect(pod_names.length).to eq(dependencies.length) | ||
end | ||
|
||
it 'should find all pods actually used' do | ||
|
@@ -74,10 +81,12 @@ | |
lock_file = ::Pod::Lockfile.from_file(fixtures + (restricted_pod + '.lock')) | ||
expect(lock_file).not_to be_nil | ||
|
||
included_pods = analyzer.parse_pods(pod_file, lock_file) | ||
included_pods, dependencies = analyzer.parse_pods(pod_file, lock_file) | ||
|
||
pod_names = included_pods.map(&:name) | ||
expect(pod_names).to eq(['EFQRCode']) | ||
expect(dependencies).to eq({ 'pkg:cocoapods/[email protected]' => [] }) | ||
expect(pod_names.length).to eq(dependencies.length) | ||
end | ||
|
||
it 'should find all pods' do | ||
|
@@ -88,10 +97,16 @@ | |
lock_file = ::Pod::Lockfile.from_file(fixtures + (tests_pod + '.lock')) | ||
expect(lock_file).not_to be_nil | ||
|
||
included_pods = analyzer.parse_pods(pod_file, lock_file) | ||
included_pods, dependencies = analyzer.parse_pods(pod_file, lock_file) | ||
|
||
pod_names = included_pods.map(&:name) | ||
expect(pod_names).to eq(['Alamofire', 'MSAL', 'MSAL/app-lib']) | ||
expect(dependencies).to eq({ | ||
'pkg:cocoapods/[email protected]' => [], | ||
'pkg:cocoapods/[email protected]' => ['pkg:cocoapods/[email protected]#app-lib'], | ||
'pkg:cocoapods/[email protected]#app-lib' => [] | ||
}) | ||
expect(pod_names.length).to eq(dependencies.length) | ||
end | ||
end | ||
|
||
|
@@ -104,10 +119,16 @@ | |
lock_file = ::Pod::Lockfile.from_file(fixtures + (simple_pod + '.lock')) | ||
expect(lock_file).not_to be_nil | ||
|
||
included_pods = analyzer.parse_pods(pod_file, lock_file) | ||
included_pods, dependencies = analyzer.parse_pods(pod_file, lock_file) | ||
|
||
pod_names = included_pods.map(&:name) | ||
expect(pod_names).to eq(['Alamofire', 'MSAL', 'MSAL/app-lib']) | ||
expect(dependencies).to eq({ | ||
'pkg:cocoapods/[email protected]' => [], | ||
'pkg:cocoapods/[email protected]' => ['pkg:cocoapods/[email protected]#app-lib'], | ||
'pkg:cocoapods/[email protected]#app-lib' => [] | ||
}) | ||
expect(pod_names.length).to eq(dependencies.length) | ||
end | ||
|
||
it 'should not include testing pods' do | ||
|
@@ -118,10 +139,12 @@ | |
lock_file = ::Pod::Lockfile.from_file(fixtures + (tests_pod + '.lock')) | ||
expect(lock_file).not_to be_nil | ||
|
||
included_pods = analyzer.parse_pods(pod_file, lock_file) | ||
included_pods, dependencies = analyzer.parse_pods(pod_file, lock_file) | ||
|
||
pod_names = included_pods.map(&:name) | ||
expect(pod_names).to eq(['Alamofire']) | ||
expect(dependencies).to eq({ 'pkg:cocoapods/[email protected]' => [] }) | ||
expect(pod_names.length).to eq(dependencies.length) | ||
end | ||
end | ||
end | ||
|