summaryrefslogtreecommitdiff
path: root/spec/unit/rest_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/rest_spec.rb')
-rw-r--r--spec/unit/rest_spec.rb98
1 files changed, 49 insertions, 49 deletions
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index 3ecbbd14b8..ba5f837c07 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -19,10 +19,10 @@
# limitations under the License.
#
-require 'spec_helper'
-require 'uri'
-require 'net/https'
-require 'stringio'
+require "spec_helper"
+require "uri"
+require "net/https"
+require "stringio"
SIGNING_KEY_DOT_PEM="-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA49TA0y81ps0zxkOpmf5V4/c4IeR5yVyQFpX3JpxO4TquwnRh
@@ -69,8 +69,8 @@ describe Chef::REST do
rest
end
- let(:standard_read_headers) {{"Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
- let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
+ let(:standard_read_headers) {{"Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
+ let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
before(:each) do
Chef::Log.init(log_stringio)
@@ -92,7 +92,7 @@ describe Chef::REST do
Chef::REST.new(base_url, nil, nil, options)
end
- context 'when created with a chef zero URL' do
+ context "when created with a chef zero URL" do
let(:url) { "chefzero://localhost:1" }
@@ -115,12 +115,12 @@ describe Chef::REST do
with(:GET, monkey_uri, standard_read_headers, false).
and_return([1,2,3])
expect(rest).to receive(:apply_response_middleware).with(1,2,3).and_return([1,2,3])
- expect(rest).to receive('success_response?'.to_sym).with(1).and_return(true)
+ expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
rest.get_rest("monkey")
end
it "makes a :GET reqest for a streaming download with the composed url" do
- expect(rest).to receive(:streaming_request).with('monkey', {})
+ expect(rest).to receive(:streaming_request).with("monkey", {})
rest.get_rest("monkey", true)
end
@@ -129,7 +129,7 @@ describe Chef::REST do
with(:DELETE, monkey_uri, standard_read_headers, false).
and_return([1,2,3])
expect(rest).to receive(:apply_response_middleware).with(1,2,3).and_return([1,2,3])
- expect(rest).to receive('success_response?'.to_sym).with(1).and_return(true)
+ expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
rest.delete_rest("monkey")
end
@@ -138,7 +138,7 @@ describe Chef::REST do
with(:POST, monkey_uri, standard_write_headers, "\"data\"").
and_return([1,2,3])
expect(rest).to receive(:apply_response_middleware).with(1,2,3).and_return([1,2,3])
- expect(rest).to receive('success_response?'.to_sym).with(1).and_return(true)
+ expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
rest.post_rest("monkey", "data")
end
@@ -147,7 +147,7 @@ describe Chef::REST do
with(:PUT, monkey_uri, standard_write_headers, "\"data\"").
and_return([1,2,3])
expect(rest).to receive(:apply_response_middleware).with(1,2,3).and_return([1,2,3])
- expect(rest).to receive('success_response?'.to_sym).with(1).and_return(true)
+ expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
rest.put_rest("monkey", "data")
end
end
@@ -162,11 +162,11 @@ describe Chef::REST do
Chef::Config[:client_key] = CHEF_SPEC_DATA + "/ssl/private_key.pem"
end
- it 'responds to raw_http_request as a public method' do
+ it "responds to raw_http_request as a public method" do
expect(rest.public_methods.map(&:to_s)).to include("raw_http_request")
end
- it 'calls the authn middleware' do
+ it "calls the authn middleware" do
data = "\"secure data\""
auth_headers = standard_write_headers.merge({"auth_done"=>"yep"})
@@ -177,18 +177,18 @@ describe Chef::REST do
expect(rest).to receive(:send_http_request).
with(:POST, monkey_uri, auth_headers, data).
and_return([1,2,3])
- expect(rest).to receive('success_response?'.to_sym).with(1).and_return(true)
+ expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
rest.raw_http_request(:POST, monkey_uri, standard_write_headers, data)
end
- it 'sets correct authn headers' do
+ it "sets correct authn headers" do
data = "\"secure data\""
method, uri, auth_headers, d = rest.authenticator.handle_request(:POST, monkey_uri, standard_write_headers, data)
expect(rest).to receive(:send_http_request).
with(:POST, monkey_uri, auth_headers, data).
and_return([1,2,3])
- expect(rest).to receive('success_response?'.to_sym).with(1).and_return(true)
+ expect(rest).to receive("success_response?".to_sym).with(1).and_return(true)
rest.raw_http_request(:POST, monkey_uri, standard_write_headers, data)
end
end
@@ -287,12 +287,12 @@ describe Chef::REST do
let(:base_headers) do #FIXME: huh?
{
- 'Accept' => 'application/json',
- 'X-Chef-Version' => Chef::VERSION,
- 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
- 'Host' => host_header,
- 'X-REMOTE-REQUEST-ID' => request_id,
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
+ "Accept" => "application/json",
+ "X-Chef-Version" => Chef::VERSION,
+ "Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
+ "Host" => host_header,
+ "X-REMOTE-REQUEST-ID" => request_id,
+ "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
}
end
@@ -314,7 +314,7 @@ describe Chef::REST do
# XXX: must reset to default b/c knife changes the UA
Chef::REST::RESTRequest.user_agent = Chef::REST::RESTRequest::DEFAULT_UA
rest.request(:GET, url, {})
- expect(request_mock['User-Agent']).to match(/^Chef Client\/#{Chef::VERSION}/)
+ expect(request_mock["User-Agent"]).to match(/^Chef Client\/#{Chef::VERSION}/)
end
# CHEF-3140
@@ -340,8 +340,8 @@ describe Chef::REST do
context "when configured with custom http headers" do
let(:custom_headers) do
{
- 'X-Custom-ChefSecret' => 'sharpknives',
- 'X-Custom-RequestPriority' => 'extremely low',
+ "X-Custom-ChefSecret" => "sharpknives",
+ "X-Custom-RequestPriority" => "extremely low",
}
end
@@ -371,7 +371,7 @@ describe Chef::REST do
end
it "should set the cookie for this request if one exists for the given host:port" do
- expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", base_headers.merge('Cookie' => "cookie monster")).and_return(request_mock)
+ expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", base_headers.merge("Cookie" => "cookie monster")).and_return(request_mock)
rest.request(:GET, url, {})
end
end
@@ -383,7 +383,7 @@ describe Chef::REST do
it "should build a new HTTP POST request" do
request = Net::HTTP::Post.new(url.path)
- expected_headers = base_headers.merge("Content-Type" => 'application/json', 'Content-Length' => '13')
+ expected_headers = base_headers.merge("Content-Type" => "application/json", "Content-Length" => "13")
expect(Net::HTTP::Post).to receive(:new).with("/?foo=bar", expected_headers).and_return(request)
rest.request(:POST, url, {}, {:one=>:two})
@@ -392,7 +392,7 @@ describe Chef::REST do
it "should build a new HTTP PUT request" do
request = Net::HTTP::Put.new(url.path)
- expected_headers = base_headers.merge("Content-Type" => 'application/json', 'Content-Length' => '13')
+ expected_headers = base_headers.merge("Content-Type" => "application/json", "Content-Length" => "13")
expect(Net::HTTP::Put).to receive(:new).with("/?foo=bar",expected_headers).and_return(request)
rest.request(:PUT, url, {}, {:one=>:two})
expect(request.body).to eq('{"one":"two"}')
@@ -419,12 +419,12 @@ describe Chef::REST do
context "when JSON is returned" do
let(:body) { '{"ohai2u":"json_api"}' }
it "should inflate the body as to an object" do
- http_response.add_field('content-type', "application/json")
+ http_response.add_field("content-type", "application/json")
expect(rest.request(:GET, url, {})).to eq({"ohai2u"=>"json_api"})
end
it "should fail if the response is truncated" do
- http_response.add_field('content-type', "application/json")
+ http_response.add_field("content-type", "application/json")
http_response["Content-Length"] = (body.bytesize + 99).to_s
expect { rest.request(:GET, url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
end
@@ -486,7 +486,7 @@ describe Chef::REST do
allow(rest).to receive(:sleep)
expect {rest.request(:GET, url)}.to raise_error(Net::HTTPFatalError)
- expect(log_stringio.string).to match(Regexp.escape('INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
+ expect(log_stringio.string).to match(Regexp.escape("INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four"))
end
end
@@ -511,7 +511,7 @@ describe Chef::REST do
it "decompresses the JSON error message" do
expect {rest.request(:GET, url)}.to raise_error(Net::HTTPFatalError)
- expect(log_stringio.string).to match(Regexp.escape('INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four'))
+ expect(log_stringio.string).to match(Regexp.escape("INFO: HTTP Request Returned 500 drooling from inside of mouth: Ears get sore!, Not even four"))
end
it "fails when the compressed body is truncated" do
@@ -544,7 +544,7 @@ describe Chef::REST do
let(:request_mock) { {} }
let(:http_response) do
- http_response = Net::HTTPSuccess.new("1.1",'200', "it-works")
+ http_response = Net::HTTPSuccess.new("1.1","200", "it-works")
allow(http_response).to receive(:read_body)
expect(http_response).not_to receive(:body)
@@ -570,24 +570,24 @@ describe Chef::REST do
end
it " build a new HTTP GET request without the application/json accept header" do
- expected_headers = {'Accept' => "*/*",
- 'X-Chef-Version' => Chef::VERSION,
- 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
- 'Host' => host_header,
- 'X-REMOTE-REQUEST-ID'=> request_id,
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
+ expected_headers = {"Accept" => "*/*",
+ "X-Chef-Version" => Chef::VERSION,
+ "Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
+ "Host" => host_header,
+ "X-REMOTE-REQUEST-ID"=> request_id,
+ "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
}
expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
rest.streaming_request(url, {})
end
it "build a new HTTP GET request with the X-Remote-Request-Id header" do
- expected_headers = {'Accept' => "*/*",
- 'X-Chef-Version' => Chef::VERSION,
- 'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
- 'Host' => host_header,
- 'X-REMOTE-REQUEST-ID'=> request_id,
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
+ expected_headers = {"Accept" => "*/*",
+ "X-Chef-Version" => Chef::VERSION,
+ "Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
+ "Host" => host_header,
+ "X-REMOTE-REQUEST-ID"=> request_id,
+ "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION,
}
expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
rest.streaming_request(url, {})
@@ -622,13 +622,13 @@ describe Chef::REST do
end
it "does not raise a divide by zero exception if the content's actual size is 0" do
- http_response['Content-Length'] = "5"
- allow(http_response).to receive(:read_body).and_yield('')
+ http_response["Content-Length"] = "5"
+ allow(http_response).to receive(:read_body).and_yield("")
expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
end
it "does not raise a divide by zero exception when the Content-Length is 0" do
- http_response['Content-Length'] = "0"
+ http_response["Content-Length"] = "0"
allow(http_response).to receive(:read_body).and_yield("ninja")
expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch)
end