Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate lockfile parsing from vulnerability scanning #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/bundler/audit/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with bundler-audit. If not, see <http://www.gnu.org/licenses/>.
#

require 'bundler/audit/scanner'
require 'bundler/audit/file_scanner'
require 'bundler/audit/version'

require 'thor'
Expand All @@ -38,7 +38,7 @@ class CLI < ::Thor
def check
update if options[:update]

scanner = Scanner.new
scanner = FileScanner.new
vulnerable = false

scanner.scan(:ignore => options.ignore) do |result|
Expand Down
26 changes: 26 additions & 0 deletions lib/bundler/audit/file_scanner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'bundler/audit/scanner'

module Bundler
module Audit
class FileScanner < Scanner

# Project root directory
attr_reader :root

#
# Initializes a file scanner.
#
# @param [String] root
# The path to the project root.
#
# @param [String] gemfile_lock
# Alternative name for the `Gemfile.lock` file.
#
def initialize(root=Dir.pwd,gemfile_lock='Gemfile.lock')
@root = File.expand_path(root)
super(LockfileParser.new(File.read(File.join(@root,gemfile_lock))))
end
end
end
end

17 changes: 4 additions & 13 deletions lib/bundler/audit/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Scanner
# @return [Database]
attr_reader :database

# Project root directory
attr_reader :root

# The parsed `Gemfile.lock` from the project
#
# @return [Bundler::LockfileParser]
Expand All @@ -33,18 +30,12 @@ class Scanner
#
# Initializes a scanner.
#
# @param [String] root
# The path to the project root.
#
# @param [String] gemfile_lock
# Alternative name for the `Gemfile.lock` file.
# @param [Bunder::LockfileParser] lockfile
# A parsed lockfile.
#
def initialize(root=Dir.pwd,gemfile_lock='Gemfile.lock')
@root = File.expand_path(root)
def initialize(lockfile)
@database = Database.new
@lockfile = LockfileParser.new(
File.read(File.join(@root,gemfile_lock))
)
@lockfile = lockfile
end

#
Expand Down
4 changes: 2 additions & 2 deletions spec/scanner_spec.rb → spec/file_scanner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'bundler/audit/scanner'
require 'bundler/audit/file_scanner'

describe Scanner do
describe FileScanner do
describe "#scan" do
let(:bundle) { 'unpatched_gems' }
let(:directory) { File.join('spec','bundle',bundle) }
Expand Down