From ca2697b8eb1b1062dfc1ff847392db91b7337f35 Mon Sep 17 00:00:00 2001 From: Stephen Kapp Date: Sat, 26 Jan 2013 11:47:01 +0000 Subject: [PATCH] Added Call Stack Handling --- lib/veracode/api/call_stack.rb | 59 ++++++++++++++++ lib/veracode/results.rb | 28 ++++++-- lib/veracode/version.rb | 2 +- spec/fixtures/veracode_cassettes/base.yml | 82 +++++++++++++++++++++++ spec/lib/veracode/call_stack_spec.rb | 24 +++++++ 5 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 lib/veracode/api/call_stack.rb create mode 100644 spec/lib/veracode/call_stack_spec.rb diff --git a/lib/veracode/api/call_stack.rb b/lib/veracode/api/call_stack.rb new file mode 100644 index 0000000..3207288 --- /dev/null +++ b/lib/veracode/api/call_stack.rb @@ -0,0 +1,59 @@ +require 'veracode/api/types' + +module Veracode + module Result + class Call < Veracode::Common::Base + api_field :data_path, :tag => :data_path + api_field :file_path, :tag => :file_path + api_field :function_name, :tag => :function_name + api_field :line_number, :tag => :line_number + end + + class CallStack < Veracode::Common::Base + api_field :module_name, :tag => :module_name + api_field :steps, :tag => :steps + api_field :local_path, :tag => :local_path + api_field :function_name, :tag => :function_name + api_field :line_number, :tag => :line_number + + def calls + @calls ||= [] + begin + if @calls.empty? + if @xml_hash.call.class == Array + @calls = @xml_hash.call.map do |item| + Call.new(item) + end + else + @calls << Call.new(@xml_hash.call) + end + end + rescue NoMethodError + end + return @calls + end + end + + class CallStacks < Veracode::Common::Base + api_field :build_id, :tag => :build_id + api_field :flaw_id, :tag => :flaw_id + + def callstack + @callstacks ||= [] + begin + if @callstacks.empty? + if @xml_hash.callstack.class == Array + @callstacks = @xml_hash.callstack.map do |item| + CallStack.new(item) + end + else + @callstacks << CallStack.new(@xml_hash.callstack) + end + end + rescue NoMethodError + end + return @callstacks + end + end + end +end \ No newline at end of file diff --git a/lib/veracode/results.rb b/lib/veracode/results.rb index 4324b55..db9dbef 100644 --- a/lib/veracode/results.rb +++ b/lib/veracode/results.rb @@ -3,18 +3,32 @@ require 'veracode/api/builds' require 'veracode/api/detailed' require 'veracode/api/summary' +require 'veracode/api/call_stack' module Veracode module API class Results < Veracode::API::Base - GET_APP_BUILDS_URI = "/api/2.0/getappbuilds.do"; - DETAILED_REPORT_URI = "/api/2.0/detailedreport.do"; - DETAILED_REPORT_PDF_URI = "/api/2.0/detailedreportpdf.do"; - SUMMARY_REPORT_URI = "/api/2.0/summaryreport.do"; - SUMMARY_REPORT_PDF_URI = "/api/2.0/summaryreportpdf.do"; - THIRD_PARTY_REPORT_PDF_URI = "/api/2.0/thirdpartyreportpdf.do"; - + GET_APP_BUILDS_URI = "/api/2.0/getappbuilds.do" + DETAILED_REPORT_URI = "/api/2.0/detailedreport.do" + DETAILED_REPORT_PDF_URI = "/api/2.0/detailedreportpdf.do" + GET_CALL_STACKS_URI = "/api/2.0/getcallstacks.do" + SUMMARY_REPORT_URI = "/api/2.0/summaryreport.do" + SUMMARY_REPORT_PDF_URI = "/api/2.0/summaryreportpdf.do" + THIRD_PARTY_REPORT_PDF_URI = "/api/2.0/thirdpartyreportpdf.do" + + def get_callstacks(build_id, flaw_id) + xml = getXML(GET_CALL_STACKS_URI + "?build_id=" + build_id + "&flaw_id=" + flaw_id) + case xml.code + when 200 + clean_xml = xml.body.strip + parsed = Veracode::Parser.parse(clean_xml) + builds = Veracode::Result::CallStacks.new(parsed) + else + xml.error! + end + end + def get_application_builds xml = getXML(GET_APP_BUILDS_URI) case xml.code diff --git a/lib/veracode/version.rb b/lib/veracode/version.rb index e893fb5..d9c2daa 100644 --- a/lib/veracode/version.rb +++ b/lib/veracode/version.rb @@ -1,5 +1,5 @@ module Veracode module API - VERSION = "0.3.1" + VERSION = "0.4.1" end end diff --git a/spec/fixtures/veracode_cassettes/base.yml b/spec/fixtures/veracode_cassettes/base.yml index 7a84fcb..9cd52a6 100644 --- a/spec/fixtures/veracode_cassettes/base.yml +++ b/spec/fixtures/veracode_cassettes/base.yml @@ -7234,4 +7234,86 @@ http_interactions: ' http_version: recorded_at: Fri, 28 Dec 2012 13:00:22 GMT +- request: + method: get + uri: https://test:test@analysiscenter.veracode.com/api/2.0/getcallstacks.do?build_id=44905&flaw_id=132 + 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=2CA6FB985F4BAE2D8E63F4714BAC3EC4; Path=/; Secure + - JSESSIONID=8CF06392B3F085E721F8FBEFB5D31A49; Path=/; Secure + Content-Type: + - text/xml + Transfer-Encoding: + - chunked + Date: + - Thu, 24 Jan 2013 23:31:48 GMT + Server: + - Apache + body: + encoding: US-ASCII + string: ! ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +' + http_version: + recorded_at: Thu, 24 Jan 2013 23:31:48 GMT recorded_with: VCR 2.2.0 diff --git a/spec/lib/veracode/call_stack_spec.rb b/spec/lib/veracode/call_stack_spec.rb new file mode 100644 index 0000000..e726868 --- /dev/null +++ b/spec/lib/veracode/call_stack_spec.rb @@ -0,0 +1,24 @@ +require (File.expand_path('./../../../spec_helper', __FILE__)) + +describe Veracode::API::Results do + describe "GET Call Stack" do + + let(:veracode) { Veracode::API::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_callstacks method" do + veracode.must_respond_to :get_callstacks + end + + it "must parse the api response from XML to Veracode::Result::CallStacks" do + veracode.get_callstacks("44905", "132").must_be_instance_of Veracode::Result::CallStacks + end + end +end