Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17 from opscode/dt/OC-2204/node-state-error-checking
Browse files Browse the repository at this point in the history
Dt/oc 2204/node state error checking
  • Loading branch information
Douglas Triggs committed Dec 31, 2012
2 parents e70be55 + 8410a6e commit 82f1048
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 11 deletions.
64 changes: 53 additions & 11 deletions oc-pushy-pedant/spec/pushy/integration/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,37 @@
# Copyright:: Copyright (c) 2012 Opscode, Inc.
#

require 'pedant/rspec/auth_headers_util'

describe "pushy config" do
def self.ruby?
false
end

let(:chef_server_host) {
chef_server = Pedant.config[:chef_server]
chef_server.gsub(/http[s]?:\/\//,'')
}

let(:config_body) {
{
"host" => chef_server_host,
"public_key" => /^-----BEGIN PUBLIC KEY-----/,
"type" => "config"
# There are a bunch of additional values
# We're not testing; one difficulty is that
# Organization/node are returning arrays,
# not actual strings, and push_jobs is complicated
} }

context "GET /organization/<name>/pushy/config/<nodename>" do
it "returns 200 and server config" do
get(api_url("pushy/config/DONKEY"), admin_user) do |response|
chef_server = Pedant.config[:chef_server]
chef_server_host = chef_server.gsub(/http[s]?:\/\//,'')
# TODO: probably should grab the correct values from config instead of
# hard-coding this, but this is proof-of-concept test only right now
response.should look_like({
:status => 200,
:body => {
"host" => chef_server_host,
"public_key" => /^-----BEGIN PUBLIC KEY-----/,
"type" => "config"
# There are a bunch of additional values
# We're not testing; one difficulty is that
# Organization/node are returning arrays,
# not actual strings, and push_jobs is complicated
}
:body => config_body
})
end
end
Expand Down Expand Up @@ -90,4 +102,34 @@
end
end
end

context 'invalid request' do
it "returns 403 (\"Forbidden\") when organization doesn't exist" do
path = api_url("/pushy/config/#{config_name}").gsub(org, "bogus-org")
get(path, admin_user) do |response|
response.should look_like({
:status => 403
})
end
end
end

describe 'handling authentication headers' do
let(:method) { :GET }
let(:body) { nil }
let(:success_user) { admin_user }
let(:failure_user) { invalid_user }

context 'GET /config/<name>' do
let(:url) { api_url("/pushy/config/#{config_name}") }
let(:response_should_be_successful) do
response.should look_like({
:status => 200,
:body => config_body
})
end

include_context 'handles authentication headers correctly'
end
end
end # describe "pushy config"
104 changes: 104 additions & 0 deletions oc-pushy-pedant/spec/pushy/integration/jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
#

require 'pedant/rspec/common'
require 'pedant/rspec/auth_headers_util'
require 'pushy/support/authorization_groups_util'

describe "Jobs API Endpoint", :jobs do
include_context "authorization_groups_util"

def self.ruby?
# Needed for pedant header checking

false
end

# TODO: turns out this doesn't really matter; will we need to create it
# at some point?
let(:node_name) { 'DONKEY' }
Expand Down Expand Up @@ -537,4 +544,101 @@
end
end # context 'GET /jobs/<name> with nested pushy_job_readers'
end # describe 'access control with nested pushy_job groups'

describe 'request error checking' do
let(:job_path) {
# This is evaluated at runtime, so there's always a (short-lived) job to
# detect during the test

post(api_url("/pushy/jobs"), admin_user, :payload => job_to_run) do |response|
list = JSON.parse(response.body)
list["uri"]
end
}

context 'invalid GET request' do
it 'returns 403 ("Forbidden") with bogus org for /jobs' do
path = api_url("/pushy/jobs").gsub(org, "bogus-org")
get(path, admin_user) do |response|
response.should look_like({
:status => 403
})
end
end

it 'returns 403 ("Forbidden") with bogus org for /jobs/<name>' do
path = job_path.gsub(org, "bogus-org")
get(path, admin_user) do |response|
response.should look_like({
:status => 403
})
end
end
end

context 'invalid POST request' do
it "returns 403 (\"Forbidden\") when organization doesn't exist" do
path = api_url("/pushy/jobs").gsub(org, "bogus-org")
post(path, admin_user, :payload => job_to_run) do |response|
response.should look_like({
:status => 403
})
end
end
end

describe 'handling authentication headers' do
let(:method) { :GET }
let(:body) { nil }
let(:success_user) { admin_user }
let(:failure_user) { invalid_user }

context 'GET /jobs' do
let(:url) { api_url("/pushy/jobs") }
let(:response_should_be_successful) do
response.should look_like({
:status => 200
# TODO: seems it's still not matching arrays
# correctly; Didn't John fix this at some point?
})
end

include_context 'handles authentication headers correctly'
end

context 'POST /jobs' do
let(:method) { :POST }
let(:body) { job_to_run }
let(:url) { api_url("/pushy/jobs") }
let(:response_should_be_successful) do
response.should look_like({
:status => 201,
:body_exact => {
'uri' => /^https\:\/\/.*\/jobs\/[0-9a-f]{32}$/
}
})
end

include_context 'handles authentication headers correctly'
end

context 'GET /jobs/<name>' do
let(:url) { job_path }
let(:response_should_be_successful) do
response.should look_like({
:status => 200,
:body_exact => {
'command' => 'sleep 1',
'id' => /^[0-9a-f]{32}$/,
'nodes' => {"unavailable" => ["DONKEY"]},
'run_timeout' => 3600,
'status' => 'quorum_failed'
}
})
end

include_context 'handles authentication headers correctly'
end
end # describe 'handling authentication headers'
end # describe 'input error checking'
end # describe "Jobs API Endpoint"
57 changes: 57 additions & 0 deletions oc-pushy-pedant/spec/pushy/integration/node_states_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
#

require 'pedant/rspec/common'
require 'pedant/rspec/auth_headers_util'
require 'pushy/support/authorization_groups_util'

describe "Node_States API Endpoint", :node_states do
include_context "authorization_groups_util"

def self.ruby?
false
end

let(:node_name) { 'some_node' }
let(:non_existent_node_name) { 'not_a_number' }

Expand Down Expand Up @@ -371,4 +376,56 @@
end
end # context 'GET /node_states/<name>'
end # describe 'access control with pushy_job_readers and nested groups'

context 'invalid request' do
it 'returns 403 ("Forbidden") with bogus org for /node_states' do
path = api_url("/pushy/node_states").gsub(org, "bogus-org")
get(path, admin_user) do |response|
response.should look_like({
:status => 403
})
end
end

it 'returns 403 ("Forbidden") with bogus org for /node_states/<name>' do
path = api_url("/pushy/node_states/#{node_name}").gsub(org, "bogus-org")
get(path, admin_user) do |response|
response.should look_like({
:status => 403
})
end
end
end

describe 'handling authentication headers' do
let(:method) { :GET }
let(:body) { nil }
let(:success_user) { admin_user }
let(:failure_user) { invalid_user }

context 'GET /node_states/' do
let(:url) { api_url("/pushy/node_states") }
let(:response_should_be_successful) do
response.should look_like({
:status => 200
# TODO: seems it's still not matching arrays
# correctly; Didn't John fix this at some point?
})
end

include_context 'handles authentication headers correctly'
end

context 'GET /node_states/<name>' do
let(:url) { api_url("/pushy/node_states/#{node_name}") }
let(:response_should_be_successful) do
response.should look_like({
:status => 200,
:body_exact => node_state_status
})
end

include_context 'handles authentication headers correctly'
end
end
end

0 comments on commit 82f1048

Please sign in to comment.