mrjoy-bundler-audit 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +2 -0
  4. data/ChangeLog.md +10 -0
  5. data/Gemfile +1 -1
  6. data/Rakefile +12 -10
  7. data/lib/bundler/audit/cli.rb +3 -0
  8. data/lib/bundler/audit/database.rb +57 -24
  9. data/lib/bundler/audit/version.rb +1 -1
  10. data/mrjoy-bundler-audit.gemspec +0 -7
  11. data/spec/advisory_spec.rb +8 -3
  12. data/spec/bundle/insecure_sources/Gemfile.lock +98 -0
  13. data/spec/bundle/secure/Gemfile.lock +90 -0
  14. data/spec/bundle/unpatched_gems/Gemfile.lock +92 -0
  15. data/spec/bundle/wrapper.rb +36 -0
  16. data/spec/database_spec.rb +62 -42
  17. data/{data/ruby-advisory-db/gems/actionpack → spec/fixtures}/OSVDB-84243.yml +0 -0
  18. data/spec/integration_spec.rb +52 -14
  19. data/spec/spec_helper.rb +5 -45
  20. metadata +7 -104
  21. data/.gitmodules +0 -3
  22. data/data/ruby-advisory-db.ts +0 -1
  23. data/data/ruby-advisory-db/.gitignore +0 -1
  24. data/data/ruby-advisory-db/.rspec +0 -1
  25. data/data/ruby-advisory-db/CONTRIBUTING.md +0 -6
  26. data/data/ruby-advisory-db/CONTRIBUTORS.md +0 -24
  27. data/data/ruby-advisory-db/Gemfile +0 -3
  28. data/data/ruby-advisory-db/LICENSE.txt +0 -5
  29. data/data/ruby-advisory-db/README.md +0 -82
  30. data/data/ruby-advisory-db/Rakefile +0 -27
  31. data/data/ruby-advisory-db/gems/actionmailer/OSVDB-98629.yml +0 -17
  32. data/data/ruby-advisory-db/gems/actionpack/OSVDB-100524.yml +0 -20
  33. data/data/ruby-advisory-db/gems/actionpack/OSVDB-100525.yml +0 -21
  34. data/data/ruby-advisory-db/gems/actionpack/OSVDB-100526.yml +0 -27
  35. data/data/ruby-advisory-db/gems/actionpack/OSVDB-100527.yml +0 -24
  36. data/data/ruby-advisory-db/gems/actionpack/OSVDB-100528.yml +0 -22
  37. data/data/ruby-advisory-db/gems/actionpack/OSVDB-103439.yml +0 -24
  38. data/data/ruby-advisory-db/gems/actionpack/OSVDB-103440.yml +0 -22
  39. data/data/ruby-advisory-db/gems/actionpack/OSVDB-79727.yml +0 -26
  40. data/data/ruby-advisory-db/gems/actionpack/OSVDB-84513.yml +0 -23
  41. data/data/ruby-advisory-db/gems/actionpack/OSVDB-84515.yml +0 -26
  42. data/data/ruby-advisory-db/gems/actionpack/OSVDB-89026.yml +0 -24
  43. data/data/ruby-advisory-db/gems/actionpack/OSVDB-91452.yml +0 -20
  44. data/data/ruby-advisory-db/gems/actionpack/OSVDB-91454.yml +0 -23
  45. data/data/ruby-advisory-db/gems/activerecord/OSVDB-103438.yml +0 -23
  46. data/data/ruby-advisory-db/gems/activerecord/OSVDB-82403.yml +0 -25
  47. data/data/ruby-advisory-db/gems/activerecord/OSVDB-82610.yml +0 -24
  48. data/data/ruby-advisory-db/gems/activerecord/OSVDB-89025.yml +0 -24
  49. data/data/ruby-advisory-db/gems/activerecord/OSVDB-90072.yml +0 -21
  50. data/data/ruby-advisory-db/gems/activerecord/OSVDB-90073.yml +0 -23
  51. data/data/ruby-advisory-db/gems/activerecord/OSVDB-91453.yml +0 -26
  52. data/data/ruby-advisory-db/gems/activesupport/OSVDB-79726.yml +0 -26
  53. data/data/ruby-advisory-db/gems/activesupport/OSVDB-84516.yml +0 -23
  54. data/data/ruby-advisory-db/gems/activesupport/OSVDB-89594.yml +0 -25
  55. data/data/ruby-advisory-db/gems/activesupport/OSVDB-91451.yml +0 -28
  56. data/data/ruby-advisory-db/gems/arabic-prawn/OSVDB-104365.yml +0 -15
  57. data/data/ruby-advisory-db/gems/cocaine/OSVDB-98835.yml +0 -15
  58. data/data/ruby-advisory-db/gems/command_wrap/OSVDB-91450.yml +0 -10
  59. data/data/ruby-advisory-db/gems/crack/OSVDB-90742.yml +0 -17
  60. data/data/ruby-advisory-db/gems/cremefraiche/OSVDB-93395.yml +0 -11
  61. data/data/ruby-advisory-db/gems/curl/OSVDB-91230.yml +0 -12
  62. data/data/ruby-advisory-db/gems/devise/OSVDB-89642.yml +0 -20
  63. data/data/ruby-advisory-db/gems/dragonfly/OSVDB-90647.yml +0 -19
  64. data/data/ruby-advisory-db/gems/echor/OSVDB-102129.yml +0 -11
  65. data/data/ruby-advisory-db/gems/echor/OSVDB-102130.yml +0 -10
  66. data/data/ruby-advisory-db/gems/enum_column3/OSVDB-94679.yml +0 -9
  67. data/data/ruby-advisory-db/gems/extlib/OSVDB-90740.yml +0 -18
  68. data/data/ruby-advisory-db/gems/fastreader/OSVDB-91232.yml +0 -12
  69. data/data/ruby-advisory-db/gems/fileutils/OSVDB-90715.yml +0 -10
  70. data/data/ruby-advisory-db/gems/fileutils/OSVDB-90716.yml +0 -10
  71. data/data/ruby-advisory-db/gems/fileutils/OSVDB-90717.yml +0 -10
  72. data/data/ruby-advisory-db/gems/flash_tool/OSVDB-90829.yml +0 -9
  73. data/data/ruby-advisory-db/gems/fog-dragonfly/OSVDB-96798.yml +0 -13
  74. data/data/ruby-advisory-db/gems/ftpd/OSVDB-90784.yml +0 -18
  75. data/data/ruby-advisory-db/gems/gitlab-grit/OSVDB-99370.yml +0 -14
  76. data/data/ruby-advisory-db/gems/gtk2/OSVDB-40774.yml +0 -20
  77. data/data/ruby-advisory-db/gems/httparty/OSVDB-90741.yml +0 -14
  78. data/data/ruby-advisory-db/gems/i18n/OSVDB-100528.yml +0 -17
  79. data/data/ruby-advisory-db/gems/json/OSVDB-90074.yml +0 -23
  80. data/data/ruby-advisory-db/gems/karteek-docsplit/OSVDB-92117.yml +0 -10
  81. data/data/ruby-advisory-db/gems/kelredd-pruview/OSVDB-92228.yml +0 -10
  82. data/data/ruby-advisory-db/gems/ldoce/OSVDB-91870.yml +0 -10
  83. data/data/ruby-advisory-db/gems/loofah/OSVDB-90945.yml +0 -21
  84. data/data/ruby-advisory-db/gems/mail/OSVDB-70667.yml +0 -21
  85. data/data/ruby-advisory-db/gems/mail/OSVDB-81631.yml +0 -14
  86. data/data/ruby-advisory-db/gems/mail/OSVDB-81632.yml +0 -16
  87. data/data/ruby-advisory-db/gems/md2pdf/OSVDB-92290.yml +0 -10
  88. data/data/ruby-advisory-db/gems/mini_magick/OSVDB-91231.yml +0 -15
  89. data/data/ruby-advisory-db/gems/multi_xml/OSVDB-89148.yml +0 -16
  90. data/data/ruby-advisory-db/gems/newrelic_rpm/OSVDB-90189.yml +0 -17
  91. data/data/ruby-advisory-db/gems/nokogiri/OSVDB-101179.yml +0 -12
  92. data/data/ruby-advisory-db/gems/nokogiri/OSVDB-101458.yml +0 -15
  93. data/data/ruby-advisory-db/gems/nori/OSVDB-90196.yml +0 -19
  94. data/data/ruby-advisory-db/gems/omniauth-facebook/OSVDB-99693.yml +0 -22
  95. data/data/ruby-advisory-db/gems/omniauth-facebook/OSVDB-99888.yml +0 -17
  96. data/data/ruby-advisory-db/gems/omniauth-oauth2/OSVDB-90264.yml +0 -16
  97. data/data/ruby-advisory-db/gems/paperclip/OSVDB-103151.yml +0 -13
  98. data/data/ruby-advisory-db/gems/paratrooper-newrelic/OSVDB-101839.yml +0 -12
  99. data/data/ruby-advisory-db/gems/paratrooper-pingdom/OSVDB-101847.yml +0 -13
  100. data/data/ruby-advisory-db/gems/pdfkit/OSVDB-90867.yml +0 -11
  101. data/data/ruby-advisory-db/gems/rack-cache/OSVDB-83077.yml +0 -18
  102. data/data/ruby-advisory-db/gems/rack/OSVDB-89939.yml +0 -23
  103. data/data/ruby-advisory-db/gems/rbovirt/OSVDB-104080.yml +0 -20
  104. data/data/ruby-advisory-db/gems/rdoc/OSVDB-90004.yml +0 -27
  105. data/data/ruby-advisory-db/gems/redis-namespace/OSVDB-96425.yml +0 -16
  106. data/data/ruby-advisory-db/gems/rgpg/OSVDB-95948.yml +0 -14
  107. data/data/ruby-advisory-db/gems/ruby_parser/OSVDB-90561.yml +0 -11
  108. data/data/ruby-advisory-db/gems/sounder/OSVDB-96278.yml +0 -13
  109. data/data/ruby-advisory-db/gems/spree/OSVDB-91216.yml +0 -11
  110. data/data/ruby-advisory-db/gems/spree/OSVDB-91217.yml +0 -11
  111. data/data/ruby-advisory-db/gems/spree/OSVDB-91218.yml +0 -11
  112. data/data/ruby-advisory-db/gems/spree/OSVDB-91219.yml +0 -11
  113. data/data/ruby-advisory-db/gems/sprout/OSVDB-100598.yml +0 -14
  114. data/data/ruby-advisory-db/gems/thumbshooter/OSVDB-91839.yml +0 -10
  115. data/data/ruby-advisory-db/gems/webbynode/OSVDB-100920.yml +0 -11
  116. data/data/ruby-advisory-db/gems/wicked/OSVDB-98270.yml +0 -14
  117. data/data/ruby-advisory-db/gems/will_paginate/OSVDB-101138.yml +0 -15
  118. data/data/ruby-advisory-db/lib/scrape.rb +0 -87
  119. data/data/ruby-advisory-db/spec/advisory_example.rb +0 -165
  120. data/data/ruby-advisory-db/spec/gems_spec.rb +0 -7
  121. data/data/ruby-advisory-db/spec/spec_helper.rb +0 -1
