Adds dependency on vcr and webmock
---
lib/aeolus_image.rb | 2 +-
rubygem-aeolus-image.spec | 16 ++++----
spec/models/factory/base.rb | 67 +++++++++++++++++++++++++++++++++++
spec/spec_helper.rb | 18 +--------
spec/vcr/cassettes/oauth.yml | 80 ++++++++++++++++++++++++++++++++++++++++++
spec/vcr_setup.rb | 19 ++++++++++
6 files changed, 177 insertions(+), 25 deletions(-)
create mode 100644 spec/models/factory/base.rb
create mode 100644 spec/vcr/cassettes/oauth.yml
create mode 100644 spec/vcr_setup.rb
diff --git a/lib/aeolus_image.rb b/lib/aeolus_image.rb
index aeb6bcc..d541b5d 100644
--- a/lib/aeolus_image.rb
+++ b/lib/aeolus_image.rb
@@ -29,4 +29,4 @@ require File.join(File.dirname(__FILE__),
'aeolus_image/model/factory', 'build')
require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory',
'provider_image')
require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory',
'target_image')
require File.join(File.dirname(__FILE__), 'aeolus_image/model/factory',
'builder')
-require File.join(File.dirname(__FILE__), 'aeolus_image',
'oauth_client')
+require File.join(File.dirname(__FILE__), 'aeolus_image',
'active_resource_oauth_client')
diff --git a/rubygem-aeolus-image.spec b/rubygem-aeolus-image.spec
index 2914a6b..baa2640 100644
--- a/rubygem-aeolus-image.spec
+++ b/rubygem-aeolus-image.spec
@@ -6,18 +6,11 @@
Summary: Ruby Client for interacting with Image Warehouse and Image Factory
Name: rubygem-aeolus-image
Version: 0.1.0
-Release: 3%{?extra_release}%{?dist}
+Release: 4%{?extra_release}%{?dist}
Group: Development/Languages
License: ASL 2.0
URL:
http://aeolusproject.org
-# The source for this packages was pulled from the upstream's git repo.
-# Use the following commands to generate the gem
-# git clone
git://git.fedorahosted.org/aeolus/conductor.git
-# git checkout next
-# cd services/image_factory/aeolus-image
-# rake gem
-# grab image_factory_console-0.0.1.gem from the pkg subdir
Source0: %{gemname}-%{version}.gem
Requires: ruby(abi) = %{rubyabi}
@@ -26,6 +19,9 @@ Requires: rubygem(nokogiri) >= 1.4.0
Requires: rubygem(rest-client)
Requires: rubygem(imagefactory-console) >= 0.4.0
Requires: rubygem(oauth)
+Requires: rubygem(vcr)
+Requires: rubygem(webmock)
+Requires: rubygem(timecop)
BuildRequires: ruby
BuildRequires: rubygems
@@ -61,6 +57,10 @@ rm -rf %{buildroot}%{gemdir}/gems/%{gemname}-%{version}/.yardoc
%{gemdir}/specifications/%{gemname}-%{version}.gemspec
%changelog
+* Mon Oct 17 2011 Matt Wagner <matt.wagner(a)redhat.com> - 0.0.1-4
+- Adds OAuth support for Factory client
+- Add vcr and webmock dependencies
+
* Tue Sep 20 2011 Martyn Taylor <mtaylor(a)redhat.com> - 0.0.1-3
- split out command line tools
diff --git a/spec/models/factory/base.rb b/spec/models/factory/base.rb
new file mode 100644
index 0000000..da5d0aa
--- /dev/null
+++ b/spec/models/factory/base.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+require 'timecop'
+
+describe Aeolus::Image::Factory::Base do
+
+ before(:each) do
+ Timecop.travel(Time.local(2011, 10, 17, 13, 38, 20))
+ end
+
+ after(:each) do
+ Timecop.return
+ end
+
+ it "should not use_oauth? if configuration is missing" do
+ Aeolus::Image::Factory::Base.config = {
+ :site => 'http://127.0.0.1:8075/imagefactory'
+ }
+ Aeolus::Image::Factory::Base.use_oauth?.should be_false
+ end
+
+ it "should use_oauth? if configuration is present" do
+ Aeolus::Image::Factory::Base.config = {
+ :site => 'http://127.0.0.1:8075/imagefactory',
+ :consumer_key => 'something',
+ :consumer_secret => 'anything'
+ }
+ Aeolus::Image::Factory::Base.use_oauth?.should be_true
+ end
+
+ it "should succeed with valid OAuth credentials" do
+ Aeolus::Image::Factory::Base.config = {
+ :site => 'http://127.0.0.1:8075/imagefactory',
+ :consumer_key => 'mock-key',
+ :consumer_secret => 'mock-secret'
+ }
+ template = "<template>\n <name>f14jeos</name>\n <os>\n
<name>Fedora</name>\n <version>14</version>\n
<arch>x86_64</arch>\n <install type='url'>\n
<
url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fed...
</install>\n </os>\n <description>Fedora
14</description>\n</template>\n"
+ img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template =>
template)
+ img.save!.should be_true
+ end
+
+ it "should fail with invalid OAuth credentials" do
+ Aeolus::Image::Factory::Base.config = {
+ :site => 'http://127.0.0.1:8075/imagefactory',
+ :consumer_key => 'mock-key',
+ :consumer_secret => 'wrong-secret'
+ }
+ template = "<template>\n <name>f14jeos</name>\n <os>\n
<name>Fedora 2</name>\n <version>14</version>\n
<arch>x86_64</arch>\n <install type='url'>\n
<
url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fed...
</install>\n </os>\n <description>Fedora
14</description>\n</template>\n"
+ img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template =>
template)
+ lambda {
+ img.save!
+ }.should raise_error(ActiveResource::UnauthorizedAccess)
+ end
+
+ it "should fail with no OAuth credentials" do
+ Aeolus::Image::Factory::Base.config = {
+ :site => 'http://127.0.0.1:8075/imagefactory'
+ }
+ template = "<template>\n <name>f14jeos</name>\n <os>\n
<name>Fedora 3</name>\n <version>14</version>\n
<arch>x86_64</arch>\n <install type='url'>\n
<
url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fed...
</install>\n </os>\n <description>Fedora
14</description>\n</template>\n"
+ img = Aeolus::Image::Factory::Image.new(:targets => 'ec2', :template =>
template)
+ # ServerError is actually not what _should_ be returned, but a bug means that's
what we get at the moment.
+ # When the bug is fixed, we need to update to test for that.
+ lambda {
+ img.save!.should be_false
+ }.should raise_error(ActiveResource::ServerError)
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6706fe2..4252180 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -15,19 +15,5 @@
$: << File.expand_path(File.join(File.dirname(__FILE__),
"../lib/aeolus_image/model/"))
require 'rubygems'
-require 'warehouse_client'
-require 'warehouse_model'
-require 'image'
-require 'image_build'
-require 'target_image'
-require 'provider_image'
-
-RSpec.configure do |config|
- config.before(:all) do
- Aeolus::Image::BaseCommand.class_eval do
- def load_config
- YAML::load(File.open(File.join(File.dirname(__FILE__),
"/../examples/aeolus-cli")))
- end
- end
- end
-end
\ No newline at end of file
+require File.join(File.dirname(__FILE__), '../lib', 'aeolus_image')
+require 'vcr_setup'
diff --git a/spec/vcr/cassettes/oauth.yml b/spec/vcr/cassettes/oauth.yml
new file mode 100644
index 0000000..9f8c7fa
--- /dev/null
+++ b/spec/vcr/cassettes/oauth.yml
@@ -0,0 +1,80 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://127.0.0.1:8075/imagefactory/images
+ body:
"{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n
<name>f14jeos</name>\\n <os>\\n <name>Fedora</name>\\n
<version>14</version>\\n <arch>x86_64</arch>\\n
<install type='url'>\\n
<
url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fed...
</install>\\n </os>\\n <description>Fedora
14</description>\\n</template>\\n\"}}"
+ headers:
+ user-agent:
+ - OAuth gem v0.4.4
+ content-type:
+ - application/json
+ authorization:
+ - OAuth oauth_body_hash="iLFFmVptnUF4tv9PvDNdNxK%2FSOs%3D",
oauth_consumer_key="mock-key",
oauth_nonce="dESbWyTyKA0UTHekLdt7DOSOFh6tYU39Mw7LpFkts",
oauth_signature="ydhBMjipuQ7ARZT5xfOrvShZfHI%3D",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318873100",
oauth_version="1.0"
+ content-length:
+ - "365"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 202
+ message: Accepted
+ headers:
+ content-type:
+ - application/json
+ server:
+ - PasteWSGIServer/0.5 Python/2.7.1
+ date:
+ - Mon, 17 Oct 2011 17:38:15 GMT
+ content-length:
+ - "640"
+ body: "{\"_type\": \"image\", \"href\":
\"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85\",
\"id\": \"18f1b17e-3fdc-4931-a5d6-f4581e5f5f85\", \"build\":
{\"target_images\": [{\"_type\": \"target_image\",
\"href\":
\"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85/builds/6d715c2f-8dc5-46eb-86ad-509366e64252/target_images/dd9c27c5-0bdb-4670-b172-46a3cf2101a6\",
\"id\": \"dd9c27c5-0bdb-4670-b172-46a3cf2101a6\"}],
\"_type\": \"build\", \"href\":
\"http://127.0.0.1:8075/imagefactory/images/18f1b17e-3fdc-4931-a5d6-f4581e5f5f85/builds/6d715c2f-8dc5-46eb-86ad-509366e64252\",
\"id\": \"6d715c2f-8dc5-46eb-86ad-509366e64252\"}}"
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://127.0.0.1:8075/imagefactory/images
+ body:
"{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n
<name>f14jeos</name>\\n <os>\\n <name>Fedora
2</name>\\n <version>14</version>\\n
<arch>x86_64</arch>\\n <install type='url'>\\n
<
url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fed...
</install>\\n </os>\\n <description>Fedora
14</description>\\n</template>\\n\"}}"
+ headers:
+ content-type:
+ - application/json
+ user-agent:
+ - OAuth gem v0.4.4
+ authorization:
+ - OAuth oauth_body_hash="tEAlC3IwCGiB%2FNSQRUOwBifTHmY%3D",
oauth_consumer_key="mock-key",
oauth_nonce="jeQp5OlYxoCbbflwdM9nfg306BUVfmidPYKV7qPOs",
oauth_signature="ERZpwVUR4qdBjfeBTJQtem%2FnKTo%3D",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318873100",
oauth_version="1.0"
+ content-length:
+ - "367"
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 401
+ message: Unauthorized
+ headers:
+ content-type:
+ - text/html; charset=UTF-8
+ date:
+ - Mon, 17 Oct 2011 17:38:15 GMT
+ server:
+ - PasteWSGIServer/0.5 Python/2.7.1
+ content-length:
+ - "0"
+ body:
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
http://127.0.0.1:8075/imagefactory/images
+ body:
"{\"image\":{\"targets\":\"ec2\",\"template\":\"<template>\\n
<name>f14jeos</name>\\n <os>\\n <name>Fedora
3</name>\\n <version>14</version>\\n
<arch>x86_64</arch>\\n <install type='url'>\\n
<
url>http://download.fedoraproject.org/pub/fedora/linux/releases/14/Fed...
</install>\\n </os>\\n <description>Fedora
14</description>\\n</template>\\n\"}}"
+ headers:
+ content-type:
+ - application/json
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 500
+ message: Internal Server Error
+ headers:
+ content-type:
+ - text/html; charset=UTF-8
+ server:
+ - PasteWSGIServer/0.5 Python/2.7.1
+ date:
+ - Mon, 17 Oct 2011 17:38:15 GMT
+ body: "'NoneType' object has no attribute
'_get_timestamp_nonce'"
+ http_version: "1.1"
diff --git a/spec/vcr_setup.rb b/spec/vcr_setup.rb
new file mode 100644
index 0000000..1d79608
--- /dev/null
+++ b/spec/vcr_setup.rb
@@ -0,0 +1,19 @@
+require 'vcr'
+require 'oauth'
+require File.join(File.dirname(__FILE__), '../lib', 'aeolus_image')
+
+
+VCR.config do |config|
+ config.cassette_library_dir = 'spec/vcr/cassettes'
+ config.stub_with :webmock
+ config.allow_http_connections_when_no_cassette = true
+end
+
+ActiveResource::Connection.class_eval do
+ def request(method, path, *args)
+ # We want to add :body, but not :headers because they're too fickle with OAuth
+ VCR.use_cassette('oauth', :record => :new_episodes, :match_requests_on
=> [:method, :uri, :body]) do
+ request_with_oauth(method, path, *args)
+ end
+ end
+end
--
1.7.6.4