Rakefile in dawnscanner-1.2.99 vs Rakefile in dawnscanner-1.3.0

- old
+ new

@@ -4,12 +4,12 @@ require 'cucumber' require 'cucumber/rake/task' require 'fileutils' -require "codesake/dawn/utils" -require "codesake/dawn/knowledge_base" +require "dawn/utils" +require "dawn/knowledge_base" Cucumber::Rake::Task.new(:features) do |t| t.cucumber_opts = "features --format pretty -x" t.fork = false end @@ -31,14 +31,14 @@ # end desc "Create a new CVE test" task :cve, :name do |t,args| name = args.name - SRC_DIR = "./lib/codesake/dawn/kb/" + SRC_DIR = "./lib/dawn/kb/" SPEC_DIR = "./spec/lib/kb/" - raise "### It seems that #{name} is already in Dawn knowledge base" unless Codesake::Dawn::KnowledgeBase.find(nil, name).nil? + raise "### It seems that #{name} is already in Dawn knowledge base" unless Dawn::KnowledgeBase.find(nil, name).nil? raise "### Invalid CVE title: #{name}" if name.nil? or name.empty? or /CVE-\d{4}-\d{4}/.match(name).nil? raise "### No target directory: #{SRC_DIR}" unless Dir.exists?(SRC_DIR) raise "### No rspec directory: #{SPEC_DIR}" unless Dir.exists?(SPEC_DIR) puts "Adding #{name} to knowledge base..." @@ -46,12 +46,11 @@ rb_filename = SRC_DIR+name.downcase.gsub("-", "_")+".rb" spec_filename = SPEC_DIR+name.downcase.gsub("-", "_")+"_spec.rb" class_name = name.gsub("-", "_") open(rb_filename, "w") do |file| - file.puts "module Codesake" - file.puts "\tmodule Dawn" + file.puts "module Dawn" file.puts "\t\tmodule Kb" file.puts "\t\t\t# Automatically created with rake on #{Time.now.strftime('%Y-%m-%d')}" file.puts "\t\t\tclass #{class_name}" file.puts "\t\t\t\t# Include the testing skeleton for this CVE" file.puts "\t\t\t\t# include PatternMatchCheck" @@ -60,61 +59,59 @@ file.puts "" file.puts "\t\t\t\tdef initialize" file.puts "\t\t\t\tend" file.puts "\t\t\tend" file.puts "\t\tend" - file.puts "\tend" file.puts "end" end puts "#{rb_filename} created" open(spec_filename, "w") do |file| file.puts "require 'spec_helper'" file.puts "describe \"The #{name} vulnerability\" do" file.puts "\tbefore(:all) do" - file.puts "\t\t@check = Codesake::Dawn::Kb::#{class_name}.new" + file.puts "\t\t@check = Dawn::Kb::#{class_name}.new" file.puts "\t\t# @check.debug = true" file.puts "\tend" file.puts "\tit \"is reported when...\"" file.puts "end" end puts "#{spec_filename} created" - puts "*** PLEASE IMPLEMENT TEST FOR #{name} IN spec/lib/dawn/codesake_knowledgebase_spec.rb in order to reflect changes" - puts "*** PLEASE ADD THIS CODE IN lib/codesake/dawn/knowledge_base.rb in order to reflect changes" - puts "require \"codesake/dawn/kb/#{class_name.downcase}\"" + puts "*** PLEASE IMPLEMENT TEST FOR #{name} IN spec/lib/dawn/knowledgebase_spec.rb in order to reflect changes" + puts "*** PLEASE ADD THIS CODE IN lib/dawn/knowledge_base.rb in order to reflect changes" + puts "require \"dawn/kb/#{class_name.downcase}\"" puts "it \"must have test for #{name}\" do" puts " sc = kb.find(\"#{name}\")" puts " sc.should_not be_nil" - puts " sc.class.should == Codesake::Dawn::Kb::#{class_name}" + puts " sc.class.should == Dawn::Kb::#{class_name}" puts "end" end desc "Create a new Generic security check" task :check, :name do |t,args| name = args.name - SRC_DIR = "./lib/codesake/dawn/kb/" + SRC_DIR = "./lib/dawn/kb/" SPEC_DIR = "./spec/lib/kb/" - raise "### It seems that #{name} is already in Dawn knowledge base" unless Codesake::Dawn::KnowledgeBase.find(nil, name).nil? + raise "### It seems that #{name} is already in Dawn knowledge base" unless Dawn::KnowledgeBase.find(nil, name).nil? raise "### No target directory: #{SRC_DIR}" unless Dir.exists?(SRC_DIR) raise "### No rspec directory: #{SPEC_DIR}" unless Dir.exists?(SPEC_DIR) puts "Adding #{name} to knowledge base..." rb_filename = SRC_DIR+name.downcase.gsub("-", "_")+".rb" spec_filename = SPEC_DIR+name.downcase.gsub("-", "_")+"_spec.rb" class_name = name.gsub("-", "_") open(rb_filename, "w") do |file| - file.puts "module Codesake" - file.puts "\tmodule Dawn" + file.puts "module Dawn" file.puts "\t\tmodule Kb" file.puts "\t\t\t# Automatically created with rake on #{Time.now.strftime('%Y-%m-%d')}" file.puts "\t\t\tclass #{class_name}" file.puts "\t\t\t\t# Include the testing skeleton for this Security Check" file.puts "\t\t\t\t# include PatternMatchCheck" @@ -123,56 +120,55 @@ file.puts "" file.puts "\t\t\t\tdef initialize" file.puts "\t\t\t\tend" file.puts "\t\t\tend" file.puts "\t\tend" - file.puts "\tend" file.puts "end" end puts "#{rb_filename} created" open(spec_filename, "w") do |file| file.puts "require 'spec_helper'" file.puts "describe \"The #{name} vulnerability\" do" file.puts "\tbefore(:all) do" - file.puts "\t\t@check = Codesake::Dawn::Kb::#{class_name}.new" + file.puts "\t\t@check = Dawn::Kb::#{class_name}.new" file.puts "\t\t# @check.debug = true" file.puts "\tend" file.puts "\tit \"is reported when...\"" file.puts "end" end puts "#{spec_filename} created" - puts "*** PLEASE IMPLEMENT TEST FOR #{name} IN spec/lib/dawn/codesake_knowledgebase_spec.rb in order to reflect changes" - puts "*** PLEASE ADD THIS CODE IN lib/codesake/dawn/knowledge_base.rb in order to reflect changes" - puts "require \"codesake/dawn/kb/#{class_name.downcase}\"" + puts "*** PLEASE IMPLEMENT TEST FOR #{name} IN spec/lib/dawn/knowledgebase_spec.rb in order to reflect changes" + puts "*** PLEASE ADD THIS CODE IN lib/dawn/knowledge_base.rb in order to reflect changes" + puts "require \"dawn/kb/#{class_name.downcase}\"" puts "it \"must have test for #{name}\" do" puts " sc = kb.find(\"#{name}\")" puts " sc.should_not be_nil" - puts " sc.class.should == Codesake::Dawn::Kb::#{class_name}" + puts " sc.class.should == Dawn::Kb::#{class_name}" puts "end" end namespace :kb do desc 'Check information lint' task :lint do - Codesake::Dawn::KnowledgeBase.new.all.each do |check| + Dawn::KnowledgeBase.new.all.each do |check| l = check.lint puts "check #{check.name} has this attribute(s) with a nil value: #{l.to_s}" unless l.size == 0 end end desc 'Creates a KnowledgeBase.md file' task :create do - checks = Codesake::Dawn::KnowledgeBase.new.all + checks = Dawn::KnowledgeBase.new.all open("KnowledgeBase.md", "w") do |file| - file.puts "# Codesake::Dawn Knowledge base" - file.puts "\nThe knowledge base library for Codesake::Dawn version #{Codesake::Dawn::VERSION} contains #{checks.count} security checks." + file.puts "# Dawn Knowledge base" + file.puts "\nThe knowledge base library for Dawn version #{Dawn::VERSION} contains #{checks.count} security checks." file.puts "---" checks.each do |c| file.puts "* [#{c.name}](#{c.cve_link}): #{c.message}" if c.name.start_with?('CVE') file.puts "* [#{c.name}](#{c.osvdb_link}): #{c.message}" if c.name.start_with?('OSVDB') file.puts "* #{c.name}: #{c.message}" unless c.name.start_with?('CVE') @@ -183,38 +179,38 @@ puts "KnowledgeBase.md file successfully generated" end end -require 'digest/sha2' +require 'digest/sha1' namespace :checksum do desc 'Calculate gem checksum' task :calculate do system 'mkdir -p checksum > /dev/null' - built_gem_path = "pkg/codesake-dawn-#{Codesake::Dawn::VERSION}.gem" - checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path)) - checksum_path = "checksum/codesake-dawn-#{Codesake::Dawn::VERSION}.gem.sha512" + built_gem_path = "pkg/dawnscanner-#{Dawn::VERSION}.gem" + checksum = Digest::SHA1.new.hexdigest(File.read(built_gem_path)) + checksum_path = "checksum/dawnscanner-#{Dawn::VERSION}.gem.sha1" File.open(checksum_path, 'w' ) {|f| f.write(checksum) } puts "#{checksum_path}: #{checksum}" end desc 'Add and commit latest checksum' task :commit do - checksum_path = "checksum/codesake-dawn-#{Codesake::Dawn::VERSION}.gem.sha512" + checksum_path = "checksum/dawnscanner-#{Dawn::VERSION}.gem.sha1" system "git add #{checksum_path}" - system "git commit -v #{checksum_path} -m \"Adding #{Codesake::Dawn::VERSION} checksum to repo\"" + system "git commit -v #{checksum_path} -m \"Adding #{Dawn::VERSION} checksum to repo\"" end end ############################################################################### # ruby-advisory-rb integration ############################################################################### namespace :rubysec do - desc 'Find new CVE bulletins to add to Codesake::Dawn' + desc 'Find new CVE bulletins to add to Dawn' task :find do git_url = 'git@github.com:rubysec/ruby-advisory-db.git' target_dir = './tmp/' system "mkdir -p #{target_dir}" system "rm -rf #{target_dir}ruby-advisory-db" @@ -230,18 +226,18 @@ # CVE-2013-1876 is a duplicate of CVE-2013-2615 that is in knowledge base exclusion = ["CVE-2007-6183", "CVE-2013-1876", "CVE-2013-1878"] if exclusion.include?(cve) puts "#{cve} is in the exclusion list" else - found = Codesake::Dawn::KnowledgeBase.find(nil, cve) - puts "#{cve} NOT in dawn v#{Codesake::Dawn::VERSION} knowledge base" unless found + found = Dawn::KnowledgeBase.find(nil, cve) + puts "#{cve} NOT in dawn v#{Dawn::VERSION} knowledge base" unless found list << cve unless found end end end unless list.empty? File.open("missing_rubyadvisory_cvs_#{Time.now.strftime("%Y%m%d")}.txt", "w") do |f| - f.puts "Missing CVE bulletins - v#{Codesake::Dawn::VERSION} - #{Time.now.strftime("%d %B %Y")}" + f.puts "Missing CVE bulletins - v#{Dawn::VERSION} - #{Time.now.strftime("%d %B %Y")}" f.puts list end end system "rm -rf #{target_dir}ruby-advisory-db"