diff --git a/CHANGELOG.md b/CHANGELOG.md index 57829da..10311ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 3.2.3 (Next) +* [#57](https://github.com/mongoid/mongo_session_store/pull/57): Cover legacy session decoding and version loading, and fix private decoder delegation in the plain-driver adapter - [@dblock](https://github.com/dblock). * [#55](https://github.com/mongoid/mongo_session_store/pull/55): Add explicit bulk stale-session cleanup with an application-selected cutoff for both adapters - [@dblock](https://github.com/dblock). * [#54](https://github.com/mongoid/mongo_session_store/pull/54): Document and test storing permitted parameter hashes rather than request-bearing Rails parameter objects in sessions - [@dblock](https://github.com/dblock). * [#53](https://github.com/mongoid/mongo_session_store/pull/53): Cover Rails 6.1 through 8.0 in CI, update RuboCop, isolate Danger permissions, and report both adapters' coverage to Coveralls - [@dblock](https://github.com/dblock). diff --git a/gemfiles/rails-current-mongo.gemfile b/gemfiles/rails-current-mongo.gemfile index 4290326..9d39e9e 100644 --- a/gemfiles/rails-current-mongo.gemfile +++ b/gemfiles/rails-current-mongo.gemfile @@ -11,5 +11,6 @@ gem "drb" gem "base64" gem "benchmark" gem "ostruct" +gem "simplecov", "~> 0.22", :require => false if ENV["COVERAGE"] == "true" gemspec :path => "../" diff --git a/lib/mongo_session_store/mongo_store.rb b/lib/mongo_session_store/mongo_store.rb index 77e43f3..f2b0f76 100644 --- a/lib/mongo_session_store/mongo_store.rb +++ b/lib/mongo_session_store/mongo_store.rb @@ -92,7 +92,7 @@ def pack(data) end def unpack(packed) - self.class.unpack(packed) + self.class.send(:unpack, packed) end end end diff --git a/spec/lib/mongo_session_store/legacy_serialization_spec.rb b/spec/lib/mongo_session_store/legacy_serialization_spec.rb new file mode 100644 index 0000000..b8daebd --- /dev/null +++ b/spec/lib/mongo_session_store/legacy_serialization_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe "Legacy session serialization" do + let(:session_class) { mongo_orm == "mongoid" ? MongoidStore::Session : MongoStore::Session } + + it "reads raw marshalled strings as well as BSON binary data" do + payload = { "nested" => { "count" => 2 }, "tags" => %w[old session] } + session = session_class.new + + expect(session.send(:unpack, Marshal.dump(payload))).to eq(payload) + expect(session.send(:unpack, BSON::Binary.new(Marshal.dump(payload), :generic))).to eq(payload) + end + + it "returns nil when there is no serialized payload" do + expect(session_class.new.send(:unpack, nil)).to be_nil + end +end diff --git a/spec/lib/mongo_session_store/version_spec.rb b/spec/lib/mongo_session_store/version_spec.rb new file mode 100644 index 0000000..581d0d9 --- /dev/null +++ b/spec/lib/mongo_session_store/version_spec.rb @@ -0,0 +1,13 @@ +require "spec_helper" + +describe "Version entry point" do + it "defines a frozen semantic version when loaded on its own" do + hide_const("MongoSessionStore::VERSION") + load File.expand_path("../../../lib/mongo_session_store/version.rb", __dir__) + + expect(MongoSessionStore::VERSION).to match(/\A\d+\.\d+\.\d+\z/) + expect(MongoSessionStore::VERSION).to be_frozen + ensure + MongoSessionStore.send(:remove_const, :VERSION) if MongoSessionStore.const_defined?(:VERSION) + end +end