Rakefile in dawnscanner-1.3.1 vs Rakefile in dawnscanner-1.3.5

- old
+ new

@@ -22,10 +22,48 @@ task :default => [ :spec, :features, :kb ] task :test => :spec task :prepare => [:build, :'checksum:calculate', :'checksum:commit'] task :release => [:prepare] +namespace :version do + desc 'Calculate some infos you want to put in version.rb' + task :update do + build_number = `git describe --tags --long | cut -d \'-\' -f 2` + commit_hash = `git describe --tags --long | cut -d \'-\' -f 3` + release = Time.now.strftime("%Y%m%d") + branch = `git symbolic-ref HEAD 2> /dev/null` + branch_name = branch.split('/')[2].chomp + a=[] + File.open("VERSION", "r") do |f| + a = f.readlines + end + version = a[a.length - 1].split('-')[0]# .chomp + codename = a[a.length - 1].split('-')[1] + + File.open("./lib/dawn/version.rb", "w") do |f| + + f.puts("module Dawn") + + puts "#{branch_name}|" + if branch_name != "master" + av = version.split('.') + f.puts " VERSION = \"#{av[0]}.#{av[1]}.#{commit_hash.chop}\"" + f.puts " CODENAME = \"#{codename.lstrip!.chop}\"" + f.puts " RELEASE = \"(development)\"" + else + puts "here" + f.puts " VERSION = \"#{version.rstrip!}\"" + f.puts " CODENAME = \"#{codename.lstrip!.chop}\"" + f.puts " RELEASE = \"#{release}\"" + end + f.puts " BUILD = \"#{build_number.chop}\"" + f.puts " COMMIT = \"#{commit_hash.chop}\"" + f.puts "end" + end + end +end + # namespace :check do # desc "Create a dependency check" # task :dependency, :name do |t, args| # end @@ -85,9 +123,71 @@ puts " sc = kb.find(\"#{name}\")" puts " sc.should_not be_nil" puts " sc.class.should == Dawn::Kb::#{class_name}" puts "end" + +end + +desc "Create a new OSVDB security check" +task :osvdb, :name do |t,args| + name = args.name + SRC_DIR = "./lib/dawn/kb/" + SPEC_DIR = "./spec/lib/kb/" + + raise "### It seems that #{name} is already in Dawn knowledge base" unless Dawn::KnowledgeBase.find(nil, name).nil? + raise "### Invalid OSVDB identifier: #{name}" if name.nil? or name.empty? or /\d{6}/.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..." + + name = "OSVDB_"+name + + 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 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" + file.puts "\t\t\t\t# include DependencyCheck" + file.puts "\t\t\t\t# include RubyVersionCheck" + 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 "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 = 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/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 == Dawn::Kb::#{class_name}" + puts "end" end