bundler-advise 1.0.0 → 1.0.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
  SHA1:
3
- metadata.gz: 87d25bc27eacc044d69d52b6fcf8d083368e9844
4
- data.tar.gz: 8646a541b6fdfd2dcb885ed5022be618dba86d1f
3
+ metadata.gz: eeda25d3d3de4dfbbc3068bbc557e30e3e4ee53a
4
+ data.tar.gz: 7530da925c37770508dc2287302d7c9c972e8068
5
5
  SHA512:
6
- metadata.gz: becf54f63bde517c9b5219167efb76b19317e232e94de7ce608a4c8e60f464bd19d8469909faab75f95defe128f2fd66ed16cb351265740a830fd46ecaab5e4c
7
- data.tar.gz: 750a49c7cb0f56c14a76fb85f16fe46e682760f19f578b832704074b248f91515201927c4ea5595e60c75ce0fdd0482b1c8e0f7100e3e675cfbd4b9d5412dc6e
6
+ metadata.gz: 6eeefba5041fcea4c9081f7050b34d94fb2110092f25d8cacacf31b65878930fe56d3925aea2275e118ac7c029c07b9a444aa4d0b65db45ee19215dc8c19a93f
7
+ data.tar.gz: af14055e3ed6337af33731cd431fe20425a445b066d827d6da643d0a5460639f3242e9cf5f7ec7a1414d94ff7ea6f10fc8f3c516ef9d6ef487d375b12e485dbf
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/chrismo/bundler-advise'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = `git ls-files -z`.split("\x0")
18
18
  spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Advise
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -0,0 +1,60 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Advisories do
4
+ context 'defaults' do
5
+ it 'should default to home dir' do
6
+ Advisories.new.dir.should == File.expand_path('~/.ruby-advisory-db')
7
+ end
8
+
9
+ it 'should default to rubysec ruby-advisory-db' do
10
+ Advisories.new.repo.should == 'git@github.com:rubysec/ruby-advisory-db.git'
11
+ end
12
+ end
13
+
14
+ context 'git clone/updates' do
15
+ before do
16
+ @a = Advisories.new(
17
+ dir: File.join(Dir.tmpdir, '.ruby-advisory-db'),
18
+ repo: 'git@github.com:chrismo/bundler-advise.git'
19
+ )
20
+ end
21
+
22
+ after do
23
+ FileUtils.rmtree @a.dir
24
+ end
25
+
26
+ it 'should clone if no copy exists' do
27
+ File.exist?(@a.dir).should_not be true
28
+ @a.update
29
+ File.exist?(@a.dir).should be true
30
+ File.exist?(File.join(@a.dir, '.git')).should be true
31
+ end
32
+
33
+ it 'should pull if working dir exists' do
34
+ File.exist?(@a.dir).should_not be true
35
+ @a.update
36
+ File.exist?(File.join(@a.dir, '.git')).should be true
37
+ @a.update
38
+ end
39
+
40
+ it 'should error handle messed up dir' do
41
+ FileUtils.makedirs @a.dir
42
+ lambda { @a.update }.should raise_error(/problem with working dir.*#{Regexp.escape(@a.dir)}/)
43
+ end
44
+
45
+ it 'should clean update a messed up dir' do
46
+ FileUtils.makedirs @a.dir
47
+ @a.clean_update!
48
+ File.exist?(File.join(@a.dir, '.git')).should be true
49
+ end
50
+ end
51
+
52
+ it 'should retrieve advisories for a gem' do
53
+ @a = Advisories.new(dir: fixture_dir)
54
+ ads = @a.gem_advisories_for('bar')
55
+ ads.length.should == 1
56
+ ad = ads.first
57
+ ad.gem.should == 'bar'
58
+ ad.patched_versions.should == [Gem::Requirement.create('>= 1.0.2')]
59
+ end
60
+ end
@@ -0,0 +1,61 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Advisory do
4
+ context 'persistence' do
5
+ it 'should parse the yummy yml' do
6
+ ad = Advisory.from_yml(File.join(fixture_dir, 'gems', 'bar', 'bar-1_0_1.yml'))
7
+ ad.id.should == 'bar-1_0_1'
8
+ ad.gem.should == 'bar'
9
+ ad.url.should == 'http://bar-gem-is-awesome.com'
10
+ ad.title.should == 'bar 1.0.1 might explode your spleen'
11
+ ad.date.should == DateTime.parse('2015-11-18')
12
+ ad.description.should == 'This version could, like, explode your spleen if taken internally'
13
+ ad.unaffected_versions.should == [Gem::Requirement.create('1.0.0')]
14
+ ad.patched_versions.should == [Gem::Requirement.create('>= 1.0.2')]
15
+ end
16
+
17
+ it 'should output back to yaml as hash' do
18
+ yml_fn = File.join(fixture_dir, 'gems', 'bar', 'bar-1_0_1.yml')
19
+ actual_yml = File.read(yml_fn)
20
+ ad = Advisory.from_yml(yml_fn)
21
+ ad.to_yaml.should == actual_yml
22
+ end
23
+ end
24
+
25
+ it 'should determine if patched' do
26
+ ad = Advisory.new(patched_versions: '>= 1.4.3')
27
+ ad.is_not_patched?('1.4.2').should be true
28
+ ad.is_not_patched?('1.4.3').should be false
29
+ ad.is_not_patched?('1.4.4').should be false
30
+
31
+ ad.is_affected?('1.4.2').should be true
32
+ ad.is_affected?('1.4.3').should be false
33
+ ad.is_affected?('1.4.4').should be false
34
+ end
35
+
36
+ it 'should determine if unaffected' do
37
+ ad = Advisory.new(unaffected_versions: '>= 1.4.3')
38
+ ad.is_not_unaffected?('1.4.2').should be true
39
+ ad.is_not_unaffected?('1.4.3').should be false
40
+ ad.is_not_unaffected?('1.4.4').should be false
41
+
42
+ ad.is_affected?('1.4.2').should be true
43
+ ad.is_affected?('1.4.3').should be false
44
+ ad.is_affected?('1.4.4').should be false
45
+ end
46
+
47
+ it 'should have sane defaults if patched and unaffected not specified' do
48
+ ad = Advisory.new
49
+ ad.is_not_unaffected?('1.4.2').should be true
50
+ ad.is_not_patched?('1.4.2').should be true
51
+ ad.is_affected?('1.4.2').should be true
52
+ end
53
+
54
+ it 'should work well if both specified' do
55
+ ad = Advisory.new(unaffected_versions: '< 1.3.0', patched_versions: '>= 1.4.3')
56
+ ad.is_affected?('1.2.0').should be false
57
+ ad.is_affected?('1.3.9').should be true
58
+ ad.is_affected?('1.4.2').should be true
59
+ ad.is_affected?('1.4.3').should be false
60
+ end
61
+ end
@@ -0,0 +1,64 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe GemAdviser do
4
+ before do
5
+ @bf = BundlerFixture.new
6
+ @bf.create_lockfile(gem_specs: [
7
+ @bf.create_spec('foo', '1.2.3', {'quux' => '~> 1.4'}),
8
+ @bf.create_spec('bar', '5.6'),
9
+ @bf.create_spec('quux', '1.4.3')
10
+ ])
11
+
12
+ @af = AdvisoriesFixture.new
13
+ end
14
+
15
+ def dump
16
+ puts File.read(File.join(@bf.dir, 'Gemfile.lock'))
17
+ end
18
+
19
+ after do
20
+ FileUtils.rmtree @af.clean_up
21
+ FileUtils.rmtree @bf.clean_up
22
+ end
23
+
24
+ it 'should find one matching advisories' do
25
+ @af.save_advisory(Advisory.new(gem: 'quux', patched_versions: '>= 1.4.5'))
26
+ ga = GemAdviser.new(dir: @bf.dir, advisories: Advisories.new(dir: @af.dir))
27
+ ga.scan_lockfile.map(&:gem).should == ['quux']
28
+ end
29
+
30
+ it 'should not find one non-matching advisories' do
31
+ @af.save_advisory(Advisory.new(gem: 'quux', patched_versions: '>= 1.4.2'))
32
+ ga = GemAdviser.new(dir: @bf.dir, advisories: Advisories.new(dir: @af.dir))
33
+ ga.scan_lockfile.map(&:gem).should be_empty
34
+ end
35
+
36
+ it 'should find one matching from many advisories' do
37
+ @af.save_advisory(Advisory.new(gem: 'quux', patched_versions: '>= 1.4.5'))
38
+ @af.save_advisory(Advisory.new(gem: 'quux', patched_versions: '>= 1.4.2'))
39
+ ga = GemAdviser.new(dir: @bf.dir, advisories: Advisories.new(dir: @af.dir))
40
+ ga.scan_lockfile.map(&:gem).should == ['quux']
41
+ end
42
+
43
+ it 'should find many matching from many advisories' do
44
+ @af.save_advisory(Advisory.new(gem: 'quux', date: '2014-01-12', patched_versions: '>= 1.4.5'))
45
+ @af.save_advisory(Advisory.new(gem: 'quux', date: '2014-01-13', patched_versions: '>= 1.4.4'))
46
+ ga = GemAdviser.new(dir: @bf.dir, advisories: Advisories.new(dir: @af.dir))
47
+ ga.scan_lockfile.map(&:date).should == ['2014-01-12', '2014-01-13']
48
+ end
49
+
50
+ it 'should find many gems matching from many advisories' do
51
+ @af.save_advisory(Advisory.new(gem: 'quux', patched_versions: '>= 1.4.5'))
52
+ @af.save_advisory(Advisory.new(gem: 'bar', patched_versions: '>= 6.0'))
53
+ ga = GemAdviser.new(dir: @bf.dir, advisories: Advisories.new(dir: @af.dir))
54
+ ga.scan_lockfile.map(&:gem).should == ['bar', 'quux']
55
+ end
56
+
57
+ it 'should skip matching but unaffected' do
58
+ @af.save_advisory(Advisory.new(gem: 'quux',
59
+ unaffected_versions: '~> 1.4.0',
60
+ patched_versions: '>= 1.6.0'))
61
+ ga = GemAdviser.new(dir: @bf.dir, advisories: Advisories.new(dir: @af.dir))
62
+ ga.scan_lockfile.map(&:gem).should be_empty
63
+ end
64
+ end
@@ -0,0 +1,20 @@
1
+ class AdvisoriesFixture
2
+ attr_reader :dir
3
+
4
+ def initialize
5
+ @dir = File.join(Dir.tmpdir, 'advisory_db')
6
+ FileUtils.makedirs @dir
7
+ end
8
+
9
+ def clean_up
10
+ FileUtils.rmtree @dir
11
+ end
12
+
13
+ def save_advisory(ad)
14
+ gem_path = File.join(@dir, 'gems', ad.gem)
15
+ FileUtils.makedirs gem_path
16
+ last_fn = Dir[File.join(gem_path, '*yml')].last || '000.yml'
17
+ next_fn = "#{File.basename(last_fn, '.yml').next}.yml"
18
+ File.open(File.join(gem_path, next_fn), 'wb') { |f| f.print ad.to_yaml }
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ class BundlerFixture
2
+ attr_reader :dir
3
+
4
+ def initialize
5
+ @dir = File.join(Dir.tmpdir, 'fake_project_root')
6
+ FileUtils.makedirs @dir
7
+ end
8
+
9
+ def clean_up
10
+ FileUtils.rmtree @dir
11
+ end
12
+
13
+ def create_lockfile(gem_specs:)
14
+ dir = @dir
15
+ index = Bundler::Index.new
16
+ deps = []
17
+ gem_specs.each do |g|
18
+ index << g
19
+ deps << Bundler::DepProxy.new(Bundler::Dependency.new(g.name, g.version), g.platform)
20
+ end
21
+ spec_set = Bundler::Resolver.resolve(deps, index)
22
+
23
+ sources = Bundler::SourceList.new
24
+ sources.add_rubygems_remote('https://rubygems.org')
25
+ spec_set.each { |s| s.source = sources.rubygems_sources.first }
26
+
27
+ gemfile_fn = File.join(dir, 'Gemfile.lock')
28
+ defn = Bundler::Definition.new(gemfile_fn, deps.map(&:dep), sources, true)
29
+ defn.instance_variable_set('@index', index)
30
+ defn.instance_variable_set('@resolve', spec_set)
31
+ defn.lock(gemfile_fn)
32
+ end
33
+
34
+ def create_spec(name, version, dependencies={})
35
+ Gem::Specification.new do |s|
36
+ s.name = name
37
+ s.version = Gem::Version.new(version)
38
+ s.platform = 'ruby'
39
+ dependencies.each do |name, requirement|
40
+ s.add_dependency name, requirement
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'bundler/advise'
3
+
4
+ include Bundler::Advise
5
+
6
+ RSpec.configure do |c|
7
+ c.expect_with(:rspec) { |co| co.syntax = :should }
8
+ end
9
+
10
+ require_relative 'fixture/advisories_fixture'
11
+ require_relative 'fixture/bundler_fixture'
12
+
13
+ def fixture_dir
14
+ File.expand_path('../fixture', __FILE__)
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-advise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrismo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-05 00:00:00.000000000 Z
11
+ date: 2016-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -103,6 +103,12 @@ files:
103
103
  - lib/bundler/advise/advisory.rb
104
104
  - lib/bundler/advise/gem_adviser.rb
105
105
  - lib/bundler/advise/version.rb
106
+ - spec/bundler/advisories_spec.rb
107
+ - spec/bundler/advisory_spec.rb
108
+ - spec/bundler/gem_adviser_spec.rb
109
+ - spec/fixture/advisories_fixture.rb
110
+ - spec/fixture/bundler_fixture.rb
111
+ - spec/spec_helper.rb
106
112
  homepage: https://github.com/chrismo/bundler-advise
107
113
  licenses:
108
114
  - MIT