Skip to content

Remove expected attributes from deleting session. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/aws/session_store/dynamo_db/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def to_hash
# @return [Hash] DDB client.
def gen_dynamo_db_client
client_opts = client_subset(@options)
client_opts[:user_agent_suffix] = _user_agent(@options.delete(:user_agent_suffix))
client = Aws::DynamoDB::Client
dynamo_db_client = @options[:dynamo_db_client] || client.new(client_opts)
{:dynamo_db_client => dynamo_db_client}
Expand Down Expand Up @@ -294,13 +293,5 @@ def client_subset(options = {})
opts
end
end

def _user_agent(custom)
if custom
custom
else
" aws-sessionstore/#{VERSION}"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/aws/session_store/dynamo_db/errors/base_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BaseHandler
# error up the stack.
# You may reraise the error passed.
#
# @param [Aws::DynamoDB::Errors::Base] error error passed in from
# @param [Aws::DynamoDB::Errors::ServiceError] error error passed in from
# Aws::SessionStore::DynamoDB::RackMiddleware.
# @param [Rack::Request::Environment,nil] env Rack environment
# @return [false] If exception was handled and will not reraise exception.
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/session_store/dynamo_db/locking/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def data_unchanged?(env, session)

# Expected attributes
def expected_attributes(sid)
{ :expected => { @config.table_key => {:value => sid, :exists => true} } }
{ :expected => {@config.table_key => {:value => sid, :exists => true}} }
end

# Attributes to be retrieved via client
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/session_store/dynamo_db/rack_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def destroy_session(env, sid, options)
def handle_error(env = nil, &block)
begin
yield
rescue Aws::DynamoDB::Errors::Base,
rescue Aws::DynamoDB::Errors::ServiceError,
Aws::SessionStore::DynamoDB::InvalidIDError => e
@config.error_handler.handle_error(e, env)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +0,0 @@
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


require 'spec_helper'

describe Aws::SessionStore::DynamoDB do
include Rack::Test::Methods

instance_exec(&ConstantHelpers)

before do
@options = { :dynamo_db_client => client, :secret_key => 'meltingbutter' }
end

let(:base_app) { MultiplierApplication.new }
let(:app) { Aws::SessionStore::DynamoDB::RackMiddleware.new(base_app, @options) }
let(:client) { double('Aws::DynamoDB::Client') }

context "Error handling for Rack Middleware with default error handler" do
it "raises error for missing secret key" do
client.stub(:update_item).and_raise(missing_key_error)
lambda { get "/" }.should raise_error(missing_key_error)
end

it "catches exception for inaccurate table name and raises error " do
client.stub(:update_item).and_raise(resource_error)
lambda { get "/" }.should raise_error(resource_error)
end

it "catches exception for inaccurate table key" do
client.stub(:update_item).and_raise(key_error)
client.stub(:get_item).and_raise(key_error)
get "/"
last_request.env["rack.errors"].string.should include(key_error_msg)
end
end

context "Test ExceptionHandler with true as return value for handle_error" do
it "raises all errors" do
@options[:raise_errors] = true
client.stub(:update_item).and_raise(client_error)
lambda { get "/" }.should raise_error(client_error)
end

it "catches exception for inaccurate table key and raises error" do
@options[:raise_errors] = true
client.stub(:update_item).and_raise(key_error)
lambda { get "/" }.should raise_error(key_error)
end
end
end
10 changes: 2 additions & 8 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,10 @@ def call(env)

ConstantHelpers = lambda do
let(:token_error_msg) { 'The security token included in the request is invalid' }
let(:resource_error) {
Aws::DynamoDB::Errors::ResourceNotFoundException.new(double('Seahorse::Client::RequestContext'), resource_error_msg)
}
let(:resource_error_msg) { 'The Resource is not found.' }
let(:resource_error) { Aws::DynamoDB::Errors::ResourceNotFoundException.new(double('Seahorse::Client::RequestContext'), 'Resource not found.') }
let(:key_error) { Aws::DynamoDB::Errors::ValidationException.new(double('Seahorse::Client::RequestContext'), key_error_msg) }
let(:key_error_msg) { 'The provided key element does not match the schema' }
let(:client_error) {
Aws::DynamoDB::Errors::UnrecognizedClientException.new(double('Seahorse::Client::RequestContext'), client_error_msg)
}
let(:client_error_msg) { 'Unrecognized Client.'}
let(:client_error) { Aws::DynamoDB::Errors::UnrecognizedClientException.new(double('Seahorse::Client::RequestContext'), 'Unrecognized Client.') }
let(:invalid_cookie) { {"HTTP_COOKIE" => "rack.session=ApplePieBlueberries"} }
let(:invalid_session_data) { {"rack.session"=>{"multiplier" => 1}} }
let(:rack_default_error_msg) { "Warning! Aws::SessionStore::DynamoDB failed to save session. Content dropped.\n" }
Expand Down