diff options
Diffstat (limited to 'features/steps/fixture_steps.rb')
-rw-r--r-- | features/steps/fixture_steps.rb | 112 |
1 files changed, 91 insertions, 21 deletions
diff --git a/features/steps/fixture_steps.rb b/features/steps/fixture_steps.rb index 6c9e8c9ed1..5239e5d762 100644 --- a/features/steps/fixture_steps.rb +++ b/features/steps/fixture_steps.rb @@ -1,19 +1,53 @@ +require 'ostruct' + Before do @fixtures = { + 'signing_caller' =>{ + :user_id=>'bobo', :secret_key => "/tmp/poop.pem" + }, 'registration' => { 'bobo' => Proc.new do - r = Chef::OpenIDRegistration.new - r.name = "bobo" - r.set_password('tclown') - r.validated = true - r.admin = true - r + + OpenStruct.new({ :save => true }) + #Chef::CouchDB.new(Chef::Config[:couchdb_url], "chef_integration")) + end + }, + 'data_bag' => { + 'users' => Proc.new do + b = Chef::DataBag.new(Chef::CouchDB.new(nil, "chef_integration")) + b.name "users" + b + end, + 'rubies' => Proc.new do + b = Chef::DataBag.new(Chef::CouchDB.new(nil, "chef_integration")) + b.name "rubies" + b + end + }, + 'data_bag_item' => { + 'francis' => Proc.new do + i = Chef::DataBagItem.new(Chef::CouchDB.new(nil, "chef_integration")) + i.data_bag "users" + i.raw_data = { "id" => "francis" } + i + end, + 'francis_extra' => Proc.new do + i = Chef::DataBagItem.new(Chef::CouchDB.new(nil, "chef_integration")) + i.data_bag "users" + i.raw_data = { "id" => "francis", "extra" => "majority" } + i + end, + 'axl_rose' => Proc.new do + i = Chef::DataBagItem.new(Chef::CouchDB.new(nil, "chef_integration")) + i.data_bag "users" + i.raw_data = { "id" => "axl_rose" } + i end }, 'role' => { 'webserver' => Proc.new do - r = Chef::Role.new + r = Chef::Role.new(Chef::CouchDB.new(nil, "chef_integration")) r.name "webserver" r.description "monkey" r.recipes("role::webserver", "role::base") @@ -22,7 +56,7 @@ Before do r end, 'db' => Proc.new do - r = Chef::Role.new + r = Chef::Role.new(Chef::CouchDB.new(nil, "chef_integration")) r.name "db" r.description "monkey" r.recipes("role::db", "role::base") @@ -33,7 +67,7 @@ Before do }, 'node' => { 'webserver' => Proc.new do - n = Chef::Node.new + n = Chef::Node.new(Chef::CouchDB.new(nil, "chef_integration")) n.name 'webserver' n.run_list << "tacos" n.snakes "on a plane" @@ -41,17 +75,34 @@ Before do n end, 'dbserver' => Proc.new do - n = Chef::Node.new + n = Chef::Node.new(Chef::CouchDB.new(nil, "chef_integration")) n.name 'dbserver' n.run_list << "oracle" n.just "kidding - who uses oracle?" n + end, + 'sync' => Proc.new do + n = Chef::Node.new(Chef::CouchDB.new(nil, "chef_integration")) + n.name 'sync' + n.run_list << "node_cookbook_sync" + n end } } @stash = {} end +def sign_request(http_method, private_key, user_id, body = "") + timestamp = Time.now.utc.iso8601 + sign_obj = Mixlib::Auth::SignedHeaderAuth.signing_object( + :http_method=>http_method, + :body=>body, + :user_id=>user_id, + :timestamp=>timestamp) + signed = sign_obj.sign(private_key).merge({:host => "localhost"}) + signed.inject({}){|memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo} +end + def get_fixture(stash_name, stash_key) fixy = @fixtures[stash_name][stash_key] if fixy.kind_of?(Proc) @@ -62,20 +113,35 @@ def get_fixture(stash_name, stash_key) end Given /^an? '(.+)' named '(.+)'$/ do |stash_name, stash_key| - @stash[stash_name] = get_fixture(stash_name, stash_key) + # BUGBUG: I need to reference fixtures individually, but the fixtures, as written, store under the type, not the fixture's identifier and I don't currently have time to re-write the tests + + key = case stash_name + when 'file','hash' + stash_key + else + stash_name + end + @stash[key] = get_fixture(stash_name, stash_key) end -Given /^an? '(.+)' named '(.+)' exists$/ do |stash_name, stash_key| +Given /^an? '(.+)' named '(.+)' exists$/ do |stash_name, stash_key| @stash[stash_name] = get_fixture(stash_name, stash_key) - if @stash[stash_name].respond_to?(:save) - @stash[stash_name].save - else - request("/#{stash_name.pluralize}", { - :method => "POST", - "HTTP_ACCEPT" => 'application/json', - "CONTENT_TYPE" => 'application/json', - :input => @stash[stash_name].to_json - }) + + if stash_name == 'registration' + r = Chef::REST.new(Chef::Config[:registration_url], Chef::Config[:validation_user], Chef::Config[:validation_key]) + r.register("bobo", "#{tmpdir}/bobo.pem") + @rest = Chef::REST.new(Chef::Config[:registration_url], 'bobo', "#{tmpdir}/bobo.pem") + else + if @stash[stash_name].respond_to?(:save)#stash_name == "registration" + @stash[stash_name].save + else + request("#{stash_name.pluralize}", { + :method => "POST", + "HTTP_ACCEPT" => 'application/json', + "CONTENT_TYPE" => 'application/json', + :input => @stash[stash_name].to_json + }.merge(sign_request("POST", OpenSSL::PKey::RSA.new(IO.read("#{tmpdir}/client.pem")), "bobo"))) + end end end @@ -98,3 +164,7 @@ Given /^there are no (.+)$/ do |stash_name| Chef::Role.list(true).each { |r| r.destroy } end end + +Given /^I wait for '(\d+)' seconds$/ do |time| + sleep time.to_i +end |