ironment 0.0.2 → 0.0.3
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.lock +1 -1
- data/ironment.gemspec +3 -0
- data/lib/ironment/cl/prompter.rb +71 -0
- data/lib/ironment/cl.rb +58 -0
- data/lib/ironment/version.rb +1 -1
- data/test/cl_test.rb +88 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc254aacbfe4d2411b4c30629dac7770dbf59173
|
4
|
+
data.tar.gz: 6c2dcf22af8f1b0f23177234097d229457dd44c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0bc96529255775d6f2d4efb3d5cc9d6b955592397f552ec3891985710d5868807ea4085f30610e5295526b9d7bfe267bdcd0b9f9d130f9f1a3bf4f75ffe1260
|
7
|
+
data.tar.gz: 85cdf56a2e82fe5e908b69f9c9271d061b7fac432e644a9e3c543f87c787b7b79b451d4b5ce06365f4bf16258104eeb5c9eabf5baecf57a38c8cd63459e1e170
|
data/Gemfile.lock
CHANGED
data/ironment.gemspec
CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
bin/iron
|
26
26
|
ironment.gemspec
|
27
27
|
lib/ironment.rb
|
28
|
+
lib/ironment/cl.rb
|
29
|
+
lib/ironment/cl/prompter.rb
|
28
30
|
lib/ironment/config.rb
|
29
31
|
lib/ironment/executor.rb
|
30
32
|
lib/ironment/finder.rb
|
@@ -32,6 +34,7 @@ Gem::Specification.new do |s|
|
|
32
34
|
lib/ironment/runcom.rb
|
33
35
|
lib/ironment/truster.rb
|
34
36
|
lib/ironment/version.rb
|
37
|
+
test/cl_test.rb
|
35
38
|
test/config_test.rb
|
36
39
|
test/finder_test.rb
|
37
40
|
test/ironment_test.rb
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Ironment
|
2
|
+
class CL
|
3
|
+
class Prompter
|
4
|
+
def initialize(options = {})
|
5
|
+
@in = options[:in] || $stdin
|
6
|
+
@out = options[:out] || $stdout
|
7
|
+
@truster = options[:truster] || Truster.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def not_trusted(runcom)
|
11
|
+
prompt_not_trusted(runcom)
|
12
|
+
request_user_action(runcom)
|
13
|
+
end
|
14
|
+
|
15
|
+
def modified(runcom)
|
16
|
+
prompt_modified(runcom)
|
17
|
+
request_user_action(runcom)
|
18
|
+
end
|
19
|
+
|
20
|
+
def request_user_action(runcom)
|
21
|
+
prompt_question
|
22
|
+
|
23
|
+
case @in.gets.strip.to_sym
|
24
|
+
when :y
|
25
|
+
@truster.trust(runcom)
|
26
|
+
true
|
27
|
+
when :v
|
28
|
+
prompt_content(runcom)
|
29
|
+
request_user_action(runcom)
|
30
|
+
when :n
|
31
|
+
false
|
32
|
+
else
|
33
|
+
request_user_action(runcom)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def prompt_not_trusted(runcom)
|
40
|
+
@out.write <<-PROMPT
|
41
|
+
Ironment has encountered a new and untrusted .envrc file. This
|
42
|
+
may contain untrusted content and should be examined manually.
|
43
|
+
|
44
|
+
#{runcom.file} (#{runcom.sha1sum})
|
45
|
+
|
46
|
+
PROMPT
|
47
|
+
end
|
48
|
+
|
49
|
+
def prompt_modified(runcom)
|
50
|
+
@out.write <<-PROMPT
|
51
|
+
Ironment has encountered a trusted, but modified .envrc file. This
|
52
|
+
may contain untrusted content and should be examined manually.
|
53
|
+
|
54
|
+
#{runcom.file} (#{runcom.sha1sum})
|
55
|
+
|
56
|
+
PROMPT
|
57
|
+
end
|
58
|
+
|
59
|
+
def prompt_question
|
60
|
+
@out.write <<-PROMPT.gsub(/\n$/, "")
|
61
|
+
Do you wish to trust this .envrc file?
|
62
|
+
y[es], n[o], v[iew]>
|
63
|
+
PROMPT
|
64
|
+
end
|
65
|
+
|
66
|
+
def prompt_content(runcom)
|
67
|
+
@out.write "\n#{runcom.content.gsub(/^/, " ")}\n"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/ironment/cl.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class Ironment
|
2
|
+
class CL
|
3
|
+
def initialize(options = {})
|
4
|
+
@ironment = options[:ironment] || Ironment.new
|
5
|
+
@prompter = options[:prompter] || Prompter.new
|
6
|
+
@truster = options[:truster] || Truster.new
|
7
|
+
@stderr = options[:stderr] || $stderr
|
8
|
+
end
|
9
|
+
|
10
|
+
def exec_with_environment(command, *args)
|
11
|
+
@ironment.exec_with_environment command, *args
|
12
|
+
rescue Truster::NotTrusted => e
|
13
|
+
if @prompter.not_trusted e.runcom
|
14
|
+
exec_with_environment command, *args
|
15
|
+
end
|
16
|
+
rescue Truster::Modified => e
|
17
|
+
if @prompter.modified e.runcom
|
18
|
+
exec_with_environment command, *args
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def trust(file)
|
23
|
+
@truster.trust Runcom.new(file)
|
24
|
+
|
25
|
+
true
|
26
|
+
rescue Errno::EACCES
|
27
|
+
@stderr.puts "ironment: Permission denied"
|
28
|
+
|
29
|
+
false
|
30
|
+
rescue Errno::ENOENT
|
31
|
+
@stderr.puts "ironment: No such file or directory"
|
32
|
+
|
33
|
+
false
|
34
|
+
rescue Errno::EISDIR
|
35
|
+
@stderr.puts "ironment: Is a directory"
|
36
|
+
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
def untrust(file)
|
41
|
+
@truster.untrust Runcom.new(file)
|
42
|
+
|
43
|
+
true
|
44
|
+
rescue Errno::EACCES
|
45
|
+
@stderr.puts "ironment: Permission denied"
|
46
|
+
|
47
|
+
false
|
48
|
+
rescue Errno::ENOENT
|
49
|
+
@stderr.puts "ironment: No such file or directory"
|
50
|
+
|
51
|
+
false
|
52
|
+
rescue Errno::EISDIR
|
53
|
+
@stderr.puts "ironment: Is a directory"
|
54
|
+
|
55
|
+
false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/ironment/version.rb
CHANGED
data/test/cl_test.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
def test_exception_handling(exception, method, message)
|
5
|
+
truster = Object.new
|
6
|
+
|
7
|
+
truster.define_singleton_method method do |*|
|
8
|
+
raise exception
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "upon receiving #{exception.inspect}" do
|
12
|
+
it "should return false" do
|
13
|
+
result = Ironment::CL.new(truster: truster, stderr: StringIO.new).send(method, ".envrc")
|
14
|
+
|
15
|
+
assert_equal false, result
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should write #{message.inspect} to :stderr" do
|
19
|
+
stderr = StringIO.new
|
20
|
+
|
21
|
+
Ironment::CL.new(truster: truster, stderr: stderr).send(method, ".envrc")
|
22
|
+
|
23
|
+
assert_includes stderr.string, message
|
24
|
+
end
|
25
|
+
|
26
|
+
it ":stderr should end with a newline" do
|
27
|
+
stderr = StringIO.new
|
28
|
+
|
29
|
+
Ironment::CL.new(truster: truster, stderr: stderr).send(method, ".envrc")
|
30
|
+
|
31
|
+
assert_equal "\n", stderr.string[-1]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Ironment::CL do
|
37
|
+
describe "#trust" do
|
38
|
+
describe "when succesfully trusting a file" do
|
39
|
+
it "should return true" do
|
40
|
+
truster = Minitest::Mock.new
|
41
|
+
truster.expect :trust, true, [Ironment::Runcom.new(".envrc")]
|
42
|
+
|
43
|
+
assert_equal true, Ironment::CL.new(truster: truster).trust(".envrc")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not write to :stderr" do
|
47
|
+
truster = Minitest::Mock.new
|
48
|
+
truster.expect :trust, true, [Ironment::Runcom.new(".envrc")]
|
49
|
+
|
50
|
+
stderr = StringIO.new
|
51
|
+
|
52
|
+
Ironment::CL.new(truster: truster, stderr: stderr).trust(".envrc")
|
53
|
+
|
54
|
+
assert_equal "", stderr.string
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
test_exception_handling Errno::EACCES, :trust, "ironment: Permission denied"
|
59
|
+
test_exception_handling Errno::ENOENT, :trust, "ironment: No such file or directory"
|
60
|
+
test_exception_handling Errno::EISDIR, :trust, "ironment: Is a directory"
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#untrust" do
|
64
|
+
describe "when succesfully untrusting a file" do
|
65
|
+
it "should return true" do
|
66
|
+
truster = Minitest::Mock.new
|
67
|
+
truster.expect :untrust, true, [Ironment::Runcom.new(".envrc")]
|
68
|
+
|
69
|
+
assert_equal true, Ironment::CL.new(truster: truster).untrust(".envrc")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not write to :stderr" do
|
73
|
+
truster = Minitest::Mock.new
|
74
|
+
truster.expect :untrust, true, [Ironment::Runcom.new(".envrc")]
|
75
|
+
|
76
|
+
stderr = StringIO.new
|
77
|
+
|
78
|
+
Ironment::CL.new(truster: truster, stderr: stderr).untrust(".envrc")
|
79
|
+
|
80
|
+
assert_equal "", stderr.string
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test_exception_handling Errno::EACCES, :untrust, "ironment: Permission denied"
|
85
|
+
test_exception_handling Errno::ENOENT, :untrust, "ironment: No such file or directory"
|
86
|
+
test_exception_handling Errno::EISDIR, :untrust, "ironment: Is a directory"
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ironment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Amundsen
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- bin/iron
|
98
98
|
- ironment.gemspec
|
99
99
|
- lib/ironment.rb
|
100
|
+
- lib/ironment/cl.rb
|
101
|
+
- lib/ironment/cl/prompter.rb
|
100
102
|
- lib/ironment/config.rb
|
101
103
|
- lib/ironment/executor.rb
|
102
104
|
- lib/ironment/finder.rb
|
@@ -104,6 +106,7 @@ files:
|
|
104
106
|
- lib/ironment/runcom.rb
|
105
107
|
- lib/ironment/truster.rb
|
106
108
|
- lib/ironment/version.rb
|
109
|
+
- test/cl_test.rb
|
107
110
|
- test/config_test.rb
|
108
111
|
- test/finder_test.rb
|
109
112
|
- test/ironment_test.rb
|