diff --git a/lib/veracode/api/detailed.rb b/lib/veracode/api/detailed.rb index 35a13f6..deebb0d 100644 --- a/lib/veracode/api/detailed.rb +++ b/lib/veracode/api/detailed.rb @@ -3,47 +3,6 @@ module Veracode module Result - class Modules < Base - xml_reader :name, :from => "@name" - xml_reader :compiler, :from => "@compiler" - xml_reader :os, :from => "@os" - xml_reader :architecture, :from => "@architecture" - xml_reader :score, :from => "@score" - xml_reader :numflawssev0, :from => "@numflawssev0" - xml_reader :numflawssev1, :from => "@numflawssev1" - xml_reader :numflawssev2, :from => "@numflawssev2" - xml_reader :numflawssev3, :from => "@numflawssev3" - xml_reader :numflawssev4, :from => "@numflawssev4" - xml_reader :numflawssev5, :from => "@numflawssev5" - end - - class Analysis < Base - xml_reader :rating, :from => "@rating" - xml_reader :score, :from => "@score" - xml_reader :submitted_date, :from => "@submitted_date" - xml_reader :published_date, :from => "@published_date" - xml_reader :mitigated_rating, :from => "@mitigated_rating" - xml_reader :mitigated_score, :from => "@mitigated_score" - xml_reader :analysis_size_bytes, :from => "@analysis_size_bytes" - xml_reader :next_scan_due, :from => "@next_scan_due" - - xml_reader :modules, :as => [Modules] - end - - class ManualAnalysis < Base - xml_reader :rating, :from => "@rating" - xml_reader :score, :from => "@score" - xml_reader :mitigated_rating, :from => "@mitigated_rating" - xml_reader :mitigated_score, :from => "@mitigated_score" - xml_reader :submitted_date, :from => "@submitted_date" - xml_reader :published_date, :from => "@published_date" - xml_reader :next_scan_due, :from => "@next_scan_due" - - xml_reader :modules, :as => [Modules] - xml_reader :cia_adjustment - xml_reader :delivery_consultant - end - class CWE < Base xml_reader :cweid, :from => "@cweid" xml_reader :cwename, :from => "@cwename" @@ -65,20 +24,6 @@ class Category < Base xml_reader :cwe, :as => [CWE] end - class FlawStatus < Base - xml_reader :new, :from => :attr - xml_reader :reopen, :from => :attr - xml_reader :open, :from => :attr - xml_reader :fixed, :from => :attr - xml_reader :total, :from => :attr - xml_reader :not_mitigated, :from => :attr - xml_reader :sev_1_change, :from => :attr - xml_reader :sev_2_change, :from => :attr - xml_reader :sev_3_change, :from => :attr - xml_reader :sev_4_change, :from => :attr - xml_reader :sev_5_change, :from => :attr - end - class Severity < Base xml_reader :level, :from => "@level" @@ -95,6 +40,7 @@ class DetailedReport < Base xml_reader :version, :from => "@version" xml_reader :build_id, :from => "@build_id" xml_reader :submitter, :from => "@submitter" + xml_reader :vendor, :from => "@vendor" xml_reader :platform, :from => "@platform" xml_reader :assurance_level, :from => "@assurance_level" xml_reader :business_criticality, :from => "@business_criticality" @@ -106,7 +52,7 @@ class DetailedReport < Base xml_reader :life_cycle_stage, :from => "@life_cycle_stage" xml_reader :planned_deployment_date, :from => "@planned_deployment_date" xml_reader :last_update_time, :from => "@last_update_time" - xml_reader :is_latest_build, :from => "@is_latest_build" + xml_reader :is_latest_build?, :from => "@is_latest_build" xml_reader :policy_name, :from => "@policy_name" xml_reader :policy_version, :from => "@policy_version" xml_reader :policy_compliance_status, :from => "@policy_compliance_status" @@ -116,7 +62,7 @@ class DetailedReport < Base xml_reader :business_owner, :from => "@business_owner" xml_reader :business_unit, :from => "@business_unit" xml_reader :tags, :from => "@tags" - xml_reader :grace_period_expired, :from => "@grace_period_expired" + xml_reader :grace_period_expired?, :from => "@grace_period_expired" xml_reader :static_analysis, :as => Analysis diff --git a/lib/veracode/api/summary.rb b/lib/veracode/api/summary.rb new file mode 100644 index 0000000..60d5a8e --- /dev/null +++ b/lib/veracode/api/summary.rb @@ -0,0 +1,63 @@ +require 'veracode/api/types' +require 'veracode/api/flaws' + +module Veracode + module Result + + class SummaryCategory < Base + xml_reader :categoryname, :from => :attr + xml_reader :severity, :from => :attr + xml_reader :count, :from => :attr + end + + class SummarySeverity < Base + xml_reader :level, :from => "@level" + + xml_reader :categories, :as => [SummaryCategory] + end + + class SummaryReport < Base + xml_convention :dasherize + + xml_reader :report_format_version, :from => "@report_format_version" + xml_reader :app_name, :from => "@app_name" + xml_reader :app_id, :from => "@app_id" + xml_reader :first_build_submitted_date, :from => "@first_build_submitted_date" + xml_reader :version, :from => "@version" + xml_reader :build_id, :from => "@build_id" + xml_reader :vendor, :from => "@vendor" + xml_reader :submitter, :from => "@submitter" + xml_reader :platform, :from => "@platform" + xml_reader :assurance_level, :from => "@assurance_level" + xml_reader :business_criticality, :from => "@business_criticality" + xml_reader :generation_date, :from => "@generation_date" + xml_reader :veracode_level, :from => "@veracode_level" + xml_reader :total_flaws, :from => "@total_flaws" + xml_reader :flaws_not_mitigated, :from => "@flaws_not_mitigated" + xml_reader :teams, :from => "@teams" + xml_reader :life_cycle_stage, :from => "@life_cycle_stage" + xml_reader :planned_deployment_date, :from => "@planned_deployment_date" + xml_reader :last_update_time, :from => "@last_update_time" + xml_reader :is_latest_build?, :from => "@is_latest_build" + xml_reader :policy_name, :from => "@policy_name" + xml_reader :policy_version, :from => "@policy_version" + xml_reader :policy_compliance_status, :from => "@policy_compliance_status" + xml_reader :policy_rules_status, :from => "@policy_rules_status" + xml_reader :scan_overdue, :from => "@scan_overdue" + xml_reader :any_type_scan_due, :from => "@any_type_scan_due" + xml_reader :business_owner, :from => "@business_owner" + xml_reader :business_unit, :from => "@business_unit" + xml_reader :tags, :from => "@tags" + xml_reader :grace_period_expired?, :from => "@grace_period_expired" + + + xml_reader :static_analysis, :as => Analysis + xml_reader :dynamic_analysis, :as => Analysis + xml_reader :manual_analysis, :as => ManualAnalysis + + xml_reader :severity, :as => [SummarySeverity] + + xml_reader :flaw_status, :as => FlawStatus + end + end +end \ No newline at end of file diff --git a/lib/veracode/api/types.rb b/lib/veracode/api/types.rb index ca74326..45b1b7a 100644 --- a/lib/veracode/api/types.rb +++ b/lib/veracode/api/types.rb @@ -35,5 +35,60 @@ class AppendixType < Base xml_reader :screenshot, :as => [Screenshot] xml_reader :code end + + class Modules < Base + xml_reader :name, :from => "@name" + xml_reader :compiler, :from => "@compiler" + xml_reader :os, :from => "@os" + xml_reader :architecture, :from => "@architecture" + xml_reader :score, :from => "@score" + xml_reader :numflawssev0, :from => "@numflawssev0" + xml_reader :numflawssev1, :from => "@numflawssev1" + xml_reader :numflawssev2, :from => "@numflawssev2" + xml_reader :numflawssev3, :from => "@numflawssev3" + xml_reader :numflawssev4, :from => "@numflawssev4" + xml_reader :numflawssev5, :from => "@numflawssev5" + end + + class Analysis < Base + xml_reader :rating, :from => "@rating" + xml_reader :score, :from => "@score" + xml_reader :submitted_date, :from => "@submitted_date" + xml_reader :published_date, :from => "@published_date" + xml_reader :mitigated_rating, :from => "@mitigated_rating" + xml_reader :mitigated_score, :from => "@mitigated_score" + xml_reader :analysis_size_bytes, :from => "@analysis_size_bytes" + xml_reader :next_scan_due, :from => "@next_scan_due" + + xml_reader :modules, :as => [Modules] + end + + class ManualAnalysis < Base + xml_reader :rating, :from => "@rating" + xml_reader :score, :from => "@score" + xml_reader :mitigated_rating, :from => "@mitigated_rating" + xml_reader :mitigated_score, :from => "@mitigated_score" + xml_reader :submitted_date, :from => "@submitted_date" + xml_reader :published_date, :from => "@published_date" + xml_reader :next_scan_due, :from => "@next_scan_due" + + xml_reader :modules, :as => [Modules] + xml_reader :cia_adjustment + xml_reader :delivery_consultant + end + + class FlawStatus < Base + xml_reader :new, :from => :attr + xml_reader :reopen, :from => :attr + xml_reader :open, :from => :attr + xml_reader :fixed, :from => :attr + xml_reader :total, :from => :attr + xml_reader :not_mitigated, :from => :attr + xml_reader :sev_1_change, :from => :attr + xml_reader :sev_2_change, :from => :attr + xml_reader :sev_3_change, :from => :attr + xml_reader :sev_4_change, :from => :attr + xml_reader :sev_5_change, :from => :attr + end end end \ No newline at end of file diff --git a/lib/veracode/results.rb b/lib/veracode/results.rb index 99038e1..035649e 100644 --- a/lib/veracode/results.rb +++ b/lib/veracode/results.rb @@ -1,8 +1,8 @@ require 'nokogiri' require 'veracode/api/builds' require 'veracode/api/detailed' +require 'veracode/api/summary' -require 'pp' module Veracode class Results < Veracode::Base @@ -23,6 +23,16 @@ def get_application_builds end end + def get_summary_report(build_id) + xml = getXML(SUMMARY_REPORT_URI + "?build_id=" + build_id) + case xml.code + when 200 + report = Veracode::Result::SummaryReport.from_xml(xml.body) + else + xml.error! + end + end + def get_detailed_report(build_id) xml = getXML(DETAILED_REPORT_URI + "?build_id=" + build_id) case xml.code diff --git a/spec/fixtures/veracode_cassettes/base.yml b/spec/fixtures/veracode_cassettes/base.yml index ff0fe1b..bb889f8 100644 --- a/spec/fixtures/veracode_cassettes/base.yml +++ b/spec/fixtures/veracode_cassettes/base.yml @@ -6577,4 +6577,154 @@ http_interactions: sev-2-change=\"14\" sev-3-change=\"148\" sev-4-change=\"22\" sev-5-change=\"6\"/>\n\n" http_version: !!null recorded_at: Wed, 06 Jun 2012 16:25:28 GMT +- request: + method: get + uri: https://test:test@analysiscenter.veracode.com/api/2.0/summaryreport.do?build_id=44905 + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Pragma: + - '' + Cache-Control: + - no-store private must-revalidate + Expires: + - Thu, 01 Jan 1970 00:00:00 GMT + Set-Cookie: + - JSESSIONID=25463857974C8954780AA750F812AEB4; Path=/; Secure + - JSESSIONID=6EDFE24528ECA1527F6865FB60E9169B; Path=/; Secure + Content-Type: + - text/xml + Transfer-Encoding: + - chunked + Date: + - Wed, 06 Jun 2012 22:41:58 GMT + Server: + - Apache + body: + encoding: US-ASCII + string: ! ' + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +' + http_version: !!null + recorded_at: Wed, 06 Jun 2012 22:41:58 GMT recorded_with: VCR 2.2.0 diff --git a/spec/lib/veracode/builds_spec.rb b/spec/lib/veracode/builds_spec.rb new file mode 100644 index 0000000..ebe3572 --- /dev/null +++ b/spec/lib/veracode/builds_spec.rb @@ -0,0 +1,35 @@ +require (File.expand_path('./../../../spec_helper', __FILE__)) + +describe Veracode::Results do + describe "GET profile" do + + let(:veracode) { Veracode::Results.new(:username => "test", :password => "test") } + + before do + VCR.insert_cassette 'base', :record => :new_episodes + end + + after do + VCR.eject_cassette + end + + it "must have a get_application_builds method" do + veracode.must_respond_to :get_application_builds + end + + it "must parse the api response from XML to Veracode::Result::Builds::Applications" do + veracode.get_application_builds.must_be_instance_of Veracode::Result::Builds::Applications + end + + describe "dynamic attributes for builds" do + + before do + @builds = veracode.get_application_builds + end + + it "must raise method missing if attribute is not present" do + lambda { @builds.foo_attribute }.must_raise NoMethodError + end + end + end +end diff --git a/spec/lib/veracode/result_spec.rb b/spec/lib/veracode/detailed_spec.rb similarity index 70% rename from spec/lib/veracode/result_spec.rb rename to spec/lib/veracode/detailed_spec.rb index bd6bacf..3aef44c 100644 --- a/spec/lib/veracode/result_spec.rb +++ b/spec/lib/veracode/detailed_spec.rb @@ -1,7 +1,7 @@ require (File.expand_path('./../../../spec_helper', __FILE__)) describe Veracode::Results do - describe "GET profile" do + describe "GET detailed report" do let(:veracode) { Veracode::Results.new(:username => "test", :password => "test") } @@ -13,33 +13,14 @@ VCR.eject_cassette end - it "must have a get_application_builds method" do - veracode.must_respond_to :get_application_builds - end - it "must have a get_application_builds method" do veracode.must_respond_to :get_detailed_report end - it "must parse the api response from XML to Veracode::Result::Builds::Applications" do - veracode.get_application_builds.must_be_instance_of Veracode::Result::Builds::Applications - end - it "must parse the api response from XML to Veracode::Result::DetailedReport" do veracode.get_detailed_report("44905").must_be_instance_of Veracode::Result::DetailedReport end - describe "dynamic attributes for builds" do - - before do - @builds = veracode.get_application_builds - end - - it "must raise method missing if attribute is not present" do - lambda { @builds.foo_attribute }.must_raise NoMethodError - end - end - describe "dynamic attributes for results" do before do diff --git a/spec/lib/veracode/summary_spec.rb b/spec/lib/veracode/summary_spec.rb new file mode 100644 index 0000000..c3e7e08 --- /dev/null +++ b/spec/lib/veracode/summary_spec.rb @@ -0,0 +1,47 @@ +require (File.expand_path('./../../../spec_helper', __FILE__)) + +describe Veracode::Results do + describe "GET summary report" do + + let(:veracode) { Veracode::Results.new(:username => "test", :password => "test") } + + before do + VCR.insert_cassette 'base', :record => :new_episodes + end + + after do + VCR.eject_cassette + end + + it "must parse the api response from XML to Veracode::Result::SummaryReport" do + veracode.get_summary_report("44905").must_be_instance_of Veracode::Result::SummaryReport + end + + describe "dynamic attributes for results" do + + before do + @result = veracode.get_summary_report("44905") + end + + it "must return the attribute value if present" do + @result.app_name.must_equal "WebGoat" + end + + it "must be an instance of Veracode::Result::Analysis" do + @result.static_analysis.must_be_instance_of Veracode::Result::Analysis + end + + it "must be an instance of Veracode::Result::Analysis" do + @result.dynamic_analysis.must_be_instance_of Veracode::Result::Analysis + end + + it "must be an instance of Veracode::Result::ManualAnalysis" do + @result.manual_analysis.must_be_instance_of Veracode::Result::ManualAnalysis + end + + it "must raise method missing if attribute is not present" do + lambda { @result.foo_attribute }.must_raise NoMethodError + end + end + end +end