diff --git a/lib/aws/session_store/dynamo_db/configuration.rb b/lib/aws/session_store/dynamo_db/configuration.rb index bc99285..725dd58 100644 --- a/lib/aws/session_store/dynamo_db/configuration.rb +++ b/lib/aws/session_store/dynamo_db/configuration.rb @@ -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} @@ -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 diff --git a/lib/aws/session_store/dynamo_db/errors/base_handler.rb b/lib/aws/session_store/dynamo_db/errors/base_handler.rb index 5abff83..21687ca 100644 --- a/lib/aws/session_store/dynamo_db/errors/base_handler.rb +++ b/lib/aws/session_store/dynamo_db/errors/base_handler.rb @@ -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. diff --git a/lib/aws/session_store/dynamo_db/locking/base.rb b/lib/aws/session_store/dynamo_db/locking/base.rb index 8516f96..c28078a 100644 --- a/lib/aws/session_store/dynamo_db/locking/base.rb +++ b/lib/aws/session_store/dynamo_db/locking/base.rb @@ -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 diff --git a/lib/aws/session_store/dynamo_db/rack_middleware.rb b/lib/aws/session_store/dynamo_db/rack_middleware.rb index 6f4ccec..ff4fb1e 100644 --- a/lib/aws/session_store/dynamo_db/rack_middleware.rb +++ b/lib/aws/session_store/dynamo_db/rack_middleware.rb @@ -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 diff --git a/spec/aws/session_store/dynamo_db/error/default_error_handler_spec.rb b/spec/aws/session_store/dynamo_db/error/default_error_handler_spec.rb index 6bc5b70..e69de29 100644 --- a/spec/aws/session_store/dynamo_db/error/default_error_handler_spec.rb +++ b/spec/aws/session_store/dynamo_db/error/default_error_handler_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5ad30e8..2ee05e9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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" }