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
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
module CLI
|
5
|
+
describe ProjectName do
|
6
|
+
let(:decisions) { Decisions.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(Decisions).to receive(:saved!) { decisions }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "show" do
|
13
|
+
it "shows the configured project name" do
|
14
|
+
decisions.name_project("test")
|
15
|
+
|
16
|
+
expect(capture_stdout { subject.show }).to match /test/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "add" do
|
21
|
+
it "sets the project name" do
|
22
|
+
silence_stdout do
|
23
|
+
subject.add("test")
|
24
|
+
end
|
25
|
+
expect(subject.decisions.project_name).to eq "test"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "remove" do
|
30
|
+
it "removes the project name" do
|
31
|
+
silence_stdout do
|
32
|
+
subject.add("test")
|
33
|
+
subject.remove
|
34
|
+
end
|
35
|
+
expect(subject.decisions.project_name).to be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
module CLI
|
5
|
+
describe Whitelist do
|
6
|
+
let(:decisions) { Decisions.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(Decisions).to receive(:saved!) { decisions }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "list" do
|
13
|
+
it "shows the whitelist of licenses" do
|
14
|
+
decisions.whitelist("MIT")
|
15
|
+
|
16
|
+
expect(capture_stdout { subject.list }).to match /MIT/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "add" do
|
21
|
+
it "adds the specified license to the whitelist" do
|
22
|
+
silence_stdout do
|
23
|
+
subject.add("test")
|
24
|
+
end
|
25
|
+
expect(subject.decisions.whitelisted).to eq [License.find_by_name("test")].to_set
|
26
|
+
end
|
27
|
+
|
28
|
+
it "adds multiple licenses to the whitelist" do
|
29
|
+
silence_stdout do
|
30
|
+
subject.add("test", "rest")
|
31
|
+
end
|
32
|
+
expect(subject.decisions.whitelisted).to eq [
|
33
|
+
License.find_by_name("test"),
|
34
|
+
License.find_by_name("rest")
|
35
|
+
].to_set
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "remove" do
|
40
|
+
it "removes the specified license from the whitelist" do
|
41
|
+
silence_stdout do
|
42
|
+
subject.add("test")
|
43
|
+
subject.remove("test")
|
44
|
+
end
|
45
|
+
expect(subject.decisions.whitelisted).to be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it "removes multiple licenses from the whitelist" do
|
49
|
+
silence_stdout do
|
50
|
+
subject.add("test", "rest")
|
51
|
+
subject.remove("test", "rest")
|
52
|
+
end
|
53
|
+
expect(subject.decisions.whitelisted).to be_empty
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -2,209 +2,64 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
module LicenseFinder
|
4
4
|
describe Configuration do
|
5
|
-
describe ".
|
5
|
+
describe ".with_optional_saved_config" do
|
6
6
|
it "should init and use saved config" do
|
7
|
-
|
8
|
-
allow(Configuration::Persistence).to receive(:get).and_return('whitelist' => ['Saved License'])
|
7
|
+
fake_project_dir = Pathname.new(__FILE__).dirname.join('..', '..', 'fixtures')
|
9
8
|
|
10
|
-
|
9
|
+
subject = described_class.with_optional_saved_config({}, fake_project_dir)
|
10
|
+
expect(subject.gradle_command).to eq('gradlew')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe "
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
describe "gradle_command" do
|
15
|
+
it "prefers primary value" do
|
16
|
+
subject = described_class.new(
|
17
|
+
{gradle_command: "primary"},
|
18
|
+
{"gradle_command" => "secondary"}
|
19
|
+
)
|
20
|
+
expect(subject.gradle_command).to eq "primary"
|
18
21
|
end
|
19
22
|
|
20
|
-
it
|
21
|
-
|
23
|
+
it "accepts saved value" do
|
24
|
+
subject = described_class.new(
|
25
|
+
{gradle_command: nil},
|
26
|
+
{"gradle_command" => "secondary"}
|
27
|
+
)
|
28
|
+
expect(subject.gradle_command).to eq "secondary"
|
22
29
|
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '.new' do
|
26
|
-
it "should default missing attributes" do
|
27
|
-
subject = described_class.new({})
|
28
|
-
expect(subject.whitelist).to eq([])
|
29
|
-
expect(subject.ignore_groups).to eq([])
|
30
|
-
expect(subject.ignore_dependencies).to eq([])
|
31
|
-
expect(subject.artifacts.dir).to eq(Pathname('./doc/'))
|
32
|
-
expect(subject.gradle_command).to eq('gradle')
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should default missing attributes even if they are saved as nils in the YAML file" do
|
36
|
-
attributes = {
|
37
|
-
"whitelist" => nil,
|
38
|
-
"ignore_groups" => nil,
|
39
|
-
"ignore_dependencies" => nil,
|
40
|
-
"dependencies_file_dir" => nil,
|
41
|
-
"project_name" => nil,
|
42
|
-
"gradle_command" => nil
|
43
|
-
}
|
44
|
-
subject = described_class.new(attributes)
|
45
|
-
expect(subject.whitelist).to eq([])
|
46
|
-
expect(subject.ignore_groups).to eq([])
|
47
|
-
expect(subject.ignore_dependencies).to eq([])
|
48
|
-
expect(subject.artifacts.dir).to eq(Pathname('./doc/'))
|
49
|
-
expect(subject.project_name).not_to be_nil
|
50
|
-
expect(subject.gradle_command).to eq('gradle')
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should set the all of the attributes on the instance" do
|
54
|
-
attributes = {
|
55
|
-
"whitelist" => %w{a whitelist},
|
56
|
-
"ignore_groups" => %w{test development},
|
57
|
-
"ignore_dependencies" => %w{bundler},
|
58
|
-
"dependencies_file_dir" => "some/path",
|
59
|
-
"project_name" => "my_app",
|
60
|
-
"gradle_command" => "./gradlew"
|
61
|
-
}
|
62
|
-
subject = described_class.new(attributes)
|
63
|
-
expect(subject.whitelist).to eq(%w{a whitelist})
|
64
|
-
expect(subject.ignore_groups).to eq(%w{test development})
|
65
|
-
expect(subject.ignore_dependencies).to eq(%w{bundler})
|
66
|
-
expect(subject.artifacts.dir).to eq(Pathname("some/path"))
|
67
|
-
expect(subject.project_name).to eq("my_app")
|
68
|
-
expect(subject.gradle_command).to eq("./gradlew")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "file paths" do
|
73
|
-
it "should be relative to artifacts dir" do
|
74
|
-
artifacts = described_class.new('dependencies_file_dir' => './elsewhere').artifacts
|
75
|
-
expect(artifacts.dir).to eq(Pathname('./elsewhere'))
|
76
|
-
expect(artifacts.legacy_yaml_file).to eq(Pathname('./elsewhere/dependencies.yml'))
|
77
|
-
expect(artifacts.text_file).to eq(Pathname('./elsewhere/dependencies.csv'))
|
78
|
-
expect(artifacts.html_file).to eq(Pathname('./elsewhere/dependencies.html'))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#database_uri" do
|
83
|
-
it "should URI escape absolute path to dependencies_file_dir, even with spaces" do
|
84
|
-
artifacts = described_class.new('dependencies_file_dir' => 'test path').artifacts
|
85
|
-
expect(artifacts.database_uri).to match(%r{test%20path/dependencies\.db$})
|
86
|
-
end
|
87
|
-
end
|
88
30
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
31
|
+
it "has default" do
|
32
|
+
subject = described_class.new(
|
33
|
+
{gradle_command: nil},
|
34
|
+
{"gradle_command" => nil}
|
35
|
+
)
|
36
|
+
expect(subject.gradle_command).to eq "gradle"
|
93
37
|
end
|
94
38
|
end
|
95
39
|
|
96
|
-
describe "
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
it "
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
expect(Configuration::Persistence).to receive(:set).with(attributes)
|
120
|
-
config.save
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe Configuration::Artifacts do
|
126
|
-
describe "#last_refreshed" do
|
127
|
-
let(:database_modified_time) { 1 }
|
128
|
-
let(:text_modified_time) { 2 }
|
129
|
-
let(:detailed_text_modified_time) { 3 }
|
130
|
-
let(:html_modified_time) { 4 }
|
131
|
-
let(:markdown_modified_time) { 5 }
|
132
|
-
|
133
|
-
before do
|
134
|
-
allow(File).to receive(:mtime).with('./doc/dependencies.db') { database_modified_time }
|
135
|
-
allow(File).to receive(:mtime).with('./doc/dependencies.csv') { text_modified_time }
|
136
|
-
allow(File).to receive(:mtime).with('./doc/dependencies_detailed.csv') { detailed_text_modified_time }
|
137
|
-
allow(File).to receive(:mtime).with('./doc/dependencies.html') { html_modified_time }
|
138
|
-
allow(File).to receive(:mtime).with('./doc/dependencies.md') { markdown_modified_time }
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'returns the earliest modified date of the config file' do
|
142
|
-
expect(described_class.new(Pathname('./doc')).last_refreshed).to eq database_modified_time
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
describe Configuration::Persistence do
|
148
|
-
describe ".get" do
|
149
|
-
it "should use saved configuration" do
|
150
|
-
file = double(:file,
|
151
|
-
:exist? => true,
|
152
|
-
:read => {'some' => 'config'}.to_yaml)
|
153
|
-
allow(described_class).to receive(:file).and_return(file)
|
154
|
-
|
155
|
-
expect(described_class.get).to eq({'some' => 'config'})
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should not mind if config is not saved" do
|
159
|
-
file = double(:file, :exist? => false)
|
160
|
-
allow(described_class).to receive(:file).and_return(file)
|
161
|
-
|
162
|
-
expect(file).not_to receive(:read)
|
163
|
-
expect(described_class.get).to eq({})
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe ".set" do
|
168
|
-
let(:tmp_yml) { '.tmp.configuration_spec.yml' }
|
169
|
-
|
170
|
-
after do
|
171
|
-
File.delete(tmp_yml)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "writes the configuration attributes to the yaml file" do
|
175
|
-
allow(described_class).to receive(:file).and_return(Pathname.new(tmp_yml))
|
176
|
-
|
177
|
-
described_class.set('some' => 'config')
|
178
|
-
expect(described_class.get).to eq({'some' => 'config'})
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe ".init" do
|
183
|
-
it "initializes the config file" do
|
184
|
-
file = double(:file, :exist? => false)
|
185
|
-
allow(described_class).to receive(:file).and_return(file)
|
186
|
-
|
187
|
-
expect(FileUtils).to receive(:cp).with(described_class.send(:file_template), file)
|
188
|
-
described_class.init
|
189
|
-
end
|
190
|
-
|
191
|
-
it "does nothing if there is already a config file" do
|
192
|
-
file = double(:file, :exist? => true)
|
193
|
-
allow(described_class).to receive(:file).and_return(file)
|
194
|
-
|
195
|
-
expect(FileUtils).not_to receive(:cp)
|
196
|
-
described_class.init
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe ".last_modified" do
|
201
|
-
let(:time) { double :time }
|
202
|
-
before do
|
203
|
-
allow(File).to receive(:mtime).with('config/license_finder.yml') { time }
|
204
|
-
end
|
205
|
-
|
206
|
-
it "returns the last time the yml file was modified" do
|
207
|
-
expect(described_class.last_modified).to eq time
|
40
|
+
describe "decisions_file" do
|
41
|
+
it "prefers primary value" do
|
42
|
+
subject = described_class.new(
|
43
|
+
{decisions_file: "primary"},
|
44
|
+
{"decisions_file" => "secondary"}
|
45
|
+
)
|
46
|
+
expect(subject.decisions_file.to_s).to eq "primary"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "accepts saved value" do
|
50
|
+
subject = described_class.new(
|
51
|
+
{decisions_file: nil},
|
52
|
+
{"decisions_file" => "secondary"}
|
53
|
+
)
|
54
|
+
expect(subject.decisions_file.to_s).to eq "secondary"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has default" do
|
58
|
+
subject = described_class.new(
|
59
|
+
{decisions_file: nil},
|
60
|
+
{"decisions_file" => nil}
|
61
|
+
)
|
62
|
+
expect(subject.decisions_file.to_s).to eq "doc/dependency_decisions.yml"
|
208
63
|
end
|
209
64
|
end
|
210
65
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
describe DecisionApplier do
|
5
|
+
describe ".acknowledged" do
|
6
|
+
it "combines manual and system packages" do
|
7
|
+
decision_applier = described_class.new(
|
8
|
+
decisions: Decisions.new.add_package("manual", nil),
|
9
|
+
packages: [Package.new("system")]
|
10
|
+
)
|
11
|
+
expect(decision_applier.acknowledged.map(&:name)).to match_array ["manual", "system"]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "applies decided licenses" do
|
15
|
+
decisions = Decisions.new.
|
16
|
+
add_package("manual", nil).
|
17
|
+
license("manual", "MIT")
|
18
|
+
decision_applier = described_class.new(decisions: decisions, packages: [])
|
19
|
+
expect(decision_applier.acknowledged.last.licenses).to eq Set.new([License.find_by_name("MIT")])
|
20
|
+
end
|
21
|
+
|
22
|
+
it "ignores specific packages" do
|
23
|
+
decisions = Decisions.new.
|
24
|
+
add_package("manual", nil).
|
25
|
+
ignore("manual")
|
26
|
+
decision_applier = described_class.new(decisions: decisions, packages: [])
|
27
|
+
expect(decision_applier.acknowledged).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it "ignores packages in certain groups" do
|
31
|
+
decisions = Decisions.new.
|
32
|
+
ignore_group("development")
|
33
|
+
dev_dep = Package.new("dep", nil, groups: ["development"])
|
34
|
+
decision_applier = described_class.new(
|
35
|
+
decisions: decisions,
|
36
|
+
packages: [dev_dep]
|
37
|
+
)
|
38
|
+
expect(decision_applier.acknowledged).to be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it "adds manual approvals to packages" do
|
42
|
+
decisions = Decisions.new.
|
43
|
+
add_package("manual", nil).
|
44
|
+
approve("manual", who: "Approver", why: "Because")
|
45
|
+
decision_applier = described_class.new(decisions: decisions, packages: [])
|
46
|
+
dep = decision_applier.acknowledged.last
|
47
|
+
expect(dep).to be_approved
|
48
|
+
expect(dep).to be_approved_manually
|
49
|
+
expect(dep.manual_approval.who).to eq "Approver"
|
50
|
+
expect(dep.manual_approval.why).to eq "Because"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "adds whitelist approvals to packages" do
|
54
|
+
decisions = Decisions.new.
|
55
|
+
add_package("manual", nil).
|
56
|
+
license("manual", "MIT").
|
57
|
+
whitelist("MIT")
|
58
|
+
decision_applier = described_class.new(decisions: decisions, packages: [])
|
59
|
+
dep = decision_applier.acknowledged.last
|
60
|
+
expect(dep).to be_approved
|
61
|
+
expect(dep).to be_whitelisted
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,347 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LicenseFinder
|
4
|
+
describe Decisions do
|
5
|
+
describe ".add_package" do
|
6
|
+
it "adds to list of packages" do
|
7
|
+
packages = subject.add_package("dep", nil).packages
|
8
|
+
expect(packages.map(&:name)).to eq ["dep"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "includes optional version" do
|
12
|
+
packages = subject.add_package("dep", "0.2.0").packages
|
13
|
+
expect(packages.first.version).to eq "0.2.0"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".remove_package" do
|
18
|
+
it "drops a package" do
|
19
|
+
packages = subject.
|
20
|
+
add_package("dep", nil).
|
21
|
+
remove_package("dep").
|
22
|
+
packages
|
23
|
+
expect(packages.size).to eq 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it "does nothing if package was never added" do
|
27
|
+
packages = subject.
|
28
|
+
remove_package("dep").
|
29
|
+
packages
|
30
|
+
expect(packages.size).to eq 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".license" do
|
35
|
+
it "will report license for a dependency" do
|
36
|
+
license = subject.
|
37
|
+
license("dep", "MIT").
|
38
|
+
licenses_of("dep").first
|
39
|
+
expect(license).to eq License.find_by_name("MIT")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "will report multiple licenses" do
|
43
|
+
licenses = subject.
|
44
|
+
license("dep", "MIT").
|
45
|
+
license("dep", "GPL").
|
46
|
+
licenses_of("dep")
|
47
|
+
expect(licenses).to eq [
|
48
|
+
License.find_by_name("MIT"),
|
49
|
+
License.find_by_name("GPL"),
|
50
|
+
].to_set
|
51
|
+
end
|
52
|
+
|
53
|
+
it "adapts names" do
|
54
|
+
license = subject.
|
55
|
+
license("dep", "Expat").
|
56
|
+
licenses_of("dep").first
|
57
|
+
expect(license).to eq License.find_by_name("MIT")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".unlicense" do
|
62
|
+
it "will not report the given dependency as licensed" do
|
63
|
+
licenses = subject.
|
64
|
+
license("dep", "MIT").
|
65
|
+
unlicense("dep", "MIT").
|
66
|
+
licenses_of("dep")
|
67
|
+
expect(licenses).to be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it "will only remove the specified license" do
|
71
|
+
licenses = subject.
|
72
|
+
license("dep", "MIT").
|
73
|
+
license("dep", "GPL").
|
74
|
+
unlicense("dep", "MIT").
|
75
|
+
licenses_of("dep")
|
76
|
+
expect(licenses).to eq [License.find_by_name("GPL")].to_set
|
77
|
+
end
|
78
|
+
|
79
|
+
it "is cumulative" do
|
80
|
+
license = subject.
|
81
|
+
license("dep", "MIT").
|
82
|
+
unlicense("dep", "MIT").
|
83
|
+
license("dep", "MIT").
|
84
|
+
licenses_of("dep").first
|
85
|
+
expect(license).to eq License.find_by_name("MIT")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ".approve" do
|
90
|
+
it "will report a dependency as approved" do
|
91
|
+
decisions = subject.approve("dep")
|
92
|
+
expect(decisions).to be_approved("dep")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "will not report a dependency as approved by default" do
|
96
|
+
expect(subject).not_to be_approved("dep")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe ".unapprove" do
|
101
|
+
it "will not report the given dependency as approved" do
|
102
|
+
decisions = subject.
|
103
|
+
approve("dep").
|
104
|
+
unapprove("dep")
|
105
|
+
expect(subject).not_to be_approved("dep")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "is cumulative" do
|
109
|
+
decisions = subject.
|
110
|
+
approve("dep").
|
111
|
+
unapprove("dep").
|
112
|
+
approve("dep")
|
113
|
+
expect(subject).to be_approved("dep")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ".whitelist" do
|
118
|
+
it "will report the given license as approved" do
|
119
|
+
decisions = subject.whitelist("MIT")
|
120
|
+
expect(decisions).to be_whitelisted(License.find_by_name("MIT"))
|
121
|
+
end
|
122
|
+
|
123
|
+
it "adapts names" do
|
124
|
+
decisions = subject.whitelist("Expat")
|
125
|
+
expect(decisions).to be_whitelisted(License.find_by_name("MIT"))
|
126
|
+
end
|
127
|
+
|
128
|
+
it "adds to list" do
|
129
|
+
decisions = subject.whitelist("MIT")
|
130
|
+
expect(decisions.whitelisted).to eq(Set.new([License.find_by_name("MIT")]))
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe ".unwhitelist" do
|
135
|
+
it "will not report the given license as approved" do
|
136
|
+
decisions = subject.
|
137
|
+
whitelist("MIT").
|
138
|
+
unwhitelist("MIT")
|
139
|
+
expect(decisions).not_to be_whitelisted(License.find_by_name("MIT"))
|
140
|
+
end
|
141
|
+
|
142
|
+
it "is cumulative" do
|
143
|
+
decisions = subject.
|
144
|
+
whitelist("MIT").
|
145
|
+
unwhitelist("MIT").
|
146
|
+
whitelist("MIT")
|
147
|
+
expect(decisions).to be_whitelisted(License.find_by_name("MIT"))
|
148
|
+
end
|
149
|
+
|
150
|
+
it "adapts names" do
|
151
|
+
decisions = subject.
|
152
|
+
whitelist("MIT").
|
153
|
+
unwhitelist("Expat")
|
154
|
+
expect(decisions).not_to be_whitelisted(License.find_by_name("MIT"))
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe ".ignore" do
|
159
|
+
it "will report ignored dependencies" do
|
160
|
+
decisions = subject.ignore("dep")
|
161
|
+
expect(decisions).to be_ignored("dep")
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe ".heed" do
|
166
|
+
it "will not report heeded dependencies" do
|
167
|
+
decisions = subject.
|
168
|
+
ignore("dep").
|
169
|
+
heed("dep")
|
170
|
+
expect(decisions).not_to be_ignored("dep")
|
171
|
+
end
|
172
|
+
|
173
|
+
it "is cumulative" do
|
174
|
+
decisions = subject.
|
175
|
+
ignore("dep").
|
176
|
+
heed("dep").
|
177
|
+
ignore("dep")
|
178
|
+
expect(decisions).to be_ignored("dep")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe ".ignore_group" do
|
183
|
+
it "will report ignored groups" do
|
184
|
+
decisions = subject.
|
185
|
+
ignore_group("development")
|
186
|
+
expect(decisions).to be_ignored_group("development")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe ".heed_group" do
|
191
|
+
it "will not report heeded groups" do
|
192
|
+
decisions = subject.
|
193
|
+
ignore_group("development").
|
194
|
+
heed_group("development")
|
195
|
+
expect(decisions).not_to be_ignored_group("development")
|
196
|
+
end
|
197
|
+
|
198
|
+
it "is cumulative" do
|
199
|
+
decisions = subject.
|
200
|
+
ignore_group("development").
|
201
|
+
heed_group("development").
|
202
|
+
ignore_group("development")
|
203
|
+
expect(decisions).to be_ignored_group("development")
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe ".name_project" do
|
208
|
+
it "reports project name" do
|
209
|
+
decisions = subject.name_project("proj")
|
210
|
+
expect(decisions.project_name).to eq "proj"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe ".unname_project" do
|
215
|
+
it "reports project name" do
|
216
|
+
decisions = subject.
|
217
|
+
name_project("proj").
|
218
|
+
unname_project
|
219
|
+
expect(decisions.project_name).to be_nil
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "persistence" do
|
224
|
+
def roundtrip(decisions)
|
225
|
+
described_class.restore(decisions.persist)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "can restore added packages" do
|
229
|
+
decisions = roundtrip(
|
230
|
+
subject.
|
231
|
+
add_package("dep", "0.2.0")
|
232
|
+
)
|
233
|
+
packages = decisions.packages
|
234
|
+
expect(packages.map(&:name)).to eq ["dep"]
|
235
|
+
end
|
236
|
+
|
237
|
+
it "can restore removed packages" do
|
238
|
+
decisions = roundtrip(
|
239
|
+
subject.
|
240
|
+
add_package("dep", nil).
|
241
|
+
remove_package("dep")
|
242
|
+
)
|
243
|
+
expect(decisions.packages.size).to eq 0
|
244
|
+
end
|
245
|
+
|
246
|
+
it "can restore licenses" do
|
247
|
+
license = roundtrip(
|
248
|
+
subject.license("dep", "MIT")
|
249
|
+
).licenses_of("dep").first
|
250
|
+
expect(license).to eq License.find_by_name("MIT")
|
251
|
+
end
|
252
|
+
|
253
|
+
it "can restore unlicenses" do
|
254
|
+
licenses = roundtrip(
|
255
|
+
subject.
|
256
|
+
license("dep", "MIT").
|
257
|
+
license("dep", "GPL").
|
258
|
+
unlicense("dep", "MIT")
|
259
|
+
).licenses_of("dep")
|
260
|
+
expect(licenses).to eq [License.find_by_name("GPL")].to_set
|
261
|
+
end
|
262
|
+
|
263
|
+
it "can restore approvals" do
|
264
|
+
time = Time.now.getutc
|
265
|
+
decisions = roundtrip(subject.approve("dep", who: "Somebody", why: "Some reason", when: time))
|
266
|
+
expect(decisions).to be_approved("dep")
|
267
|
+
approval = decisions.approval_of("dep")
|
268
|
+
expect(approval.who).to eq "Somebody"
|
269
|
+
expect(approval.why).to eq "Some reason"
|
270
|
+
expect(approval.safe_when).to eq time
|
271
|
+
end
|
272
|
+
|
273
|
+
it "can restore unapprovals" do
|
274
|
+
decisions = roundtrip(
|
275
|
+
subject.
|
276
|
+
approve("dep").
|
277
|
+
unapprove("dep")
|
278
|
+
)
|
279
|
+
expect(decisions).not_to be_approved("dep")
|
280
|
+
end
|
281
|
+
|
282
|
+
it "can restore whitelists" do
|
283
|
+
decisions = roundtrip(
|
284
|
+
subject.whitelist("MIT")
|
285
|
+
)
|
286
|
+
expect(decisions).to be_whitelisted(License.find_by_name("MIT"))
|
287
|
+
end
|
288
|
+
|
289
|
+
it "can restore un-whitelists" do
|
290
|
+
decisions = roundtrip(
|
291
|
+
subject.
|
292
|
+
whitelist("MIT").
|
293
|
+
unwhitelist("MIT")
|
294
|
+
)
|
295
|
+
expect(decisions).not_to be_whitelisted(License.find_by_name("MIT"))
|
296
|
+
end
|
297
|
+
|
298
|
+
it "can restore ignorals" do
|
299
|
+
decisions = roundtrip(subject.ignore("dep"))
|
300
|
+
expect(decisions).to be_ignored("dep")
|
301
|
+
end
|
302
|
+
|
303
|
+
it "can restore heeds" do
|
304
|
+
decisions = roundtrip(
|
305
|
+
subject.
|
306
|
+
ignore("dep").
|
307
|
+
heed("dep")
|
308
|
+
)
|
309
|
+
expect(decisions).not_to be_ignored("dep")
|
310
|
+
end
|
311
|
+
|
312
|
+
it "can restore ignored groups" do
|
313
|
+
decisions = roundtrip(
|
314
|
+
subject.
|
315
|
+
ignore_group("development")
|
316
|
+
)
|
317
|
+
expect(decisions).to be_ignored_group("development")
|
318
|
+
end
|
319
|
+
|
320
|
+
it "can restore heeded groups" do
|
321
|
+
decisions = roundtrip(
|
322
|
+
subject.
|
323
|
+
ignore_group("development").
|
324
|
+
heed_group("development")
|
325
|
+
)
|
326
|
+
expect(decisions).not_to be_ignored_group("development")
|
327
|
+
end
|
328
|
+
|
329
|
+
it "can restore project names" do
|
330
|
+
decisions = roundtrip(
|
331
|
+
subject.
|
332
|
+
name_project("an-app")
|
333
|
+
)
|
334
|
+
expect(decisions.project_name).to eq "an-app"
|
335
|
+
end
|
336
|
+
|
337
|
+
it "can restore project unnames" do
|
338
|
+
decisions = roundtrip(
|
339
|
+
subject.
|
340
|
+
name_project("an-app").
|
341
|
+
unname_project
|
342
|
+
)
|
343
|
+
expect(decisions.project_name).to be_nil
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|