gem-compare 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '096fabc998369169bf705a75200c474ba447d3c356fe315b41e43de604cfb083'
|
4
|
+
data.tar.gz: d23ba898f4d201e2e02c83662c3e333b3c3b8a33ab0b4e6bc698a8acc24c0cde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c8ab50db4a790a4af27bd2ed8fe19ffc463a24af0f17e30be05d84cc4b1f2a57d9b02e0650dd6c963d088676c464985577783b92e20c2d819b44dcb3ac3f581
|
7
|
+
data.tar.gz: 9814f8ef072e89b299bb5ff3d952ad2247b79867b61328b6e6f50af653ee5128560a5cb271517d1073d888b5022b79fb20228d3c18bcbf94243922da628ee6c5
|
@@ -47,7 +47,7 @@ class Gem::Comparator
|
|
47
47
|
curr_permissions = File.stat(curr_file).mode
|
48
48
|
|
49
49
|
diff = prev_permissions ^ curr_permissions
|
50
|
-
diff ^= 020 if ignore_group_writable
|
50
|
+
diff ^= 020 if diff != 0 && ignore_group_writable
|
51
51
|
|
52
52
|
if diff != 0
|
53
53
|
" (!) New permissions: " +
|
@@ -59,13 +59,21 @@ class Gem::Comparator
|
|
59
59
|
|
60
60
|
def self.new_file_permissions(file, ignore_group_writable=false)
|
61
61
|
file_permissions = File.stat(file).mode
|
62
|
-
formatted_file_permissions = format_permissions(file_permissions)
|
63
62
|
|
64
|
-
|
63
|
+
expected_permissions = if DirUtils.gem_bin_file?(file)
|
64
|
+
0100755
|
65
|
+
else
|
66
|
+
0100644
|
67
|
+
end
|
68
|
+
|
69
|
+
permissions_to_compare = if ignore_group_writable && file_permissions != expected_permissions
|
70
|
+
file_permissions ^ 020
|
71
|
+
else
|
72
|
+
file_permissions
|
73
|
+
end
|
65
74
|
|
66
|
-
unless
|
67
|
-
|
68
|
-
return " (!) Unexpected permissions: #{formatted_file_permissions}"
|
75
|
+
unless permissions_to_compare == expected_permissions
|
76
|
+
return " (!) Unexpected permissions: #{format_permissions(file_permissions)}"
|
69
77
|
end
|
70
78
|
''
|
71
79
|
end
|
@@ -9,9 +9,10 @@ class TestFileListComparator < TestGemComparator
|
|
9
9
|
assert_equal [], @report['files']['0.0.1->0.0.2']['deleted'].messages
|
10
10
|
assert_equal [], @report['files']['0.0.1->0.0.2']['updated'].messages
|
11
11
|
assert_equal "bin/lorem +3/-0", @report['files']['0.0.2->0.0.3']['added'].lines(1)
|
12
|
-
assert_equal "(!)
|
13
|
-
assert_equal "(!)
|
14
|
-
assert_equal "
|
12
|
+
assert_equal "(!) Unexpected permissions: 100664", @report['files']['0.0.2->0.0.3']['added'].lines(2).strip
|
13
|
+
assert_equal "(!) File is not executable", @report['files']['0.0.2->0.0.3']['added'].lines(3).strip
|
14
|
+
assert_equal "(!) Shebang found: #!/usr/bin/ruby", @report['files']['0.0.2->0.0.3']['added'].lines(4).strip
|
15
|
+
assert_equal "lib/lorem/utils.rb +7/-0", @report['files']['0.0.2->0.0.3']['added'].lines(5).strip
|
15
16
|
assert_nil @report['files']['0.0.2->0.0.3']['added'].lines(6)
|
16
17
|
assert_equal [], @report['files']['0.0.2->0.0.3']['deleted'].messages
|
17
18
|
assert_equal [], @report['files']['0.0.2->0.0.3']['updated'].messages
|
@@ -49,6 +49,21 @@ class TestMonitor < TestGemModule
|
|
49
49
|
file1 = File.join(@v003, 'bin/lorem')
|
50
50
|
file2 = File.join(@v004, 'bin/lorem')
|
51
51
|
assert_equal '(!) New permissions: 100664 -> 100775', Gem::Comparator::Monitor.files_permissions_changes(file1, file2).strip
|
52
|
+
assert_equal '(!) New permissions: 100664 -> 100775', Gem::Comparator::Monitor.files_permissions_changes(file1, file2, true).strip
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_files_permissions_changes_no_change
|
56
|
+
file1 = Tempfile.new
|
57
|
+
file2 = Tempfile.new
|
58
|
+
begin
|
59
|
+
File.chmod(0644, file1)
|
60
|
+
File.chmod(0644, file2)
|
61
|
+
assert_equal '', Gem::Comparator::Monitor.files_permissions_changes(file1.path, file2.path)
|
62
|
+
assert_equal '', Gem::Comparator::Monitor.files_permissions_changes(file1.path, file2.path, true)
|
63
|
+
ensure
|
64
|
+
file1.unlink
|
65
|
+
file2.unlink
|
66
|
+
end
|
52
67
|
end
|
53
68
|
|
54
69
|
def test_files_permissions_changes_ignores_group_writable_added
|
@@ -94,16 +109,39 @@ class TestMonitor < TestGemModule
|
|
94
109
|
file1 = File.join(@v004, 'bin/lorem')
|
95
110
|
file2 = File.join(@v004, 'lib/lorem.rb')
|
96
111
|
assert_equal '(!) Unexpected permissions: 100775', Gem::Comparator::Monitor.new_file_permissions(file1).strip
|
97
|
-
assert_equal '(!) Unexpected permissions: 100664', Gem::Comparator::Monitor.new_file_permissions(file2).strip
|
112
|
+
assert_equal '(!) Unexpected permissions: 100664', Gem::Comparator::Monitor.new_file_permissions(file2).strip
|
113
|
+
ignore_group_writable = true
|
114
|
+
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(file1, ignore_group_writable).strip
|
115
|
+
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(file2, ignore_group_writable).strip
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_new_file_permissions_ignore_group_writable_when_not_group_writable
|
119
|
+
file = Tempfile.new
|
120
|
+
bin_file = temp_bin_file
|
121
|
+
begin
|
122
|
+
File.chmod(0644, file)
|
123
|
+
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(file.path, true)
|
124
|
+
|
125
|
+
File.chmod(0755, bin_file)
|
126
|
+
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(bin_file.path, true)
|
127
|
+
ensure
|
128
|
+
file.unlink
|
129
|
+
bin_file.unlink
|
130
|
+
end
|
98
131
|
end
|
99
132
|
|
100
133
|
def test_new_file_permissions_ignore_group_writable
|
101
134
|
file = Tempfile.new
|
135
|
+
bin_file = temp_bin_file
|
102
136
|
begin
|
103
137
|
File.chmod(0664, file)
|
104
|
-
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(file, true)
|
138
|
+
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(file.path, true)
|
139
|
+
|
140
|
+
File.chmod(0775, bin_file)
|
141
|
+
assert_equal '', Gem::Comparator::Monitor.new_file_permissions(bin_file.path, true)
|
105
142
|
ensure
|
106
143
|
file.unlink
|
144
|
+
bin_file.unlink
|
107
145
|
end
|
108
146
|
end
|
109
147
|
|
data/test/test_helper.rb
CHANGED
@@ -11,6 +11,12 @@ def setup_file_permissions
|
|
11
11
|
File.chmod(0775, File.join(gemfiles_path, 'lorem-0.0.4', 'bin', 'lorem'))
|
12
12
|
end
|
13
13
|
|
14
|
+
def temp_bin_file
|
15
|
+
bin_dir = File.join(Dir.mktmpdir, "bin")
|
16
|
+
Dir.mkdir(bin_dir)
|
17
|
+
Tempfile.new("", bin_dir)
|
18
|
+
end
|
19
|
+
|
14
20
|
class TestGemComparator < Minitest::Test
|
15
21
|
def setup
|
16
22
|
super
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-compare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josef Stribny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|