From 66187d73fb015055910baf651a4d4c6f8c00d1ca Mon Sep 17 00:00:00 2001 From: Eddie Johnston Date: Thu, 6 Jul 2017 16:33:53 +0100 Subject: [PATCH] Fix Fog::Compute::AWS::Images#all Calling #all fails with the error: `Excon::Error::Socket: 25:28: FATAL: Document is empty (Nokogiri::XML::SyntaxError)`. This was because of the parser not handling nil creationDate values: ``` when 'creationDate' @image[name] = Time.parse(value) ``` This commit ensures nil `creationDate` fields are not parsed. --- .../aws/parsers/compute/describe_images.rb | 2 +- .../parsers/compute/describe_images_tests.rb | 33 +++++++++++++++++++ tests/requests/compute/helper.rb | 21 ++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tests/parsers/compute/describe_images_tests.rb diff --git a/lib/fog/aws/parsers/compute/describe_images.rb b/lib/fog/aws/parsers/compute/describe_images.rb index 0fe8e275b..9d88eef1e 100644 --- a/lib/fog/aws/parsers/compute/describe_images.rb +++ b/lib/fog/aws/parsers/compute/describe_images.rb @@ -75,7 +75,7 @@ module Fog @image[name] = false end when 'creationDate' - @image[name] = Time.parse(value) + @image[name] = Time.parse(value) if value && !value.empty? when 'item' @response['imagesSet'] << @image @image = { 'blockDeviceMapping' => [], 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} } diff --git a/tests/parsers/compute/describe_images_tests.rb b/tests/parsers/compute/describe_images_tests.rb new file mode 100644 index 000000000..8748a0c3f --- /dev/null +++ b/tests/parsers/compute/describe_images_tests.rb @@ -0,0 +1,33 @@ +require 'fog/xml' +require 'fog/aws/parsers/compute/describe_images' + +DESCRIBE_IMAGES_RESULT = <<-EOF + + 180a8433-ade0-4a6c-b35b-107897579572 + + + aki-02486376 + ec2-public-images-eu/vmlinuz-2.6.21-2.fc8xen-ec2-v1.0.i386.aki.manifest.xml + available + 206029621532 + + true + i386 + kernel + amazon + instance-store + + paravirtual + xen + + + +EOF + +Shindo.tests('Compute::AWS | parsers | describe_images', ['compute', 'aws', 'parser']) do + tests('parses the xml').formats(AWS::Compute::Formats::DESCRIBE_IMAGES) do + parser = Nokogiri::XML::SAX::Parser.new(Fog::Parsers::Compute::AWS::DescribeImages.new) + parser.parse(DESCRIBE_IMAGES_RESULT) + parser.document.response + end +end diff --git a/tests/requests/compute/helper.rb b/tests/requests/compute/helper.rb index a6f49facc..962de2a95 100644 --- a/tests/requests/compute/helper.rb +++ b/tests/requests/compute/helper.rb @@ -2,9 +2,26 @@ class AWS module Compute module Formats BASIC = { - 'requestId' => String, - 'return' => ::Fog::Boolean + 'requestId' => String } + + DESCRIBE_IMAGES = BASIC.merge({ + "imagesSet" => [{ + "imageId" => String, + "imageLocation" => String, + "imageState" => String, + "imageOwnerId" => String, + "creationDate" => Fog::Nullable::String, + "isPublic" => Fog::Nullable::Boolean, + "architecture" => String, + "imageType" => String, + "imageOwnerAlias" => String, + "rootDeviceType" => String, + "blockDeviceMapping" => Array, + "virtualizationType" => String, + "hypervisor" => String + }] + }) end end end