cucumber-create-meta 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cucumber/create_meta.rb +40 -28
- data/spec/capture_warnings.rb +74 -0
- data/spec/cucumber/remove_userinfo_from_url_spec.rb +29 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a4f36daf37f233cc900ef6e7e9b962dc8109d1054faecf1de72e532a59335ff
|
4
|
+
data.tar.gz: 0c1fe89598d1eedb5914ac7f8fea417a03c59f6a5b901ef503542fb7695ea675
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7141737ea7d22b1bc7e78f282c0e589eb4c12fc9bfc793b99f75efe69119e5392beb2660d3ce87839e553b917c5a47967777db5eb26cb3ab40740b9dd328cb91
|
7
|
+
data.tar.gz: 7aa043622a0c97318e8abe92941e41a82071e3fecae213962e7a99c437d4bd16dfb34bd4e7b7d71e98788bcbf66da11242002d5bff094682e936cc396a879a10
|
data/lib/cucumber/create_meta.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
+
require 'uri'
|
1
2
|
require 'cucumber/messages'
|
2
3
|
require 'sys/uname'
|
3
4
|
require 'json'
|
4
5
|
|
5
6
|
module Cucumber
|
6
7
|
module CreateMeta
|
7
|
-
CI_DICT = JSON.parse(IO.read(File.join(File.dirname(__FILE__),"ciDict.json")))
|
8
|
+
CI_DICT = JSON.parse(IO.read(File.join(File.dirname(__FILE__), "ciDict.json")))
|
8
9
|
|
9
|
-
def create_meta(tool_name, tool_version, env=ENV)
|
10
|
+
def create_meta(tool_name, tool_version, env = ENV)
|
10
11
|
Cucumber::Messages::Meta.new(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
12
|
+
protocol_version: Cucumber::Messages::VERSION,
|
13
|
+
implementation: Cucumber::Messages::Meta::Product.new(
|
14
|
+
name: tool_name,
|
15
|
+
version: tool_version
|
16
|
+
),
|
17
|
+
runtime: Cucumber::Messages::Meta::Product.new(
|
18
|
+
name: RUBY_ENGINE,
|
19
|
+
version: RUBY_VERSION
|
20
|
+
),
|
21
|
+
os: Cucumber::Messages::Meta::Product.new(
|
22
|
+
name: RbConfig::CONFIG['target_os'],
|
23
|
+
version: Sys::Uname.uname.version
|
24
|
+
),
|
25
|
+
cpu: Cucumber::Messages::Meta::Product.new(
|
26
|
+
name: RbConfig::CONFIG['target_cpu']
|
27
|
+
),
|
28
|
+
ci: detect_ci(env)
|
28
29
|
)
|
29
30
|
end
|
30
31
|
|
@@ -41,14 +42,14 @@ module Cucumber
|
|
41
42
|
return nil if url.nil?
|
42
43
|
|
43
44
|
Cucumber::Messages::Meta::CI.new(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
url: url,
|
46
|
+
name: ci_name,
|
47
|
+
git: Cucumber::Messages::Meta::CI::Git.new(
|
48
|
+
remote: remove_userinfo_from_url(evaluate(ci_system['git']['remote'], env)),
|
49
|
+
revision: evaluate(ci_system['git']['revision'], env),
|
50
|
+
branch: evaluate(ci_system['git']['branch'], env),
|
51
|
+
tag: evaluate(ci_system['git']['tag'], env),
|
52
|
+
)
|
52
53
|
)
|
53
54
|
end
|
54
55
|
|
@@ -80,6 +81,17 @@ module Cucumber
|
|
80
81
|
m[1]
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
def remove_userinfo_from_url(value)
|
85
|
+
return nil if value.nil?
|
86
|
+
begin
|
87
|
+
uri = URI(value)
|
88
|
+
uri.userinfo = ''
|
89
|
+
uri.to_s
|
90
|
+
rescue
|
91
|
+
value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
module_function :create_meta, :detect_ci, :create_ci, :group1, :evaluate, :remove_userinfo_from_url
|
84
96
|
end
|
85
97
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# With thanks to @myronmarston
|
3
|
+
# https://github.com/vcr/vcr/blob/master/spec/capture_warnings.rb
|
4
|
+
|
5
|
+
module CaptureWarnings
|
6
|
+
def report_warnings(&block)
|
7
|
+
current_dir = Dir.pwd
|
8
|
+
warnings, errors = capture_error(&block).partition { |line| line.include?('warning') }
|
9
|
+
project_warnings, other_warnings = warnings.uniq.partition { |line| line.include?(current_dir) }
|
10
|
+
|
11
|
+
if errors.any?
|
12
|
+
puts errors.join("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
if other_warnings.any?
|
16
|
+
puts "#{ other_warnings.count } warnings detected, set VIEW_OTHER_WARNINGS=true to see them."
|
17
|
+
print_warnings('other', other_warnings) if ENV['VIEW_OTHER_WARNINGS']
|
18
|
+
end
|
19
|
+
|
20
|
+
# Until they fix https://bugs.ruby-lang.org/issues/10661
|
21
|
+
if RUBY_VERSION == "2.2.0"
|
22
|
+
project_warnings = project_warnings.reject { |w| w =~ /warning: possible reference to past scope/ }
|
23
|
+
end
|
24
|
+
|
25
|
+
if project_warnings.any?
|
26
|
+
puts "#{ project_warnings.count } warnings detected"
|
27
|
+
print_warnings('cucumber-expressions', project_warnings)
|
28
|
+
fail "Please remove all cucumber-expressions warnings."
|
29
|
+
end
|
30
|
+
|
31
|
+
ensure_system_exit_if_required
|
32
|
+
end
|
33
|
+
|
34
|
+
def capture_error(&block)
|
35
|
+
old_stderr = STDERR.clone
|
36
|
+
pipe_r, pipe_w = IO.pipe
|
37
|
+
pipe_r.sync = true
|
38
|
+
error = String.new
|
39
|
+
reader = Thread.new do
|
40
|
+
begin
|
41
|
+
loop do
|
42
|
+
error << pipe_r.readpartial(1024)
|
43
|
+
end
|
44
|
+
rescue EOFError
|
45
|
+
end
|
46
|
+
end
|
47
|
+
STDERR.reopen(pipe_w)
|
48
|
+
block.call
|
49
|
+
ensure
|
50
|
+
capture_system_exit
|
51
|
+
STDERR.reopen(old_stderr)
|
52
|
+
pipe_w.close
|
53
|
+
reader.join
|
54
|
+
return error.split("\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
def print_warnings(type, warnings)
|
58
|
+
puts
|
59
|
+
puts "-" * 30 + " #{type} warnings: " + "-" * 30
|
60
|
+
puts
|
61
|
+
puts warnings.join("\n")
|
62
|
+
puts
|
63
|
+
puts "-" * 75
|
64
|
+
puts
|
65
|
+
end
|
66
|
+
|
67
|
+
def ensure_system_exit_if_required
|
68
|
+
raise @system_exit if @system_exit
|
69
|
+
end
|
70
|
+
|
71
|
+
def capture_system_exit
|
72
|
+
@system_exit = $!
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'cucumber/create_meta'
|
2
|
+
|
3
|
+
describe 'remove_user_info_from_url' do
|
4
|
+
it 'returns nil for nil' do
|
5
|
+
expect(Cucumber::CreateMeta.remove_userinfo_from_url(nil)).to be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'returns empty string for empty string' do
|
9
|
+
expect(Cucumber::CreateMeta.remove_userinfo_from_url('')).to eq('')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'leaves the data intact when no sensitive information is detected' do
|
13
|
+
expect(Cucumber::CreateMeta.remove_userinfo_from_url('pretty safe')).to eq('pretty safe')
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with URLs' do
|
17
|
+
it 'leaves intact when no password is found' do
|
18
|
+
expect(Cucumber::CreateMeta.remove_userinfo_from_url('https://example.com/git/repo.git')).to eq('https://example.com/git/repo.git')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'removes credentials when found' do
|
22
|
+
expect(Cucumber::CreateMeta.remove_userinfo_from_url('http://login@example.com/git/repo.git')).to eq('http://example.com/git/repo.git')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'removes credentials and passwords when found' do
|
26
|
+
expect(Cucumber::CreateMeta.remove_userinfo_from_url('ssh://login:password@example.com/git/repo.git')).to eq('ssh://example.com/git/repo.git')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-create-meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Prêtre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber-messages
|
@@ -99,7 +99,9 @@ files:
|
|
99
99
|
- LICENSE
|
100
100
|
- lib/cucumber/ciDict.json
|
101
101
|
- lib/cucumber/create_meta.rb
|
102
|
+
- spec/capture_warnings.rb
|
102
103
|
- spec/cucumber/create_meta_spec.rb
|
104
|
+
- spec/cucumber/remove_userinfo_from_url_spec.rb
|
103
105
|
homepage: https://github.com/cucumber/create-meta-ruby
|
104
106
|
licenses:
|
105
107
|
- MIT
|
@@ -128,6 +130,8 @@ requirements: []
|
|
128
130
|
rubygems_version: 3.1.2
|
129
131
|
signing_key:
|
130
132
|
specification_version: 4
|
131
|
-
summary: cucumber-create-meta-2.0.
|
133
|
+
summary: cucumber-create-meta-2.0.2
|
132
134
|
test_files:
|
133
135
|
- spec/cucumber/create_meta_spec.rb
|
136
|
+
- spec/cucumber/remove_userinfo_from_url_spec.rb
|
137
|
+
- spec/capture_warnings.rb
|