@@ -0,0 +1,92 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.10)
5
+ actionpack (= 3.2.10)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.10)
8
+ activemodel (= 3.2.10)
9
+ activesupport (= 3.2.10)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.10)
18
+ activesupport (= 3.2.10)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.10)
21
+ activemodel (= 3.2.10)
22
+ activesupport (= 3.2.10)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.10)
26
+ activemodel (= 3.2.10)
27
+ activesupport (= 3.2.10)
28
+ activesupport (3.2.10)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.3)
32
+ builder (3.0.4)
33
+ erubis (2.7.0)
34
+ hike (1.2.3)
35
+ i18n (0.6.9)
36
+ journey (1.0.4)
37
+ jquery-rails (3.1.0)
38
+ railties (>= 3.0, < 5.0)
39
+ thor (>= 0.14, < 2.0)
40
+ json (1.8.1)
41
+ mail (2.4.4)
42
+ i18n (>= 0.4.0)
43
+ mime-types (~> 1.16)
44
+ treetop (~> 1.4.8)
45
+ mime-types (1.25.1)
46
+ multi_json (1.9.2)
47
+ polyglot (0.3.4)
48
+ rack (1.4.5)
49
+ rack-cache (1.2)
50
+ rack (>= 0.4)
51
+ rack-ssl (1.3.4)
52
+ rack
53
+ rack-test (0.6.2)
54
+ rack (>= 1.0)
55
+ rails (3.2.10)
56
+ actionmailer (= 3.2.10)
57
+ actionpack (= 3.2.10)
58
+ activerecord (= 3.2.10)
59
+ activeresource (= 3.2.10)
60
+ activesupport (= 3.2.10)
61
+ bundler (~> 1.0)
62
+ railties (= 3.2.10)
63
+ railties (3.2.10)
64
+ actionpack (= 3.2.10)
65
+ activesupport (= 3.2.10)
66
+ rack-ssl (~> 1.3.2)
67
+ rake (>= 0.8.7)
68
+ rdoc (~> 3.4)
69
+ thor (>= 0.14.6, < 2.0)
70
+ rake (10.3.0)
71
+ rdoc (3.12.2)
72
+ json (~> 1.4)
73
+ sprockets (2.2.2)
74
+ hike (~> 1.2)
75
+ multi_json (~> 1.0)
76
+ rack (~> 1.0)
77
+ tilt (~> 1.1, != 1.3.0)
78
+ sqlite3 (1.3.9)
79
+ thor (0.19.1)
80
+ tilt (1.4.1)
81
+ treetop (1.4.15)
82
+ polyglot
83
+ polyglot (>= 0.3.1)
84
+ tzinfo (0.3.39)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ jquery-rails
91
+ rails (= 3.2.10)
92
+ sqlite3
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ version = RUBY_VERSION.split(/\./).map(&:to_i)
6
+ if((version[0] == 1 && version[1] >= 9) || (version[0] >= 2))
7
+ require 'simplecov'
8
+ require 'json'
9
+
10
+ # Be silent so we don't muck up test runs that look at output.
11
+ class NullFormatter; def format(result); ""; end; end
12
+ SimpleCov.formatter = NullFormatter
13
+
14
+ # Use the project-level root despite executing in a sub-dir of it.
15
+ SimpleCov.root(File.expand_path('../../..', __FILE__))
16
+
17
+ SimpleCov.start do
18
+ # Being in a sub-dir may cause us some filtering issues...
19
+ filters.clear
20
+ add_filter do |src|
21
+ !(src.filename =~ /^#{SimpleCov.root}/)
22
+ end
23
+ command_name "RSpec/#{ENV["SIMPLECOV_COMMAND_NAME"]}"
24
+ end
25
+ end
26
+ root_dir = File.expand_path('../../..', __FILE__)
27
+ $LOAD_PATH << root_dir unless $LOAD_PATH.include?(root_dir)
28
+ lib_dir = File.join(root_dir, 'lib')
29
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
30
+
31
+ require 'tmpdir'
32
+ require 'bundler/audit/database'
33
+ Bundler::Audit::Database.path = Dir.mktmpdir('ruby-advisory-db')
34
+ Bundler::Audit::Database.update!
35
+
36
+ load 'bin/bundle-audit'
@@ -4,46 +4,37 @@ require 'tmpdir'
4
4
  require 'rake/file_list'
5
5
 
6
6
  describe Bundler::Audit::Database do
7
- let(:vendored_advisories) do
8
- Rake::FileList[File.join(Bundler::Audit::Database::VENDORED_PATH, '**/*.yml')].sort
9
- end
7
+ describe "update!" do
8
+ context "when PATH does not exist yet" do
9
+ before do
10
+ FileUtils.rm_rf(described_class.path)
11
+ end
10
12
 
11
- describe "path" do
12
- subject { described_class.path }
13
+ it "should create the path as needed" do
14
+ described_class.update!
13
15
 
14
- it "it should be a directory" do
15
- File.directory?(subject).should be_true
16
+ expect(File.directory?(described_class.path)).to be_true
17
+ end
16
18
  end
17
19
 
18
- it "should prefer the user repo, iff it's as up to date, or more up to date than the vendored one" do
19
- Bundler::Audit::Database.update!
20
+ context "when PATH does exist" do
21
+ before(:all) do
22
+ @t1 = Dir.chdir(described_class.path) do
23
+ system 'git', 'reset', '--hard', 'HEAD^1'
20
24
 
21
- # As up to date...
22
- expect(Bundler::Audit::Database.path).to eq mocked_user_path
23
-
24
- # More up to date...
25
- fake_a_commit_in_the_user_repo
26
- expect(Bundler::Audit::Database.path).to eq mocked_user_path
27
-
28
- roll_user_repo_back(2)
29
- expect(Bundler::Audit::Database.path).to eq Bundler::Audit::Database::VENDORED_PATH
30
- end
31
- end
25
+ Time.parse(`git log -1 --format=%ad`)
26
+ end
32
27
 
33
- describe "update!" do
34
- it "should create the USER_PATH path as needed" do
35
- Bundler::Audit::Database.update!
36
- expect(File.directory?(mocked_user_path)).to be true
37
- end
28
+ described_class.update!
38
29
 
39
- it "should create the repo, then update it given multple successive calls." do
40
- expect_update_to_clone_repo!
41
- Bundler::Audit::Database.update!
42
- expect(File.directory?(mocked_user_path)).to be true
30
+ @t2 = Dir.chdir(described_class.path) do
31
+ Time.parse(`git log -1 --format=%ad`)
32
+ end
33
+ end
43
34
 
44
- expect_update_to_update_repo!
45
- Bundler::Audit::Database.update!
46
- expect(File.directory?(mocked_user_path)).to be true
35
+ it "should update the git repository" do
36
+ expect(@t2).to be > @t1
37
+ end
47
38
  end
48
39
  end
49
40
 
@@ -51,8 +42,8 @@ describe Bundler::Audit::Database do
51
42
  context "when given no arguments" do
52
43
  subject { described_class.new }
53
44
 
54
- it "should default path to path" do
55
- subject.path.should == described_class.path
45
+ it "should set path to the default path" do
46
+ expect(subject.path).to be == described_class.path
56
47
  end
57
48
  end
58
49
 
@@ -75,6 +66,36 @@ describe Bundler::Audit::Database do
75
66
  end
76
67
  end
77
68
 
69
+ describe "#update!" do
70
+ before do
71
+ @t1 = Dir.chdir(subject.path) do
72
+ system 'git', 'reset', '--hard', 'HEAD^1'
73
+
74
+ Time.parse(`git log -1 --format=%ad`)
75
+ end
76
+
77
+ described_class.update!
78
+
79
+ @t2 = Dir.chdir(subject.path) do
80
+ Time.parse(`git log -1 --format=%ad`)
81
+ end
82
+ end
83
+
84
+ it "should update the git repository" do
85
+ expect(@t2).to be > @t1
86
+ end
87
+ end
88
+
89
+ describe "#last_updated" do
90
+ let(:timestamp) do
91
+ Dir.chdir(subject.path) { Time.parse(`git log -1 --format=%ad`) }
92
+ end
93
+
94
+ it "should return the time of the last update" do
95
+ expect(subject.last_updated).to be == timestamp
96
+ end
97
+ end
98
+
78
99
  describe "#check_gem" do
79
100
  let(:gem) do
80
101
  Gem::Specification.new do |s|
@@ -106,17 +127,16 @@ describe Bundler::Audit::Database do
106
127
  end
107
128
 
108
129
  describe "#size" do
109
- it { expect(subject.size).to eq vendored_advisories.count }
130
+ it "should return > 0" do
131
+ expect(subject.size).to be > 0
132
+ end
110
133
  end
111
134
 
112
135
  describe "#advisories" do
113
- it "should return a list of all advisories." do
114
- actual_advisories = Bundler::Audit::Database.new.
115
- advisories.
116
- map(&:path).
117
- sort
136
+ let(:glob) { File.join(subject.path,'gems','*','*.yml') }
118
137
 
119
- expect(actual_advisories).to eq vendored_advisories
138
+ it "should return a list of all advisories" do
139
+ expect(subject.advisories.map(&:path)).to eq Dir[glob]
120
140
  end
121
141
  end
122
142
 
@@ -128,7 +148,7 @@ describe Bundler::Audit::Database do
128
148
 
129
149
  describe "#inspect" do
130
150
  it "should produce a Ruby-ish instance descriptor" do
131
- expect(Bundler::Audit::Database.new.inspect).to eq("#<Bundler::Audit::Database:#{Bundler::Audit::Database::VENDORED_PATH}>")
151
+ expect(subject.inspect).to eq("#<Bundler::Audit::Database:#{subject.path}>")
132
152
  end
133
153
  end
134
154
  end
@@ -4,23 +4,24 @@ describe "CLI" do
4
4
  include Helpers
5
5
 
6
6
  let(:command) do
7
- File.expand_path(File.join(File.dirname(__FILE__),'..','bin','bundle-audit'))
7
+ File.expand_path('../bundle/wrapper.rb', __FILE__)
8
8
  end
9
9
 
10
10
  context "when auditing a bundle with unpatched gems" do
11
11
  let(:bundle) { 'unpatched_gems' }
12
12
  let(:directory) { File.join('spec','bundle',bundle) }
13
13
 
14
- subject do
15
- Dir.chdir(directory) { sh(command, :fail => true) }
16
- end
14
+ context "in default display mode" do
15
+ subject do
16
+ Dir.chdir(directory) { sh(command, :fail => true) }
17
+ end
17
18
 
18
- it "should print a warning" do
19
- subject.should include("Unpatched versions found!")
20
- end
19
+ it "should print a warning" do
20
+ subject.should include("Unpatched versions found!")
21
+ end
21
22
 
22
- it "should print advisory information for the vulnerable gems" do
23
- advisory_pattern = /(Name: [^\n]+
23
+ it "should print advisory information for the vulnerable gems" do
24
+ advisory_pattern = /(Name: [^\n]+
24
25
  Version: \d+.\d+.\d+
25
26
  Advisory: OSVDB-\d+
26
27
  Criticality: (High|Medium)
@@ -28,8 +29,34 @@ URL: http:\/\/(direct|www\.)?osvdb.org\/show\/osvdb\/\d+
28
29
  Title: [^\n]*?
29
30
  Solution: upgrade to ((~>|=>) \d+.\d+.\d+, )*(~>|=>) \d+.\d+.\d+[\s\n]*?)+/
30
31
 
31
- expect(subject).to match(advisory_pattern)
32
- expect(subject).to include("Unpatched versions found!")
32
+ expect(subject).to match(advisory_pattern)
33
+ expect(subject).to include("Unpatched versions found!")
34
+ end
35
+ end
36
+
37
+ context "in verbose display mode" do
38
+ subject do
39
+ Dir.chdir(directory) { sh(command + " --verbose", :fail => true) }
40
+ end
41
+
42
+ it "should print a warning" do
43
+ subject.should include("Unpatched versions found!")
44
+ end
45
+
46
+ it "should print advisory information for the vulnerable gems" do
47
+ advisory_pattern = /(Name: [^\n]+
48
+ Version: \d+.\d+.\d+
49
+ Advisory: OSVDB-\d+
50
+ Criticality: (High|Medium)
51
+ URL: http:\/\/(direct|www\.)?osvdb.org\/show\/osvdb\/\d+
52
+ Description:
53
+
54
+ (( .*?)?\n)+
55
+ Solution: upgrade to ((~>|=>) \d+.\d+.\d+, )*(~>|=>) \d+.\d+.\d+[\s\n]*?)+/
56
+
57
+ expect(subject).to match(advisory_pattern)
58
+ expect(subject).to include("Unpatched versions found!")
59
+ end
33
60
  end
34
61
  end
35
62
 
@@ -38,7 +65,7 @@ Solution: upgrade to ((~>|=>) \d+.\d+.\d+, )*(~>|=>) \d+.\d+.\d+[\s\n]*?)+/
38
65
  let(:directory) { File.join('spec','bundle',bundle) }
39
66
 
40
67
  let(:command) do
41
- File.expand_path(File.join(File.dirname(__FILE__),'..','bin','bundle-audit -i OSVDB-89026'))
68
+ File.expand_path('../bundle/wrapper.rb', __FILE__) + " -i OSVDB-89026"
42
69
  end
43
70
 
44
71
  subject do
@@ -70,12 +97,23 @@ Insecure Source URI found: http://rubygems.org/
70
97
  let(:bundle) { 'secure' }
71
98
  let(:directory) { File.join('spec','bundle',bundle) }
72
99
 
100
+ # Skip this test on any Ruby below 1.9.3.
101
+ version = RUBY_VERSION.split(/\./).map(&:to_i)
102
+ if((version[0] == 1 && version[1] >= 9 && version[2] >= 3) || (version[0] >= 2))
73
103
  subject do
74
104
  Dir.chdir(directory) { sh(command) }
75
105
  end
76
106
 
77
- it "should print nothing when everything is fine" do
78
- subject.strip.should == "No unpatched versions found"
107
+ it "should notify us properly when everything is fine" do
108
+ # We check the end of the output because a DB install/update "may" (
109
+ # _will_, in the case of the test but _may_ in the real world) have been
110
+ # performed.
111
+ subject.strip.should =~ /No unpatched versions found\Z/
79
112
  end
113
+ else
114
+ it "should notify us properly when everything is fine" do
115
+ pending "Requires ActiveSupport 4.x, which requires Ruby >= 1.9.3."
116
+ end
117
+ end
80
118
  end
81
119
  end
data/spec/spec_helper.rb CHANGED
@@ -10,12 +10,14 @@ if((version[0] == 1 && version[1] >= 9) || (version[0] >= 2))
10
10
  end
11
11
 
12
12
  require 'rspec'
13
+ require 'tmpdir'
13
14
  require 'bundler/audit'
14
15
  require 'bundler/audit/version'
15
16
 
16
17
  module Helpers
17
18
  def sh(command, options={})
18
19
  Bundler.with_clean_env do
20
+ ENV["SIMPLECOV_COMMAND_NAME"] = example.full_description
19
21
  result = `#{command} 2>&1`
20
22
  raise "FAILED #{command}\n#{result}" if $?.success? == !!options[:fail]
21
23
  result
@@ -25,56 +27,14 @@ module Helpers
25
27
  def decolorize(string)
26
28
  string.gsub(/\e\[\d+m/, "")
27
29
  end
28
-
29
- def executable
30
- File.expand_path(File.join('..','..','bin','bundle-audit'), __FILE__)
31
- end
32
-
33
- def audit_in_directory(additions, directory, options={})
34
- Dir.chdir(directory) { decolorize(sh([executable, additions].compact.join(' '), options)) }
35
- end
36
-
37
- def mocked_user_path
38
- File.expand_path('../../tmp/data', __FILE__)
39
- end
40
-
41
- def expect_update_to_clone_repo!
42
- Bundler::Audit::Database.
43
- should_receive(:system).
44
- with('git', 'clone', Bundler::Audit::Database::VENDORED_PATH, mocked_user_path).
45
- and_call_original
46
- end
47
-
48
- def expect_update_to_update_repo!
49
- Bundler::Audit::Database.
50
- should_receive(:system).
51
- with('git', 'pull', 'origin', 'master').
52
- and_call_original
53
- end
54
-
55
- def fake_a_commit_in_the_user_repo
56
- Dir.chdir(mocked_user_path) do
57
- system 'git', 'commit', '--allow-empty', '-m', 'Dummy commit.'
58
- end
59
- end
60
-
61
- def roll_user_repo_back(num_commits)
62
- Dir.chdir(mocked_user_path) do
63
- system 'git', 'checkout', "HEAD~#{num_commits}"
64
- system 'git', 'branch', '-f', 'master', 'HEAD'
65
- system 'git', 'checkout', 'master'
66
- end
67
- end
68
30
  end
69
31
 
70
32
  include Bundler::Audit
71
33
 
72
34
  RSpec.configure do |config|
73
- include Helpers
35
+ config.include Helpers
74
36
 
75
- config.before(:each) do
76
- stub_const("Bundler::Audit::Database::URL", Bundler::Audit::Database::VENDORED_PATH)
77
- stub_const("Bundler::Audit::Database::USER_PATH", mocked_user_path)
78
- FileUtils.rm_rf mocked_user_path if(File.exist?(mocked_user_path))
37
+ config.before(:suite) do
38
+ Database.path = Dir.mktmpdir('ruby-advisory-db')
79
39
  end
80
40
  end