license_finder 1.2 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.rdoc +27 -0
- data/CONTRIBUTING.md +38 -0
- data/README.md +139 -159
- data/Rakefile +17 -13
- data/features/features/cli_spec.rb +43 -0
- data/features/features/configure/add_dependencies_spec.rb +37 -0
- data/features/features/configure/approve_dependencies_spec.rb +30 -0
- data/features/features/configure/assign_licenses_spec.rb +20 -0
- data/features/features/configure/ignore_dependencies_spec.rb +35 -0
- data/features/features/configure/ignore_groups_spec.rb +31 -0
- data/features/features/configure/name_project_spec.rb +32 -0
- data/features/features/configure/whitelist_licenses_spec.rb +40 -0
- data/features/features/package_managers/bower_spec.rb +14 -0
- data/features/features/package_managers/cocoapods_spec.rb +14 -0
- data/features/features/package_managers/gradle_spec.rb +14 -0
- data/features/features/package_managers/maven_spec.rb +14 -0
- data/features/features/package_managers/npm_spec.rb +14 -0
- data/features/features/package_managers/pip_spec.rb +14 -0
- data/features/features/report/csv_spec.rb +17 -0
- data/features/features/report/html_spec.rb +50 -0
- data/{spec → features}/fixtures/Podfile +0 -0
- data/{spec → features}/fixtures/build.gradle +0 -0
- data/{spec → features}/fixtures/pom.xml +0 -0
- data/features/support/testing_dsl.rb +295 -0
- data/lib/license_finder.rb +16 -50
- data/lib/license_finder/cli.rb +13 -253
- data/lib/license_finder/cli/approvals.rb +26 -0
- data/lib/license_finder/cli/base.rb +20 -0
- data/lib/license_finder/cli/dependencies.rb +39 -0
- data/lib/license_finder/cli/ignored_dependencies.rb +30 -0
- data/lib/license_finder/cli/ignored_groups.rb +30 -0
- data/lib/license_finder/cli/licenses.rb +24 -0
- data/lib/license_finder/cli/main.rb +82 -0
- data/lib/license_finder/cli/makes_decisions.rb +48 -0
- data/lib/license_finder/cli/patched_thor.rb +34 -0
- data/lib/license_finder/cli/project_name.rb +31 -0
- data/lib/license_finder/cli/whitelist.rb +32 -0
- data/lib/license_finder/configuration.rb +14 -145
- data/lib/license_finder/decision_applier.rb +46 -0
- data/lib/license_finder/decisions.rb +174 -0
- data/lib/license_finder/license.rb +13 -32
- data/lib/license_finder/license/definitions.rb +15 -13
- data/lib/license_finder/license/template.rb +1 -1
- data/lib/{data/licenses → license_finder/license/templates}/Apache2.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/BSD.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/GPLv2.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/ISC.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/LGPL.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/MIT.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/NewBSD.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/Python.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/Ruby.txt +0 -0
- data/lib/{data/licenses → license_finder/license/templates}/SimplifiedBSD.txt +0 -0
- data/lib/license_finder/package.rb +77 -7
- data/lib/license_finder/package_manager.rb +43 -0
- data/lib/license_finder/package_managers/bower.rb +1 -1
- data/lib/license_finder/package_managers/bower_package.rb +23 -44
- data/lib/license_finder/package_managers/bundler.rb +4 -7
- data/lib/license_finder/package_managers/bundler_package.rb +14 -31
- data/lib/license_finder/package_managers/cocoa_pods.rb +1 -1
- data/lib/license_finder/package_managers/cocoa_pods_package.rb +2 -10
- data/lib/license_finder/package_managers/gradle.rb +6 -2
- data/lib/license_finder/package_managers/gradle_package.rb +6 -30
- data/lib/license_finder/package_managers/manual_package.rb +25 -0
- data/lib/license_finder/package_managers/maven_package.rb +8 -37
- data/lib/license_finder/package_managers/npm.rb +16 -4
- data/lib/license_finder/package_managers/npm_package.rb +12 -43
- data/lib/license_finder/package_managers/pip_package.rb +17 -37
- data/lib/license_finder/platform.rb +0 -16
- data/lib/license_finder/possible_license_file.rb +9 -14
- data/lib/license_finder/possible_license_files.rb +1 -5
- data/lib/license_finder/report.rb +26 -0
- data/lib/license_finder/reports/csv_report.rb +58 -0
- data/lib/license_finder/reports/erb_report.rb +61 -0
- data/lib/license_finder/reports/html_report.rb +10 -1
- data/lib/license_finder/reports/markdown_report.rb +7 -1
- data/lib/license_finder/reports/templates/bootstrap.css +9 -0
- data/lib/license_finder/reports/templates/html_report.erb +105 -0
- data/lib/{templates → license_finder/reports/templates}/markdown_report.erb +7 -7
- data/lib/license_finder/reports/text_report.rb +5 -3
- data/lib/license_finder/version.rb +3 -0
- data/license_finder.gemspec +2 -6
- data/release/instructions.md +8 -0
- data/spec/feature_helper.rb +11 -0
- data/spec/fixtures/config/license_finder.yml +3 -0
- data/spec/fixtures/{nested_readme/vendor/README → license_directory/LICENSE/Apache.txt} +0 -0
- data/spec/lib/license_finder/cli/approvals_spec.rb +63 -0
- data/spec/lib/license_finder/cli/dependencies_spec.rb +59 -0
- data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +47 -0
- data/spec/lib/license_finder/cli/ignored_groups_spec.rb +40 -0
- data/spec/lib/license_finder/cli/licenses_spec.rb +60 -0
- data/spec/lib/license_finder/cli/main_spec.rb +110 -0
- data/spec/lib/license_finder/cli/project_name_spec.rb +40 -0
- data/spec/lib/license_finder/cli/whitelist_spec.rb +58 -0
- data/spec/lib/license_finder/configuration_spec.rb +46 -191
- data/spec/lib/license_finder/decision_applier_spec.rb +65 -0
- data/spec/lib/license_finder/decisions_spec.rb +347 -0
- data/spec/lib/license_finder/license/definitions_spec.rb +1 -7
- data/spec/lib/license_finder/license_spec.rb +2 -30
- data/spec/lib/license_finder/package_manager_spec.rb +22 -0
- data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -66
- data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +7 -71
- data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -11
- data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +28 -32
- data/spec/lib/license_finder/package_managers/gradle_spec.rb +18 -23
- data/spec/lib/license_finder/package_managers/maven_package_spec.rb +20 -43
- data/spec/lib/license_finder/package_managers/npm_package_spec.rb +22 -73
- data/spec/lib/license_finder/package_managers/npm_spec.rb +18 -21
- data/spec/lib/license_finder/package_managers/pip_package_spec.rb +24 -63
- data/spec/lib/license_finder/package_spec.rb +121 -0
- data/spec/lib/license_finder/possible_license_file_spec.rb +2 -3
- data/spec/lib/license_finder/possible_license_files_spec.rb +18 -22
- data/spec/lib/license_finder/reports/csv_report_spec.rb +26 -0
- data/spec/lib/license_finder/reports/html_report_spec.rb +39 -22
- data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -16
- data/spec/lib/license_finder/reports/text_report_spec.rb +21 -12
- data/spec/spec_helper.rb +1 -4
- data/spec/support/shared_examples_for_package.rb +0 -11
- data/spec/support/shared_examples_for_package_manager.rb +1 -0
- data/spec/support/stdout_helpers.rb +4 -11
- metadata +73 -158
- data/db/migrate/201303290935_create_dependencies.rb +0 -14
- data/db/migrate/201303291155_create_licenses.rb +0 -13
- data/db/migrate/201303291402_create_approvals.rb +0 -13
- data/db/migrate/201303291456_create_ancestries.rb +0 -9
- data/db/migrate/201303291519_create_bundler_groups.rb +0 -13
- data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +0 -11
- data/db/migrate/201303291753_allow_null_license_names.rb +0 -7
- data/db/migrate/201304011027_allow_null_dependency_version.rb +0 -7
- data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +0 -5
- data/db/migrate/201304181524_add_manual_to_dependencies.rb +0 -7
- data/db/migrate/201307250917_add_license_manual_to_dependencies.rb +0 -7
- data/db/migrate/201307251004_data_fix_manual_licenses.rb +0 -15
- data/db/migrate/201307251107_reassociate_license.rb +0 -23
- data/db/migrate/201307251340_remove_manual_from_license_aliases.rb +0 -7
- data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +0 -7
- data/db/migrate/201311192003_reassociate_manual_approval.rb +0 -13
- data/db/migrate/201311192010_drop_approvals.rb +0 -5
- data/db/migrate/201401302113_re_reassociate_license.rb +0 -23
- data/db/migrate/201403181732_rename_manual_fields.rb +0 -10
- data/db/migrate/201403190028_add_manual_approvals.rb +0 -22
- data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +0 -15
- data/db/migrate/201403191645_remove_license_aliases.rb +0 -23
- data/db/migrate/201410031451_rename_dependency_license_name.rb +0 -6
- data/features/cli.feature +0 -37
- data/features/cocoapods_dependencies.feature +0 -10
- data/features/configure_bundler_groups.feature +0 -23
- data/features/configure_ignore_dependencies.feature +0 -16
- data/features/configure_project_name.feature +0 -10
- data/features/configure_whitelist.feature +0 -27
- data/features/gradle_dependencies.feature +0 -9
- data/features/manually_added.feature +0 -19
- data/features/manually_approved.feature +0 -10
- data/features/manually_assigned_license.feature +0 -16
- data/features/maven_dependencies.feature +0 -9
- data/features/multiple_licenses.feature +0 -9
- data/features/node_dependencies.feature +0 -9
- data/features/python_dependencies.feature +0 -9
- data/features/report_csv.feature +0 -15
- data/features/report_html.feature +0 -24
- data/features/step_definitions/cli_steps.rb +0 -51
- data/features/step_definitions/cocoapod_steps.rb +0 -8
- data/features/step_definitions/configure_bundler_groups_steps.rb +0 -30
- data/features/step_definitions/configure_ignore_dependencies.rb +0 -35
- data/features/step_definitions/configure_project_name_steps.rb +0 -3
- data/features/step_definitions/configure_whitelist_steps.rb +0 -45
- data/features/step_definitions/gradle_steps.rb +0 -8
- data/features/step_definitions/manually_added_steps.rb +0 -28
- data/features/step_definitions/manually_approved_steps.rb +0 -24
- data/features/step_definitions/manually_assigned_license_steps.rb +0 -34
- data/features/step_definitions/maven_steps.rb +0 -8
- data/features/step_definitions/multiple_licenses_steps.rb +0 -14
- data/features/step_definitions/node_steps.rb +0 -8
- data/features/step_definitions/python_steps.rb +0 -8
- data/features/step_definitions/report_csv_steps.rb +0 -20
- data/features/step_definitions/report_html_steps.rb +0 -60
- data/features/step_definitions/shared_steps.rb +0 -307
- data/lib/data/license_finder.example.yml +0 -12
- data/lib/license_finder/dependency_manager.rb +0 -92
- data/lib/license_finder/package_saver.rb +0 -44
- data/lib/license_finder/reports/dependency_report.rb +0 -34
- data/lib/license_finder/reports/detailed_text_report.rb +0 -19
- data/lib/license_finder/reports/formatted_report.rb +0 -40
- data/lib/license_finder/reports/reporter.rb +0 -27
- data/lib/license_finder/tables.rb +0 -9
- data/lib/license_finder/tables/bundler_group.rb +0 -7
- data/lib/license_finder/tables/dependency.rb +0 -113
- data/lib/license_finder/tables/manual_approval.rb +0 -13
- data/lib/license_finder/yml_to_sql.rb +0 -117
- data/lib/templates/html_report.erb +0 -117
- data/lib/templates/text_report.erb +0 -3
- data/release/gem_version.rb +0 -3
- data/release/manual_instructions.md +0 -29
- data/release/publish.sh +0 -32
- data/spec/fixtures/APACHE-2-LICENSE +0 -202
- data/spec/fixtures/GPLv2 +0 -339
- data/spec/fixtures/ISC-LICENSE +0 -10
- data/spec/fixtures/MIT-LICENSE +0 -22
- data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +0 -22
- data/spec/fixtures/README-with-MIT-LICENSE +0 -222
- data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +0 -25
- data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +0 -339
- data/spec/fixtures/license_directory/LICENSE/LICENSE +0 -191
- data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -21
- data/spec/fixtures/license_directory/LICENSE/RUBY.txt +0 -60
- data/spec/fixtures/mit_licensed_gem/LICENSE +0 -22
- data/spec/fixtures/other_licensed_gem/LICENSE +0 -3
- data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
- data/spec/fixtures/readme/README +0 -0
- data/spec/fixtures/readme/Readme.markdown +0 -0
- data/spec/lib/license_finder/cli_spec.rb +0 -298
- data/spec/lib/license_finder/dependency_manager_spec.rb +0 -198
- data/spec/lib/license_finder/package_saver_spec.rb +0 -82
- data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +0 -33
- data/spec/lib/license_finder/reports/reporter_spec.rb +0 -33
- data/spec/lib/license_finder/tables/dependency_spec.rb +0 -196
- data/spec/lib/license_finder/yml_to_sql_spec.rb +0 -123
- data/spec/lib/license_finder_spec.rb +0 -16
@@ -1,198 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module LicenseFinder
|
4
|
-
describe DependencyManager do
|
5
|
-
let(:config) { Configuration.new('whitelist' => ['MIT', 'other']) }
|
6
|
-
let(:dependency_manager) { DependencyManager.new }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(LicenseFinder).to receive(:config).and_return config
|
10
|
-
allow(Reporter).to receive(:write_reports)
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#sync" do
|
14
|
-
let(:gem1) { double(:package) }
|
15
|
-
let(:gem2) { double(:package) }
|
16
|
-
let!(:bundler) { Bundler.new }
|
17
|
-
|
18
|
-
before { allow(Bundler).to receive(:new) { bundler } }
|
19
|
-
|
20
|
-
it "destroys every dependency except for the ones Bundler reports as 'current' or are marked as 'added_manually'" do
|
21
|
-
cur1 = Dependency.create(name: "current dependency 1")
|
22
|
-
cur2 = Dependency.create(name: "current dependency 2")
|
23
|
-
man1 = Dependency.create(name: "manual dependency", added_manually: true)
|
24
|
-
Dependency.create(name: "old dependency 1")
|
25
|
-
Dependency.create(name: "old dependency 2")
|
26
|
-
|
27
|
-
current_packages = [gem1, gem2]
|
28
|
-
allow(bundler).to receive(:current_packages) { current_packages }
|
29
|
-
expect(PackageSaver).to receive(:save_all).with(current_packages).and_return([cur1, cur2])
|
30
|
-
|
31
|
-
dependency_manager.sync_with_package_managers
|
32
|
-
expect(Dependency.all.map(&:name)).to match_array([cur1, cur2, man1].map(&:name))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe ".manually_add" do
|
37
|
-
it "should add a Dependency" do
|
38
|
-
expect do
|
39
|
-
dependency_manager.manually_add("MIT", "js_dep", "0.0.0")
|
40
|
-
end.to change(Dependency, :count).by(1)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should mark the dependency as manual" do
|
44
|
-
expect(dependency_manager.manually_add("MIT", "js_dep", "0.0.0"))
|
45
|
-
.to be_added_manually
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should set the appropriate values" do
|
49
|
-
dep = dependency_manager.manually_add("GPL", "js_dep", "0.0.0")
|
50
|
-
expect(dep.name).to eq("js_dep")
|
51
|
-
expect(dep.version).to eq("0.0.0")
|
52
|
-
expect(dep.licenses.first.name).to eq("GPL")
|
53
|
-
expect(dep).not_to be_approved
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should complain if the dependency already exists" do
|
57
|
-
Dependency.create(name: "current dependency 1")
|
58
|
-
expect { dependency_manager.manually_add("GPL", "current dependency 1", "0.0.0") }
|
59
|
-
.to raise_error(Error)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ".manually_remove" do
|
64
|
-
it "should remove a manually managed Dependency" do
|
65
|
-
dependency_manager.manually_add("GPL", "a manually managed dep", nil)
|
66
|
-
expect do
|
67
|
-
dependency_manager.manually_remove("a manually managed dep")
|
68
|
-
end.to change(Dependency, :count).by(-1)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should not remove a bundler Dependency" do
|
72
|
-
Dependency.create(name: "a bundler dep")
|
73
|
-
expect do
|
74
|
-
expect do
|
75
|
-
dependency_manager.manually_remove("a bundler dep")
|
76
|
-
end.to raise_error(Error)
|
77
|
-
end.to_not change(Dependency, :count)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe ".approve!" do
|
82
|
-
it "approves the dependency" do
|
83
|
-
dep = Dependency.named("current dependency")
|
84
|
-
dep.licenses = [License.find_by_name('not approved')].to_set
|
85
|
-
dep.save
|
86
|
-
expect(dep.reload).not_to be_approved
|
87
|
-
dependency_manager.approve!("current dependency")
|
88
|
-
expect(dep.reload).to be_approved
|
89
|
-
end
|
90
|
-
|
91
|
-
it "optionally adds approver and approval notes" do
|
92
|
-
dep = Dependency.named("current dependency")
|
93
|
-
dependency_manager.approve!("current dependency", "Julian", "We really need this")
|
94
|
-
approval = dep.reload.manual_approval
|
95
|
-
expect(approval.approver).to eq "Julian"
|
96
|
-
expect(approval.notes).to eq "We really need this"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should raise an error if it can't find the dependency" do
|
100
|
-
expect { dependency_manager.approve!("non-existent dependency") }
|
101
|
-
.to raise_error(Error)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe ".license!" do
|
106
|
-
let(:dependency) { double(:dependency) }
|
107
|
-
|
108
|
-
it "adds a license for the dependency" do
|
109
|
-
allow(dependency_manager).to receive(:find_by_name).with("dependency").and_return(dependency)
|
110
|
-
expect(dependency).to receive(:set_license_manually!).with(License.find_by_name "MIT")
|
111
|
-
dependency_manager.license!("dependency", "MIT")
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should raise an error if it can't find the dependency" do
|
115
|
-
expect { dependency_manager.license!("non-existent dependency", "a license") }
|
116
|
-
.to raise_error(Error)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe ".modifying" do
|
121
|
-
let(:file_exists) { double(:file, :exist? => true) }
|
122
|
-
let(:file_does_not_exist) { double(:file, :exist? => false) }
|
123
|
-
|
124
|
-
context "when the database doesn't exist" do
|
125
|
-
before do
|
126
|
-
allow(config.artifacts).to receive(:database_file).and_return(file_does_not_exist)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "writes reports" do
|
130
|
-
expect(Reporter).to receive(:write_reports)
|
131
|
-
dependency_manager.modifying {}
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "when the database exists" do
|
136
|
-
before do
|
137
|
-
allow(config.artifacts).to receive(:database_file).and_return(file_exists)
|
138
|
-
end
|
139
|
-
|
140
|
-
context "when the database has changed" do
|
141
|
-
before do
|
142
|
-
i = 0
|
143
|
-
allow(Digest::SHA2).to receive_message_chain(:file, :hexdigest) { i += 1 }
|
144
|
-
end
|
145
|
-
|
146
|
-
it "writes reports" do
|
147
|
-
expect(Reporter).to receive(:write_reports)
|
148
|
-
dependency_manager.modifying {}
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when the database has not changed" do
|
153
|
-
before do
|
154
|
-
allow(Digest::SHA2).to receive_message_chain(:file, :hexdigest) { 5 }
|
155
|
-
allow(config).to receive(:last_modified) { config_last_update }
|
156
|
-
allow(config.artifacts).to receive(:last_refreshed) { artifacts_last_update }
|
157
|
-
end
|
158
|
-
|
159
|
-
context "and the reports do not exist" do
|
160
|
-
before do
|
161
|
-
allow(config.artifacts).to receive(:html_file).and_return(file_does_not_exist)
|
162
|
-
end
|
163
|
-
|
164
|
-
it "writes reports" do
|
165
|
-
expect(Reporter).to receive(:write_reports)
|
166
|
-
dependency_manager.modifying {}
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "and the reports exist" do
|
171
|
-
before do
|
172
|
-
allow(config.artifacts).to receive(:html_file).and_return(file_exists)
|
173
|
-
end
|
174
|
-
|
175
|
-
context "and configs are newer than the reports" do
|
176
|
-
let(:config_last_update) { 4 }
|
177
|
-
let(:artifacts_last_update) { 1 }
|
178
|
-
it "writes reports" do
|
179
|
-
expect(Reporter).to receive(:write_reports)
|
180
|
-
dependency_manager.modifying {}
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
context "and configs are older than the reports" do
|
185
|
-
let(:config_last_update) { 4 }
|
186
|
-
let(:artifacts_last_update) { 6 }
|
187
|
-
|
188
|
-
it "does not write reports" do
|
189
|
-
expect(Reporter).not_to receive(:write_reports)
|
190
|
-
dependency_manager.modifying {}
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module LicenseFinder
|
4
|
-
describe PackageSaver do
|
5
|
-
let(:package) do
|
6
|
-
double(
|
7
|
-
:package,
|
8
|
-
licenses: [License.find_by_name('license')].to_set,
|
9
|
-
children: ['child'],
|
10
|
-
groups: [:group],
|
11
|
-
summary: 'summary',
|
12
|
-
description: 'description',
|
13
|
-
name: 'spec_name',
|
14
|
-
version: '1.2.3',
|
15
|
-
homepage: 'http://example.com'
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
describe ".save_all" do
|
20
|
-
let(:dependency) { double(:dependency).as_null_object }
|
21
|
-
|
22
|
-
it "find and updates relevant dependencies" do
|
23
|
-
expect(Dependency).to receive(:named).with('spec_name').and_return(dependency)
|
24
|
-
expect(dependency).to receive(:save_changes)
|
25
|
-
described_class.save_all([package])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#save" do
|
30
|
-
it "persists changes" do
|
31
|
-
dep = Dependency.create(
|
32
|
-
name: 'spec_name',
|
33
|
-
version: '0.1.2',
|
34
|
-
summary: 'old summary',
|
35
|
-
description: 'old desription',
|
36
|
-
homepage: 'old homepage',
|
37
|
-
license_names: ["old license"].to_json
|
38
|
-
)
|
39
|
-
dep.add_bundler_group BundlerGroup.named("old group")
|
40
|
-
dep.add_child Dependency.named("old child")
|
41
|
-
|
42
|
-
saver = described_class.new(dep, package)
|
43
|
-
subject = saver.save
|
44
|
-
|
45
|
-
expect(subject.id).to be
|
46
|
-
expect(subject.name).to eq("spec_name")
|
47
|
-
expect(subject.version).to eq("1.2.3")
|
48
|
-
expect(subject.summary).to eq("summary")
|
49
|
-
expect(subject.description).to eq("description")
|
50
|
-
expect(subject.homepage).to eq("http://example.com")
|
51
|
-
expect(subject.bundler_groups.map(&:name)).to eq(['group'])
|
52
|
-
expect(subject.children.map(&:name)).to eq(['child'])
|
53
|
-
expect(subject.licenses.first.name).to eq('license')
|
54
|
-
end
|
55
|
-
|
56
|
-
it "keeps approval" do
|
57
|
-
dep = Dependency.create(
|
58
|
-
name: 'spec_name',
|
59
|
-
)
|
60
|
-
dep.approve!
|
61
|
-
saver = described_class.new(dep, package)
|
62
|
-
subject = saver.save
|
63
|
-
|
64
|
-
expect(subject).to be_approved
|
65
|
-
end
|
66
|
-
|
67
|
-
context "to minimize db changes" do
|
68
|
-
it "does not re-save unchanged dependencies" do
|
69
|
-
# See note in PackageSaver#save
|
70
|
-
|
71
|
-
first_run = described_class.find_or_create_by_name(package)
|
72
|
-
expect(first_run.dependency).to receive(:save).and_call_original
|
73
|
-
first_run.save
|
74
|
-
|
75
|
-
second_run = described_class.find_or_create_by_name(package)
|
76
|
-
expect(second_run.dependency).to_not receive(:save)
|
77
|
-
second_run.save
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module LicenseFinder
|
4
|
-
describe DetailedTextReport do
|
5
|
-
describe '#to_s' do
|
6
|
-
let(:dep1) do
|
7
|
-
Dependency.new(
|
8
|
-
'name' => 'gem_a',
|
9
|
-
'version' => '1.0',
|
10
|
-
'summary' => 'Summary',
|
11
|
-
'description' => 'Description',
|
12
|
-
'licenses' => [License.find_by_name('MIT')].to_set
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:dep2) do
|
17
|
-
Dependency.new(
|
18
|
-
'name' => 'gem_b',
|
19
|
-
'version' => '1.0',
|
20
|
-
'summary' => 'Summary',
|
21
|
-
'description' => 'Description',
|
22
|
-
'licenses' => [License.find_by_name('MIT')].to_set
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
subject { DetailedTextReport.new([dep2, dep1]).to_s }
|
27
|
-
|
28
|
-
it 'should generate a text report with the name, version, license, summary and description of each dependency, sorted by name' do
|
29
|
-
is_expected.to eq("gem_a,1.0,MIT,Summary,Description\ngem_b,1.0,MIT,Summary,Description\n")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module LicenseFinder
|
4
|
-
describe Reporter do
|
5
|
-
describe "#write_reports" do
|
6
|
-
subject { Reporter.write_reports }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(Dependency).to receive(:acknowledged) { [double(:dep)] }
|
10
|
-
|
11
|
-
allow(MarkdownReport).to receive(:of) { 'markdown report' }
|
12
|
-
allow(DetailedTextReport).to receive(:of) { 'detailed csv report' }
|
13
|
-
allow(TextReport).to receive(:of) { 'csv report' }
|
14
|
-
allow(HtmlReport).to receive(:of) { 'html report' }
|
15
|
-
end
|
16
|
-
|
17
|
-
it "writes an html file" do
|
18
|
-
subject
|
19
|
-
expect(LicenseFinder.config.artifacts.text_file.read).to eq("csv report\n")
|
20
|
-
expect(LicenseFinder.config.artifacts.detailed_text_file.read).to eq("detailed csv report\n")
|
21
|
-
expect(LicenseFinder.config.artifacts.markdown_file.read).to eq("markdown report\n")
|
22
|
-
expect(LicenseFinder.config.artifacts.html_file.read).to eq("html report\n")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "deletes old dependencies.txt file" do
|
26
|
-
fake_file = double(:fake_file, :exist? => true)
|
27
|
-
allow(LicenseFinder.config.artifacts).to receive(:legacy_text_file) { fake_file }
|
28
|
-
expect(fake_file).to receive(:delete)
|
29
|
-
subject
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,196 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module LicenseFinder
|
4
|
-
describe Dependency do
|
5
|
-
describe '.unapproved' do
|
6
|
-
before do
|
7
|
-
allow(License.find_by_name('MIT')).to receive_messages(:whitelisted? => true)
|
8
|
-
allow(LicenseFinder.config).to receive(:ignore_dependencies) { ['this ignored dependency', 'that ignored dependency'] }
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return all unapproved dependencies that are not ignored" do
|
12
|
-
dependency = Dependency.create(name: "unapproved dependency", version: '0.0.1')
|
13
|
-
approved = Dependency.create(name: "approved dependency", version: '0.0.1')
|
14
|
-
this_ignored = Dependency.create(name: "this ignored dependency", version: '0.0.1')
|
15
|
-
that_ignored = Dependency.create(name: "that ignored dependency", version: '0.0.1')
|
16
|
-
approved.approve!
|
17
|
-
whitelisted = Dependency.create(name: "approved dependency", version: '0.0.1')
|
18
|
-
whitelisted.licenses = [License.find_by_name('MIT')].to_set
|
19
|
-
whitelisted.save
|
20
|
-
|
21
|
-
unapproved = Dependency.unapproved
|
22
|
-
expect(unapproved.count).to eq(1)
|
23
|
-
expect(unapproved).not_to be_any(&:approved?)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe ".named" do
|
28
|
-
it "creates a new dependency" do
|
29
|
-
dep = described_class.named("never_seen")
|
30
|
-
expect(dep.name).to eq("never_seen")
|
31
|
-
expect(dep).not_to be_new
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns an existing dependency" do
|
35
|
-
described_class.named("referenced_again")
|
36
|
-
dep = described_class.named("referenced_again")
|
37
|
-
expect(dep.name).to eq("referenced_again")
|
38
|
-
expect(dep).not_to be_new
|
39
|
-
expect(Dependency.count(name: "referenced_again")).to eq(1)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe ".acknowledged" do
|
44
|
-
it "returns all dependencies that are not ignored" do
|
45
|
-
acknowledged_dependency = Dependency.create(name: "acknowledged dependency", version: '0.0.1')
|
46
|
-
ignored_dependency = Dependency.create(name: "ignored dependency", version: '0.0.1')
|
47
|
-
allow(LicenseFinder.config).to receive(:ignore_dependencies) { [ignored_dependency.name] }
|
48
|
-
|
49
|
-
expect(Dependency.acknowledged).to match_array [acknowledged_dependency]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#approve!' do
|
54
|
-
it "should update the database to show the dependency is approved" do
|
55
|
-
dependency = Dependency.named("foo")
|
56
|
-
dependency.approve!
|
57
|
-
expect(dependency.reload).to be_approved
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should record the approver and notes" do
|
61
|
-
dependency = Dependency.named("foo")
|
62
|
-
dependency.approve!("Julian", "We really need this")
|
63
|
-
approval = dependency.reload.manual_approval
|
64
|
-
expect(approval.approver).to eq "Julian"
|
65
|
-
expect(approval.notes).to eq "We really need this"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#approved?" do
|
70
|
-
let(:not_approved_manually) { Dependency.create(name: 'some gem').reload }
|
71
|
-
let(:approved_manually) { Dependency.create(name: 'some gem').approve!.reload }
|
72
|
-
|
73
|
-
it "is true if its license is whitelisted" do
|
74
|
-
fake_license = double(:license, whitelisted?: true)
|
75
|
-
allow(not_approved_manually).to receive(:licenses).and_return [fake_license].to_set
|
76
|
-
expect(not_approved_manually).to be_approved
|
77
|
-
end
|
78
|
-
|
79
|
-
it "is true if one of its licenses is whitelisted" do
|
80
|
-
fake_licenses = [double(:license, whitelisted?: false), double(:license, whitelisted?: true)].to_set
|
81
|
-
allow(not_approved_manually).to receive(:licenses).and_return fake_licenses
|
82
|
-
expect(not_approved_manually).to be_approved
|
83
|
-
end
|
84
|
-
|
85
|
-
it "is true if it has been approved" do
|
86
|
-
allow(approved_manually).to receive_message_chain(:license, whitelisted?: false)
|
87
|
-
expect(approved_manually).to be_approved
|
88
|
-
end
|
89
|
-
|
90
|
-
it "is false otherwise" do
|
91
|
-
allow(not_approved_manually).to receive_message_chain(:license, whitelisted?: false)
|
92
|
-
expect(not_approved_manually).not_to be_approved
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "#set_license_manually!" do
|
97
|
-
let(:dependency) { Dependency.create(name: 'foogem') }
|
98
|
-
|
99
|
-
it "sets manual license to true" do
|
100
|
-
expect(dependency).not_to be_license_assigned_manually
|
101
|
-
dependency.set_license_manually! License.find_by_name("Updated")
|
102
|
-
expect(dependency).to be_license_assigned_manually
|
103
|
-
end
|
104
|
-
|
105
|
-
it "modifies the license" do
|
106
|
-
dependency.set_license_manually! License.find_by_name("Updated")
|
107
|
-
expect(dependency.reload.licenses.first.name).to eq('Updated')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#bundler_group_names=" do
|
112
|
-
let(:dependency) { Dependency.named('some gem') }
|
113
|
-
|
114
|
-
it "saves the bundler groups" do
|
115
|
-
dependency.bundler_group_names = %w[1 2 3]
|
116
|
-
expect(dependency.bundler_groups.map(&:name)).to match_array(%w[1 2 3])
|
117
|
-
end
|
118
|
-
|
119
|
-
it "removed outdated groups and adds new groups" do
|
120
|
-
dependency.add_bundler_group BundlerGroup.named('old')
|
121
|
-
dependency.add_bundler_group BundlerGroup.named('maintained')
|
122
|
-
dependency.bundler_group_names = %w[new maintained]
|
123
|
-
expect(dependency.bundler_groups.map(&:name)).to match_array(%w[new maintained])
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "children_names=" do
|
128
|
-
let(:dependency) { Dependency.named('some gem') }
|
129
|
-
|
130
|
-
it "saves the children" do
|
131
|
-
dependency.children_names = %w[1 2 3]
|
132
|
-
expect(dependency.children.map(&:name)).to match_array(%w[1 2 3])
|
133
|
-
end
|
134
|
-
|
135
|
-
it "removes outdated children and adds new children" do
|
136
|
-
dependency.add_child Dependency.named('old')
|
137
|
-
dependency.add_child Dependency.named('maintained')
|
138
|
-
dependency.children_names = %w[new maintained]
|
139
|
-
expect(dependency.children.map(&:name)).to match_array(%w[new maintained])
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "#set_licenses" do
|
144
|
-
let(:dependency) { Dependency.named('some gem') }
|
145
|
-
|
146
|
-
it "keeps a manually assigned license" do
|
147
|
-
dependency.set_license_manually! License.find_by_name("manual")
|
148
|
-
dependency.set_licenses [License.find_by_name("new")].to_set
|
149
|
-
expect(dependency.licenses.first.name).to eq "manual"
|
150
|
-
end
|
151
|
-
|
152
|
-
it "saves a new license" do
|
153
|
-
dependency.set_licenses [License.find_by_name("new license")].to_set
|
154
|
-
expect(dependency.licenses.first.name).to eq "new license"
|
155
|
-
end
|
156
|
-
|
157
|
-
it "updates the license's name" do
|
158
|
-
dependency.licenses = [License.find_by_name("old")].to_set
|
159
|
-
|
160
|
-
dependency.set_licenses [License.find_by_name("new license")].to_set
|
161
|
-
expect(dependency.licenses.first.name).to eq "new license"
|
162
|
-
end
|
163
|
-
|
164
|
-
it "won't update the database if the license isn't changing" do
|
165
|
-
# See note in PackageSaver#save
|
166
|
-
dependency.licenses = [License.find_by_name("same")].to_set
|
167
|
-
expect(dependency).to be_modified
|
168
|
-
dependency.save
|
169
|
-
expect(dependency).not_to be_modified
|
170
|
-
|
171
|
-
dependency.set_licenses [License.find_by_name("same")].to_set
|
172
|
-
expect(dependency).not_to be_modified
|
173
|
-
end
|
174
|
-
|
175
|
-
it "updates the database if an additional license is added" do
|
176
|
-
# See note in PackageSaver#save
|
177
|
-
dependency.licenses = [License.find_by_name("first")].to_set
|
178
|
-
expect(dependency).to be_modified
|
179
|
-
dependency.save
|
180
|
-
expect(dependency).not_to be_modified
|
181
|
-
|
182
|
-
dependency.set_licenses [License.find_by_name("first"), License.find_by_name("second")].to_set
|
183
|
-
expect(dependency).to be_modified
|
184
|
-
end
|
185
|
-
|
186
|
-
it "does not change the approval" do
|
187
|
-
dependency.licenses = [License.find_by_name("old")].to_set
|
188
|
-
dependency.approve!
|
189
|
-
|
190
|
-
dependency.set_licenses [License.find_by_name("new license")].to_set
|
191
|
-
expect(dependency).to be_approved
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|