danger-logging_lint 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +148 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +170 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +25 -0
- data/danger-logging_lint.gemspec +50 -0
- data/lib/danger_logging_lint.rb +3 -0
- data/lib/danger_plugin.rb +3 -0
- data/lib/logging_lint/gem_version.rb +5 -0
- data/lib/logging_lint/plugin.rb +297 -0
- data/spec/fixtures/IgnoredModifiedFile.txt +112 -0
- data/spec/fixtures/ModifiedFile.kt +112 -0
- data/spec/fixtures/NewFile.kt +78 -0
- data/spec/logging_lint_spec.rb +132 -0
- data/spec/spec_helper.rb +67 -0
- metadata +209 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("spec_helper", __dir__)
|
4
|
+
|
5
|
+
module Danger
|
6
|
+
describe Danger::DangerLoggingLint do
|
7
|
+
it "should be a plugin" do
|
8
|
+
expect(Danger::DangerLoggingLint.new(nil)).to be_a Danger::Plugin
|
9
|
+
end
|
10
|
+
|
11
|
+
dir_name = File.dirname(__FILE__)
|
12
|
+
modified_files = %W(#{dir_name}/fixtures/ModifiedFile.kt #{dir_name}/fixtures/IgnoredModifiedFile.txt)
|
13
|
+
added_files = %W(#{dir_name}/fixtures/NewFile.kt)
|
14
|
+
warning_text = "Does this log comply with security rules?"
|
15
|
+
|
16
|
+
#
|
17
|
+
# Defines linter, danger file and other variables used by the linter.
|
18
|
+
#
|
19
|
+
describe "with Dangerfile" do
|
20
|
+
before do
|
21
|
+
@dangerfile = testing_dangerfile
|
22
|
+
@logging_lint = @dangerfile.logging_lint
|
23
|
+
|
24
|
+
allow(@logging_lint.git).to receive(:deleted_files).and_return([])
|
25
|
+
allow(@logging_lint.git).to receive(:added_files).and_return([])
|
26
|
+
allow(@logging_lint.git).to receive(:modified_files).and_return([])
|
27
|
+
allow(@logging_lint).to receive(:file_extensions).and_return(%w(kt))
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Test for logging lines in cases when linter does not run (either by config or file settings).
|
32
|
+
#
|
33
|
+
|
34
|
+
it "Error is printed when log functions are not configured" do
|
35
|
+
allow(@logging_lint).to receive(:log_functions).and_return([])
|
36
|
+
@logging_lint.log_lint
|
37
|
+
expect(@dangerfile.status_report[:errors]).to eq(["No log functions are defined. Please check your Danger file."])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Error is printed when log variable regex is not configured" do
|
41
|
+
allow(@logging_lint).to receive(:line_variable_regex).and_return([])
|
42
|
+
@logging_lint.log_lint
|
43
|
+
expect(@dangerfile.status_report[:messages][0]).to eq("At least one variable index must be defined (using default). Please check your Danger file.")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "Nothing is printed when there are no files to check" do
|
47
|
+
@logging_lint.log_lint
|
48
|
+
expect(@dangerfile.status_report[:errors]).to eq([])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "Nothing is printed when there are no files to check (filtered by extensions)" do
|
52
|
+
allow(@logging_lint.git).to receive(:modified_files).and_return(modified_files)
|
53
|
+
allow(@logging_lint).to receive(:file_extensions).and_return(%w(unknownExtension))
|
54
|
+
@logging_lint.log_lint
|
55
|
+
expect(@dangerfile.status_report[:errors]).to eq([])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "Nothing is printed when log levels are not present" do
|
59
|
+
allow(@logging_lint).to receive(:log_functions).and_return(%w(missingLogLevel))
|
60
|
+
@logging_lint.log_lint
|
61
|
+
expect(@dangerfile.status_report[:warnings]).to eq([])
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Test for logging lines in cases when linter does run.
|
66
|
+
#
|
67
|
+
|
68
|
+
it "Log with variables is warned for modified files (end line index)" do
|
69
|
+
allow(@logging_lint.git).to receive(:modified_files).and_return(modified_files)
|
70
|
+
allow(@logging_lint).to receive(:line_index_position).and_return("end")
|
71
|
+
@logging_lint.log_lint
|
72
|
+
violation_lines = [63, 64, 73, 76, 88, 92, 97, 98, 101, 106, 107, 110]
|
73
|
+
compare_warning_with_lines(violation_lines)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "Log with variables is warned for modified files (start line index)" do
|
77
|
+
allow(@logging_lint.git).to receive(:modified_files).and_return(modified_files)
|
78
|
+
allow(@logging_lint).to receive(:line_index_position).and_return("start")
|
79
|
+
@logging_lint.log_lint
|
80
|
+
violation_lines = [63, 64, 71, 74, 85, 89, 93, 98, 99, 102, 107, 108]
|
81
|
+
compare_warning_with_lines(violation_lines)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "Log with variables is warned for modified files (middle line index)" do
|
85
|
+
allow(@logging_lint.git).to receive(:modified_files).and_return(modified_files)
|
86
|
+
allow(@logging_lint).to receive(:line_index_position).and_return("middle")
|
87
|
+
@logging_lint.log_lint
|
88
|
+
violation_lines = [63, 64, 73, 76, 88, 92, 97, 98, 101, 106, 107, 110]
|
89
|
+
compare_warning_with_lines(violation_lines)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "Log with variables is warned for new files" do
|
93
|
+
allow(@logging_lint.git).to receive(:added_files).and_return(added_files)
|
94
|
+
@logging_lint.log_lint
|
95
|
+
violation_lines = [47, 48, 57, 60, 72, 76]
|
96
|
+
compare_warning_with_lines(violation_lines)
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Test for waning texts and links.
|
101
|
+
#
|
102
|
+
|
103
|
+
it "Log with variables is warned with link address" do
|
104
|
+
warning_link = "http://error.io"
|
105
|
+
allow(@logging_lint.git).to receive(:added_files).and_return(added_files)
|
106
|
+
allow(@logging_lint).to receive(:warning_description).and_return(warning_link)
|
107
|
+
@logging_lint.log_lint
|
108
|
+
expect(@dangerfile.status_report[:warnings][0]).to eq("#{warning_text} Check: #{warning_link}")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "Log with variables is warned without link address" do
|
112
|
+
allow(@logging_lint.git).to receive(:added_files).and_return(added_files)
|
113
|
+
@logging_lint.log_lint
|
114
|
+
expect(@dangerfile.status_report[:warnings][0]).to eq(warning_text)
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Compares violation lines against danger warning lines. It expects them to be equal.
|
119
|
+
#
|
120
|
+
def compare_warning_with_lines(violation_lines)
|
121
|
+
warnings = @dangerfile.status_report[:warnings]
|
122
|
+
warning_lines = []
|
123
|
+
warnings.each_with_index do |value, index|
|
124
|
+
if index > 0 && (index + 1) % 4 == 0
|
125
|
+
warning_lines << value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
expect(warning_lines).to eq(violation_lines)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
ROOT = Pathname.new(File.expand_path("..", __dir__))
|
5
|
+
$:.unshift("#{ROOT}lib".to_s)
|
6
|
+
$:.unshift("#{ROOT}spec".to_s)
|
7
|
+
|
8
|
+
require "bundler/setup"
|
9
|
+
require "pry"
|
10
|
+
|
11
|
+
require "rspec"
|
12
|
+
require "danger"
|
13
|
+
|
14
|
+
if `git remote -v` == ""
|
15
|
+
puts "You cannot run tests without setting a local git remote on this repo"
|
16
|
+
puts "It's a weird side-effect of Danger's internals."
|
17
|
+
exit(0)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Use coloured output, it's the best.
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.filter_gems_from_backtrace "bundler"
|
23
|
+
config.color = true
|
24
|
+
config.tty = true
|
25
|
+
end
|
26
|
+
|
27
|
+
require "danger_plugin"
|
28
|
+
|
29
|
+
# These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
|
30
|
+
# If you are expanding these files, see if it's already been done ^.
|
31
|
+
|
32
|
+
# A silent version of the user interface,
|
33
|
+
# it comes with an extra function `.string` which will
|
34
|
+
# strip all ANSI colours from the string.
|
35
|
+
|
36
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
37
|
+
def testing_ui
|
38
|
+
@output = StringIO.new
|
39
|
+
def @output.winsize
|
40
|
+
[20, 9999]
|
41
|
+
end
|
42
|
+
|
43
|
+
cork = Cork::Board.new(out: @output)
|
44
|
+
def cork.string
|
45
|
+
out.string.gsub(/\e\[([;\d]+)?m/, "")
|
46
|
+
end
|
47
|
+
cork
|
48
|
+
end
|
49
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
50
|
+
|
51
|
+
# Example environment (ENV) that would come from
|
52
|
+
# running a PR on TravisCI
|
53
|
+
def testing_env
|
54
|
+
{
|
55
|
+
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
|
56
|
+
"TRAVIS_PULL_REQUEST" => "800",
|
57
|
+
"TRAVIS_REPO_SLUG" => "artsy/eigen",
|
58
|
+
"TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
|
59
|
+
"DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
# A stubbed out Dangerfile for use in tests
|
64
|
+
def testing_dangerfile
|
65
|
+
env = Danger::EnvironmentManager.new(testing_env)
|
66
|
+
Danger::Dangerfile.new(env, testing_ui)
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danger-logging_lint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Sucharda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: danger-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.14'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.14'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.7'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.7'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: listen
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.0.7
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.0.7
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: Checks logging commands in code.
|
154
|
+
email:
|
155
|
+
- david.sucharda@eman.cz
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rubocop.yml"
|
162
|
+
- ".travis.yml"
|
163
|
+
- Gemfile
|
164
|
+
- Gemfile.lock
|
165
|
+
- Guardfile
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- danger-logging_lint.gemspec
|
170
|
+
- lib/danger_logging_lint.rb
|
171
|
+
- lib/danger_plugin.rb
|
172
|
+
- lib/logging_lint/gem_version.rb
|
173
|
+
- lib/logging_lint/plugin.rb
|
174
|
+
- spec/fixtures/IgnoredModifiedFile.txt
|
175
|
+
- spec/fixtures/ModifiedFile.kt
|
176
|
+
- spec/fixtures/NewFile.kt
|
177
|
+
- spec/logging_lint_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
homepage: https://github.com/eManPrague/danger-logging_lint
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata: {}
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubygems_version: 3.1.2
|
199
|
+
signing_key:
|
200
|
+
specification_version: 4
|
201
|
+
summary: Logging might be a security issue that is why this plugin checks files for
|
202
|
+
new/changed logs with variables that might be a security issue and warns them using
|
203
|
+
Danger.
|
204
|
+
test_files:
|
205
|
+
- spec/fixtures/IgnoredModifiedFile.txt
|
206
|
+
- spec/fixtures/ModifiedFile.kt
|
207
|
+
- spec/fixtures/NewFile.kt
|
208
|
+
- spec/logging_lint_spec.rb
|
209
|
+
- spec/spec_helper.rb
|