license-acceptance 0.2.10 → 2.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +17 -1
- data/config/product_info.toml +41 -10
- data/lib/license_acceptance/acceptor.rb +107 -50
- data/lib/license_acceptance/cli_flags/mixlib_cli.rb +2 -2
- data/lib/license_acceptance/cli_flags/thor.rb +3 -3
- data/lib/license_acceptance/config.rb +6 -4
- data/lib/license_acceptance/logger.rb +1 -1
- data/lib/license_acceptance/product.rb +15 -8
- data/lib/license_acceptance/product_reader.rb +32 -17
- data/lib/license_acceptance/strategy/argument.rb +45 -0
- data/lib/license_acceptance/strategy/base.rb +7 -0
- data/lib/license_acceptance/strategy/environment.rb +39 -0
- data/lib/license_acceptance/strategy/file.rb +101 -0
- data/lib/license_acceptance/strategy/prompt.rb +111 -0
- data/lib/license_acceptance/strategy/provided_value.rb +31 -0
- data/lib/license_acceptance/version.rb +1 -1
- metadata +20 -137
- data/Gemfile.lock +0 -94
- data/Rakefile +0 -6
- data/lib/license_acceptance/arg_acceptance.rb +0 -32
- data/lib/license_acceptance/env_acceptance.rb +0 -26
- data/lib/license_acceptance/file_acceptance.rb +0 -97
- data/lib/license_acceptance/prompt_acceptance.rb +0 -106
- data/spec/license_acceptance/acceptor_spec.rb +0 -272
- data/spec/license_acceptance/arg_acceptance_spec.rb +0 -57
- data/spec/license_acceptance/cli_flags/mixlib_cli_spec.rb +0 -14
- data/spec/license_acceptance/cli_flags/thor_spec.rb +0 -14
- data/spec/license_acceptance/config_spec.rb +0 -111
- data/spec/license_acceptance/env_acceptance_spec.rb +0 -65
- data/spec/license_acceptance/file_acceptance_spec.rb +0 -121
- data/spec/license_acceptance/product_reader_spec.rb +0 -139
- data/spec/license_acceptance/product_spec.rb +0 -13
- data/spec/license_acceptance/prompt_acceptance_spec.rb +0 -100
- data/spec/spec_helper.rb +0 -25
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
require 'date'
|
|
2
|
-
require 'yaml'
|
|
3
|
-
require 'fileutils'
|
|
4
|
-
require 'etc'
|
|
5
|
-
require "license_acceptance/logger"
|
|
6
|
-
|
|
7
|
-
module LicenseAcceptance
|
|
8
|
-
class FileAcceptance
|
|
9
|
-
include Logger
|
|
10
|
-
|
|
11
|
-
attr_reader :config
|
|
12
|
-
|
|
13
|
-
def initialize(config)
|
|
14
|
-
@config = config
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
INVOCATION_TIME = DateTime.now.freeze
|
|
18
|
-
|
|
19
|
-
# For all the given products in the product set, search all possible locations for the
|
|
20
|
-
# license acceptance files.
|
|
21
|
-
def accepted?(product_relationship)
|
|
22
|
-
searching = [product_relationship.parent] + product_relationship.children
|
|
23
|
-
missing_licenses = searching.clone
|
|
24
|
-
logger.debug("Searching for the following licenses: #{missing_licenses.map(&:name)}")
|
|
25
|
-
|
|
26
|
-
searching.each do |product|
|
|
27
|
-
found = false
|
|
28
|
-
config.license_locations.each do |loc|
|
|
29
|
-
f = File.join(loc, product.filename)
|
|
30
|
-
if File.exist?(f)
|
|
31
|
-
found = true
|
|
32
|
-
logger.debug("Found license #{product.filename} at #{f}")
|
|
33
|
-
missing_licenses.delete(product)
|
|
34
|
-
break
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
break if missing_licenses.empty?
|
|
38
|
-
end
|
|
39
|
-
logger.debug("Missing licenses remaining: #{missing_licenses.map(&:name)}")
|
|
40
|
-
missing_licenses
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def persist(product_relationship, missing_licenses)
|
|
44
|
-
parent = product_relationship.parent
|
|
45
|
-
parent_version = product_relationship.parent_version
|
|
46
|
-
root_dir = config.persist_location
|
|
47
|
-
|
|
48
|
-
if !Dir.exist?(root_dir)
|
|
49
|
-
begin
|
|
50
|
-
FileUtils.mkdir_p(root_dir)
|
|
51
|
-
rescue StandardError => e
|
|
52
|
-
msg = "Could not create license directory #{root_dir}"
|
|
53
|
-
logger.info "#{msg}\n\t#{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
|
54
|
-
return [e]
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
errs = []
|
|
59
|
-
if missing_licenses.include?(parent)
|
|
60
|
-
err = persist_license(root_dir, parent, parent, parent_version)
|
|
61
|
-
errs << err unless err.nil?
|
|
62
|
-
end
|
|
63
|
-
product_relationship.children.each do |child|
|
|
64
|
-
if missing_licenses.include?(child)
|
|
65
|
-
err = persist_license(root_dir, child, parent, parent_version)
|
|
66
|
-
errs << err unless err.nil?
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
return errs
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
def persist_license(folder_path, product, parent, parent_version)
|
|
75
|
-
path = File.join(folder_path, product.filename)
|
|
76
|
-
logger.info("Persisting a license for #{product.name} at path #{path}")
|
|
77
|
-
File.open(path, File::WRONLY | File::CREAT | File::EXCL) do |license_file|
|
|
78
|
-
contents = {
|
|
79
|
-
name: product.name,
|
|
80
|
-
date_accepted: INVOCATION_TIME.iso8601,
|
|
81
|
-
accepting_product: parent.name,
|
|
82
|
-
accepting_product_version: parent_version,
|
|
83
|
-
user: Etc.getlogin,
|
|
84
|
-
file_format: 1,
|
|
85
|
-
}
|
|
86
|
-
contents = Hash[contents.map { |k, v| [k.to_s, v] }]
|
|
87
|
-
license_file << YAML.dump(contents)
|
|
88
|
-
end
|
|
89
|
-
return nil
|
|
90
|
-
rescue StandardError => e
|
|
91
|
-
msg = "Could not persist license to #{path}"
|
|
92
|
-
logger.info "#{msg}\n\t#{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
|
93
|
-
return e
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
end
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
require 'tty-prompt'
|
|
2
|
-
require 'pastel'
|
|
3
|
-
require "license_acceptance/logger"
|
|
4
|
-
require "timeout"
|
|
5
|
-
|
|
6
|
-
module LicenseAcceptance
|
|
7
|
-
class PromptAcceptance
|
|
8
|
-
include Logger
|
|
9
|
-
|
|
10
|
-
attr_reader :output
|
|
11
|
-
|
|
12
|
-
def initialize(config)
|
|
13
|
-
@output = config.output
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
WIDTH = 50.freeze
|
|
17
|
-
PASTEL = Pastel.new
|
|
18
|
-
BORDER = "+---------------------------------------------+".freeze
|
|
19
|
-
YES = PASTEL.green.bold("yes")
|
|
20
|
-
CHECK = PASTEL.green("✔")
|
|
21
|
-
|
|
22
|
-
def request(missing_licenses, &persist_callback)
|
|
23
|
-
logger.debug("Requesting a license for #{missing_licenses.map(&:name)}")
|
|
24
|
-
c = missing_licenses.size
|
|
25
|
-
s = c > 1 ? "s": ""
|
|
26
|
-
|
|
27
|
-
acceptance_question = "Do you accept the #{c} product license#{s} (#{YES}/no)?"
|
|
28
|
-
output.puts <<~EOM
|
|
29
|
-
#{BORDER}
|
|
30
|
-
Chef License Acceptance
|
|
31
|
-
|
|
32
|
-
Before you can continue, #{c} product license#{s}
|
|
33
|
-
must be accepted. View the license at
|
|
34
|
-
https://www.chef.io/end-user-license-agreement/
|
|
35
|
-
|
|
36
|
-
License#{s} that need accepting:
|
|
37
|
-
* #{missing_licenses.map(&:pretty_name).join("\n * ")}
|
|
38
|
-
|
|
39
|
-
#{acceptance_question}
|
|
40
|
-
|
|
41
|
-
EOM
|
|
42
|
-
|
|
43
|
-
if ask(output, c, s, persist_callback)
|
|
44
|
-
output.puts BORDER
|
|
45
|
-
return true
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
output.puts <<~EOM
|
|
49
|
-
|
|
50
|
-
If you do not accept this license you will
|
|
51
|
-
not be able to use Chef products.
|
|
52
|
-
|
|
53
|
-
#{acceptance_question}
|
|
54
|
-
|
|
55
|
-
EOM
|
|
56
|
-
|
|
57
|
-
answer = ask(output, c, s, persist_callback)
|
|
58
|
-
if answer != "yes"
|
|
59
|
-
output.puts BORDER
|
|
60
|
-
end
|
|
61
|
-
return answer
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
private
|
|
65
|
-
|
|
66
|
-
def ask(output, c, s, persist_callback)
|
|
67
|
-
logger.debug("Attempting to request interactive prompt on TTY")
|
|
68
|
-
prompt = TTY::Prompt.new(track_history: false, active_color: :bold, interrupt: :exit, output: output)
|
|
69
|
-
|
|
70
|
-
answer = "no"
|
|
71
|
-
begin
|
|
72
|
-
Timeout::timeout(60, PromptTimeout) do
|
|
73
|
-
answer = prompt.ask(">") do |q|
|
|
74
|
-
q.modify :down, :trim
|
|
75
|
-
q.required true
|
|
76
|
-
q.messages[:required?] = "You must enter 'yes' or 'no'"
|
|
77
|
-
q.validate /^\s*(yes|no)\s*$/i
|
|
78
|
-
q.messages[:valid?] = "You must enter 'yes' or 'no'"
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
rescue PromptTimeout
|
|
82
|
-
prompt.unsubscribe(prompt.reader)
|
|
83
|
-
output.puts "Prompt timed out. Use non-interactive flags or enter an answer within 60 seconds."
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
if answer == "yes"
|
|
87
|
-
output.puts
|
|
88
|
-
output.puts "Persisting #{c} product license#{s}..."
|
|
89
|
-
errs = persist_callback.call
|
|
90
|
-
if errs.empty?
|
|
91
|
-
output.puts "#{CHECK} #{c} product license#{s} persisted.\n\n"
|
|
92
|
-
else
|
|
93
|
-
output.puts <<~EOM
|
|
94
|
-
#{CHECK} #{c} product license#{s} accepted.
|
|
95
|
-
Could not persist acceptance:\n\t* #{errs.map(&:message).join("\n\t* ")}
|
|
96
|
-
EOM
|
|
97
|
-
end
|
|
98
|
-
return true
|
|
99
|
-
end
|
|
100
|
-
return false
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class PromptTimeout < StandardError; end
|
|
106
|
-
end
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "license_acceptance/acceptor"
|
|
3
|
-
|
|
4
|
-
RSpec.describe LicenseAcceptance::Acceptor do
|
|
5
|
-
it "has a version number" do
|
|
6
|
-
expect(LicenseAcceptance::VERSION).not_to be nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
let(:output) do
|
|
10
|
-
d = StringIO.new
|
|
11
|
-
allow(d).to receive(:isatty).and_return(true)
|
|
12
|
-
d
|
|
13
|
-
end
|
|
14
|
-
let(:opts) { { output: output } }
|
|
15
|
-
let(:acc) { LicenseAcceptance::Acceptor.new(opts) }
|
|
16
|
-
let(:product) { "chef_client" }
|
|
17
|
-
let(:version) { "version" }
|
|
18
|
-
let(:relationship) { instance_double(LicenseAcceptance::ProductRelationship) }
|
|
19
|
-
let(:p1) { instance_double(LicenseAcceptance::Product) }
|
|
20
|
-
let(:missing) { [p1] }
|
|
21
|
-
|
|
22
|
-
describe "#check_and_persist!" do
|
|
23
|
-
let(:err) { LicenseAcceptance::LicenseNotAcceptedError.new([product]) }
|
|
24
|
-
it "outputs an error message to stdout and exits when license acceptance is declined" do
|
|
25
|
-
expect(acc).to receive(:check_and_persist).and_raise(err)
|
|
26
|
-
expect { acc.check_and_persist!(product, version) }.to raise_error(SystemExit)
|
|
27
|
-
expect(output.string).to match(/#{product}/)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#check_and_persist" do
|
|
32
|
-
let(:reader) { instance_double(LicenseAcceptance::ProductReader) }
|
|
33
|
-
let(:file_acc) { instance_double(LicenseAcceptance::FileAcceptance) }
|
|
34
|
-
let(:arg_acc) { instance_double(LicenseAcceptance::ArgAcceptance) }
|
|
35
|
-
let(:prompt_acc) { instance_double(LicenseAcceptance::PromptAcceptance) }
|
|
36
|
-
let(:env_acc) { instance_double(LicenseAcceptance::EnvAcceptance) }
|
|
37
|
-
|
|
38
|
-
before do
|
|
39
|
-
expect(LicenseAcceptance::ProductReader).to receive(:new).and_return(reader)
|
|
40
|
-
expect(LicenseAcceptance::FileAcceptance).to receive(:new).and_return(file_acc)
|
|
41
|
-
expect(LicenseAcceptance::ArgAcceptance).to receive(:new).and_return(arg_acc)
|
|
42
|
-
expect(LicenseAcceptance::PromptAcceptance).to receive(:new).and_return(prompt_acc)
|
|
43
|
-
expect(LicenseAcceptance::EnvAcceptance).to receive(:new).and_return(env_acc)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "when check-no-persist environment variable is set" do
|
|
47
|
-
it "returns true" do
|
|
48
|
-
expect(env_acc).to receive(:no_persist?).and_return(true)
|
|
49
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe "when check-no-persist command line argument is set" do
|
|
54
|
-
it "returns true" do
|
|
55
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
56
|
-
expect(arg_acc).to receive(:no_persist?).and_return(true)
|
|
57
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "when there are no missing licenses" do
|
|
62
|
-
it "returns true" do
|
|
63
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
64
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
65
|
-
expect(reader).to receive(:read)
|
|
66
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
67
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return([])
|
|
68
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe "when the user accepts as an environment variable" do
|
|
73
|
-
it "returns true" do
|
|
74
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
75
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
76
|
-
expect(reader).to receive(:read)
|
|
77
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
78
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
79
|
-
expect(env_acc).to receive(:accepted?).with(ENV).and_return(true)
|
|
80
|
-
expect(env_acc).to receive(:silent?).with(ENV).and_return(false)
|
|
81
|
-
expect(arg_acc).to receive(:silent?).with(ARGV).and_return(false)
|
|
82
|
-
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
|
83
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
84
|
-
expect(output.string).to match(/1 product license accepted./)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
describe "when persist is set to false" do
|
|
88
|
-
let(:opts) { { output: output, persist: false } }
|
|
89
|
-
|
|
90
|
-
it "returns true" do
|
|
91
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
92
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
93
|
-
expect(reader).to receive(:read)
|
|
94
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
95
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
96
|
-
expect(env_acc).to receive(:accepted?).with(ENV).and_return(true)
|
|
97
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
98
|
-
expect(output.string).to_not match(/accepted./)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "when the silent option is used" do
|
|
103
|
-
let(:opts) { { output: output } }
|
|
104
|
-
|
|
105
|
-
it "returns true and silently persists the file" do
|
|
106
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
107
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
108
|
-
expect(reader).to receive(:read)
|
|
109
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
110
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
111
|
-
expect(env_acc).to receive(:accepted?).with(ENV).and_return(false)
|
|
112
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(false)
|
|
113
|
-
expect(env_acc).to receive(:silent?).with(ENV).twice.and_return(true)
|
|
114
|
-
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
|
115
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
116
|
-
expect(output.string).to be_empty
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "when file persistance fails" do
|
|
121
|
-
it "returns true" do
|
|
122
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
123
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
124
|
-
expect(reader).to receive(:read)
|
|
125
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
126
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
127
|
-
expect(env_acc).to receive(:accepted?).with(ENV).and_return(true)
|
|
128
|
-
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("foo")])
|
|
129
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
130
|
-
expect(output.string).to match(/Could not persist acceptance:/)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
describe "when the user accepts as an arg" do
|
|
136
|
-
it "returns true" do
|
|
137
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
138
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
139
|
-
expect(reader).to receive(:read)
|
|
140
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
141
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
142
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
143
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
|
|
144
|
-
expect(env_acc).to receive(:silent?).with(ENV).and_return(false)
|
|
145
|
-
expect(arg_acc).to receive(:silent?).with(ARGV).and_return(false)
|
|
146
|
-
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
|
147
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
148
|
-
expect(output.string).to match(/1 product license accepted./)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe "when the silent option is used" do
|
|
152
|
-
let(:opts) { { output: output } }
|
|
153
|
-
|
|
154
|
-
it "returns true and silently persists the file" do
|
|
155
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
156
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
157
|
-
expect(reader).to receive(:read)
|
|
158
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
159
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
160
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
161
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(false)
|
|
162
|
-
expect(env_acc).to receive(:silent?).with(ENV).twice.and_return(false)
|
|
163
|
-
expect(arg_acc).to receive(:silent?).with(ARGV).twice.and_return(true)
|
|
164
|
-
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
|
|
165
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
166
|
-
expect(output.string).to be_empty
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
describe "when persist is set to false" do
|
|
172
|
-
let(:opts) { { output: output, persist: false } }
|
|
173
|
-
|
|
174
|
-
it "returns true" do
|
|
175
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
176
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
177
|
-
expect(reader).to receive(:read)
|
|
178
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
179
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
180
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
181
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
|
|
182
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
183
|
-
expect(output.string).to_not match(/accepted./)
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
describe "when file persistance fails" do
|
|
188
|
-
it "returns true" do
|
|
189
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
190
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
191
|
-
expect(reader).to receive(:read)
|
|
192
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
193
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
194
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
195
|
-
expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
|
|
196
|
-
expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("bar")])
|
|
197
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
198
|
-
expect(output.string).to match(/Could not persist acceptance:/)
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
describe "when the prompt is not a tty" do
|
|
204
|
-
let(:opts) { { output: File.open(File::NULL, "w") } }
|
|
205
|
-
it "raises a LicenseNotAcceptedError error" do
|
|
206
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
207
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
208
|
-
expect(reader).to receive(:read)
|
|
209
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
210
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
211
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
212
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
|
213
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
|
214
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
|
215
|
-
expect(prompt_acc).to_not receive(:request)
|
|
216
|
-
expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
describe "when the user accepts with the prompt" do
|
|
221
|
-
it "returns true" do
|
|
222
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
223
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
224
|
-
expect(reader).to receive(:read)
|
|
225
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
226
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
227
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
228
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
|
229
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
|
230
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
|
231
|
-
expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
|
|
232
|
-
expect(file_acc).to receive(:persist).with(relationship, missing)
|
|
233
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
describe "when persist is set to false" do
|
|
237
|
-
let(:opts) { { output: output, persist: false } }
|
|
238
|
-
|
|
239
|
-
it "returns true" do
|
|
240
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
241
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
242
|
-
expect(reader).to receive(:read)
|
|
243
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
244
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
245
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
246
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
|
247
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
|
248
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
|
249
|
-
expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
|
|
250
|
-
expect(acc.check_and_persist(product, version)).to eq(true)
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
describe "when the user declines with the prompt" do
|
|
256
|
-
it "raises a LicenseNotAcceptedError error" do
|
|
257
|
-
expect(env_acc).to receive(:no_persist?).and_return(false)
|
|
258
|
-
expect(arg_acc).to receive(:no_persist?).and_return(false)
|
|
259
|
-
expect(reader).to receive(:read)
|
|
260
|
-
expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
|
|
261
|
-
expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
|
|
262
|
-
expect(env_acc).to receive(:accepted?).and_return(false)
|
|
263
|
-
expect(arg_acc).to receive(:accepted?).and_return(false)
|
|
264
|
-
expect(env_acc).to receive(:silent?).and_return(false)
|
|
265
|
-
expect(arg_acc).to receive(:silent?).and_return(false)
|
|
266
|
-
expect(prompt_acc).to receive(:request).with(missing).and_return(false)
|
|
267
|
-
expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
end
|
|
272
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "license_acceptance/arg_acceptance"
|
|
3
|
-
|
|
4
|
-
RSpec.describe LicenseAcceptance::ArgAcceptance do
|
|
5
|
-
let(:acc) { LicenseAcceptance::ArgAcceptance.new }
|
|
6
|
-
|
|
7
|
-
describe "with an accept option" do
|
|
8
|
-
describe "#accepted?" do
|
|
9
|
-
it "returns true if the args contain the required flag with spaces" do
|
|
10
|
-
expect(acc.accepted?(["--chef-license", "accept"])).to eq(true)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "returns true if the args contain the required flag with equal" do
|
|
14
|
-
expect(acc.accepted?(["--chef-license=accept"])).to eq(true)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "returns false if the args do not contain the required value" do
|
|
18
|
-
expect(acc.accepted?(["--chef-license"])).to eq(false)
|
|
19
|
-
expect(acc.accepted?(["--chef-license=foo"])).to eq(false)
|
|
20
|
-
expect(acc.accepted?(["--chef-license", "foo"])).to eq(false)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "#silent?" do
|
|
25
|
-
it "returns true if the args contain the required flag with spaces" do
|
|
26
|
-
expect(acc.silent?(["--chef-license", "accept-silent"])).to eq(true)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "returns true if the args contain the required flag with equal" do
|
|
30
|
-
expect(acc.silent?(["--chef-license=accept-silent"])).to eq(true)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "returns false if the args do not contain the required value" do
|
|
34
|
-
expect(acc.silent?(["--chef-license"])).to eq(false)
|
|
35
|
-
expect(acc.silent?(["--chef-license=accept"])).to eq(false)
|
|
36
|
-
expect(acc.silent?(["--chef-license", "accept"])).to eq(false)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe "#no_persist?" do
|
|
42
|
-
it "returns true if the args contain the required flag with spaces" do
|
|
43
|
-
expect(acc.no_persist?(["--chef-license", "accept-no-persist"])).to eq(true)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns true if the args contain the required flag with equal" do
|
|
47
|
-
expect(acc.no_persist?(["--chef-license=accept-no-persist"])).to eq(true)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "returns false if the args do not contain the required value" do
|
|
51
|
-
expect(acc.no_persist?(["--chef-license"])).to eq(false)
|
|
52
|
-
expect(acc.no_persist?(["--chef-license=accept"])).to eq(false)
|
|
53
|
-
expect(acc.no_persist?(["--chef-license", "accept"])).to eq(false)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "license_acceptance/cli_flags/mixlib_cli"
|
|
3
|
-
|
|
4
|
-
class TestMixlibKlass
|
|
5
|
-
include Mixlib::CLI
|
|
6
|
-
include LicenseAcceptance::CLIFlags::MixlibCLI
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
RSpec.describe LicenseAcceptance::CLIFlags::MixlibCLI do
|
|
10
|
-
let(:klass) { TestMixlibKlass.new }
|
|
11
|
-
it "adds the correct command line flag" do
|
|
12
|
-
expect(klass.options).to include(:chef_license)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "license_acceptance/cli_flags/thor"
|
|
3
|
-
require "thor"
|
|
4
|
-
|
|
5
|
-
class TestThorKlass < Thor
|
|
6
|
-
include LicenseAcceptance::CLIFlags::Thor
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
RSpec.describe LicenseAcceptance::CLIFlags::Thor do
|
|
10
|
-
let(:klass) { TestThorKlass.new }
|
|
11
|
-
it "adds the correct command line flag" do
|
|
12
|
-
expect(klass.class.class_options.keys).to eq([:chef_license])
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "climate_control"
|
|
3
|
-
require "license_acceptance/config"
|
|
4
|
-
require "license_acceptance/product_relationship"
|
|
5
|
-
|
|
6
|
-
RSpec.describe LicenseAcceptance::Config do
|
|
7
|
-
let(:opts) { {} }
|
|
8
|
-
let(:config) { LicenseAcceptance::Config.new(opts) }
|
|
9
|
-
|
|
10
|
-
it "loads correctly with default values" do
|
|
11
|
-
config
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "with overwritten values" do
|
|
15
|
-
let(:output) { StringIO.new }
|
|
16
|
-
let(:logger) { "logger" }
|
|
17
|
-
let(:license_locations) { [] }
|
|
18
|
-
let(:persist_location) { "foo" }
|
|
19
|
-
let(:persist) { false }
|
|
20
|
-
let(:opts) { { output: output, logger: logger, license_locations: license_locations, persist_location: persist_location, persist: persist } }
|
|
21
|
-
|
|
22
|
-
it "loads correctly" do
|
|
23
|
-
expect(config.output).to eq(output)
|
|
24
|
-
expect(config.logger).to eq(logger)
|
|
25
|
-
expect(config.license_locations).to eq(license_locations)
|
|
26
|
-
expect(config.persist_location).to eq("foo")
|
|
27
|
-
expect(config.persist).to eq(false)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#default_license_locations and #default_persist_location" do
|
|
32
|
-
before do
|
|
33
|
-
expect(Process).to receive(:uid).and_return(uid)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe "when platform is Windows" do
|
|
37
|
-
before do
|
|
38
|
-
stub_const("RUBY_PLATFORM", "mingw")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe "when user is Administrator" do
|
|
42
|
-
let(:uid) { 0 }
|
|
43
|
-
|
|
44
|
-
it "returns the default value" do
|
|
45
|
-
ClimateControl.modify HOMEDRIVE: "C:" do
|
|
46
|
-
expect(config.license_locations).to eq(["C:/chef/accepted_licenses/"])
|
|
47
|
-
expect(config.persist_location).to eq("C:/chef/accepted_licenses/")
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe "when user is not Administrator" do
|
|
53
|
-
let(:uid) { 1000 }
|
|
54
|
-
|
|
55
|
-
it "returns the default USERPROFILE value" do
|
|
56
|
-
ClimateControl.modify HOMEDRIVE: "C:", USERPROFILE: "C:/Users/foo", HOME: nil do
|
|
57
|
-
expect(Dir).to receive(:exist?).with("C:/Users/foo").and_return(true)
|
|
58
|
-
expect(config.license_locations).to eq([
|
|
59
|
-
"C:/chef/accepted_licenses/",
|
|
60
|
-
"C:/Users/foo/.chef/accepted_licenses/"
|
|
61
|
-
])
|
|
62
|
-
expect(config.persist_location).to eq("C:/Users/foo/.chef/accepted_licenses/")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "returns the default HOMEDRIVE + HOMEPATH value" do
|
|
67
|
-
ClimateControl.modify HOMEDRIVE: "C:", USERPROFILE: "C:/Users/bar", HOME: nil do
|
|
68
|
-
expect(Dir).to receive(:exist?).with("C:/Users/bar").and_return(true)
|
|
69
|
-
expect(config.license_locations).to eq([
|
|
70
|
-
"C:/chef/accepted_licenses/",
|
|
71
|
-
"C:/Users/bar/.chef/accepted_licenses/"
|
|
72
|
-
])
|
|
73
|
-
expect(config.persist_location).to eq("C:/Users/bar/.chef/accepted_licenses/")
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe "when platform is non-Windows" do
|
|
81
|
-
before do
|
|
82
|
-
stub_const("RUBY_PLATFORM", "darwin")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe "when user is root" do
|
|
86
|
-
let(:uid) { 0 }
|
|
87
|
-
|
|
88
|
-
it "returns the default value" do
|
|
89
|
-
expect(config.license_locations).to eq(["/etc/chef/accepted_licenses/"])
|
|
90
|
-
expect(config.persist_location).to eq("/etc/chef/accepted_licenses/")
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
describe "when user is not root" do
|
|
95
|
-
let(:uid) { 1000 }
|
|
96
|
-
|
|
97
|
-
it "returns the default user value" do
|
|
98
|
-
ClimateControl.modify HOME: "/Users/foo" do
|
|
99
|
-
expect(config.license_locations).to eq([
|
|
100
|
-
"/etc/chef/accepted_licenses/",
|
|
101
|
-
"/Users/foo/.chef/accepted_licenses/"
|
|
102
|
-
])
|
|
103
|
-
expect(config.persist_location).to eq("/Users/foo/.chef/accepted_licenses/")
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
end
|