spec/rack_spec.rb in ey-hmac-1.0.0 vs spec/rack_spec.rb in ey-hmac-2.0.0
- old
+ new
@@ -14,68 +14,68 @@
"rack.input" => StringIO.new("{1: 2}"),
"HTTP_CONTENT_TYPE" => "application/json",
)
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
- request.env['HTTP_AUTHORIZATION'].should start_with("EyHmac")
- request.env['HTTP_CONTENT_DIGEST'].should == Digest::MD5.hexdigest(request.body.tap(&:rewind).read)
- Time.parse(request.env['HTTP_DATE']).should_not be_nil
+ expect(request.env['HTTP_AUTHORIZATION']).to start_with("EyHmac")
+ expect(request.env['HTTP_CONTENT_DIGEST']).to eq(Digest::MD5.hexdigest(request.body.tap(&:rewind).read))
+ expect(Time.parse(request.env['HTTP_DATE'])).not_to be_nil
yielded = false
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
- key_id.should == key_id
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
+ expect(key_id).to eq(key_id)
yielded = true
key_secret
- end.should be_true
+ end).to be_truthy
- yielded.should be_true
+ expect(yielded).to be_truthy
end
it "should not set Content-Digest if body is nil" do
request = Rack::Request.new(
"HTTP_CONTENT_TYPE" => "application/json",
)
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
- request.env['HTTP_AUTHORIZATION'].should start_with("EyHmac")
- request.env.should_not have_key('HTTP_CONTENT_DIGEST')
- Time.parse(request.env['HTTP_DATE']).should_not be_nil
+ expect(request.env['HTTP_AUTHORIZATION']).to start_with("EyHmac")
+ expect(request.env).not_to have_key('HTTP_CONTENT_DIGEST')
+ expect(Time.parse(request.env['HTTP_DATE'])).not_to be_nil
yielded = false
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
- key_id.should == key_id
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
+ expect(key_id).to eq(key_id)
yielded = true
key_secret
- end.should be_true
+ end).to be_truthy
- yielded.should be_true
+ expect(yielded).to be_truthy
end
it "should not set Content-Digest if body is empty" do
request = Rack::Request.new(
"rack.input" => StringIO.new(""),
"HTTP_CONTENT_TYPE" => "application/json",
)
Ey::Hmac.sign!(request, key_id, key_secret, adapter: adapter)
- request.env['HTTP_AUTHORIZATION'].should start_with("EyHmac")
- request.env.should_not have_key('HTTP_CONTENT_DIGEST')
- Time.parse(request.env['HTTP_DATE']).should_not be_nil
+ expect(request.env['HTTP_AUTHORIZATION']).to start_with("EyHmac")
+ expect(request.env).not_to have_key('HTTP_CONTENT_DIGEST')
+ expect(Time.parse(request.env['HTTP_DATE'])).not_to be_nil
yielded = false
- Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
- key_id.should == key_id
+ expect(Ey::Hmac.authenticated?(request, adapter: adapter) do |key_id|
+ expect(key_id).to eq(key_id)
yielded = true
key_secret
- end.should be_true
+ end).to be_truthy
- yielded.should be_true
+ expect(yielded).to be_truthy
end
context "with a request" do
let(:request) {
Rack::Request.new(
@@ -101,11 +101,11 @@
client = Rack::Client.new do
use Ey::Hmac::Rack, _key_id, _key_secret, sign_with: :sha1
run app
end
- client.get("/resource").status.should == 200
+ expect(client.get("/resource").status).to eq(200)
end
it "should accept a SHA256 signature" do # default
app = lambda do |env|
authenticated = Ey::Hmac.authenticated?(env, adapter: Ey::Hmac::Adapter::Rack) do |auth_id|
@@ -118,11 +118,11 @@
client = Rack::Client.new do
use Ey::Hmac::Rack, _key_id, _key_secret
run app
end
- client.get("/resource").status.should == 200
+ expect(client.get("/resource").status).to eq(200)
end
it "should accept multiple digest signatures" do # default
require 'ey-hmac/faraday'
Bundler.require(:rack)
@@ -132,15 +132,14 @@
(auth_id == key_id) && key_secret
end
[(authenticated ? 200 : 401), {"Content-Type" => "text/plain"}, []]
end
- request_env = nil
connection = Faraday.new do |c|
- c.request :hmac, key_id, key_secret, digest: [:sha1, :sha256]
+ c.use :hmac, key_id, key_secret, digest: [:sha1, :sha256]
c.adapter(:rack, app)
end
- connection.get("/resources").status.should == 200
+ expect(connection.get("/resources").status).to eq(200)
end
end
end