Sha256: f5e9220f84449efcc1b459d5efe636661d5a63cc9fc7ed1bf0ef46afc47b06ed

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

require_relative "spec_helper"

module Nyara
  describe Session do
    context "no cipher" do
      before :all do
        Config['session', 'cipher_key'] = nil
        Session.init
      end

      it "should encode and decode" do
        cookie = {}
        session = {'hello' => 'world'}
        Session.encode session, cookie

        assert_includes cookie[Session.name], 'world'

        session2 = Session.decode cookie
        assert_equal 'world', session2[:hello]
      end

      it "drops bad signature" do
        cookie = {}
        session = {'hello' => 'world'}
        Session.encode session, cookie

        cookie[Session.name].sub!(/\w/, &:swapcase)

        session = Session.decode cookie
        assert_empty session
      end
    end

    context "with cipher" do
      before :all do
        Config['session', 'cipher_key'] = "some cipher key"
        Session.init
      end

      it "encode and decode" do
        cookie = {}
        session = {'hello' => 'world'}
        Session.encode session, cookie

        assert_not_includes cookie[Session.name], 'world'

        session2 = Session.decode cookie
        assert_equal 'world', session2[:hello]
      end

      it "cipher should not be pure" do
        message = 'OCB is by far the best mode, as it allows encryption and authentication in a single pass. However there are patents on it in USA.'
        r1 = Session.cipher message
        r2 = Session.cipher message
        assert_not_equal r1, r2
      end

      it "decipher returns blank str when message too short" do
        r = Session.decipher Base64.urlsafe_encode64 'short one'
        assert_empty r
        r = Session.decipher Base64.urlsafe_encode64 's' * (256/8)
        assert_empty r
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nyara-0.0.1.pre.5 spec/session_spec.rb
nyara-0.0.1.pre.4 spec/session_spec.rb
nyara-0.0.1.pre.3 spec/session_spec.rb
nyara-0.0.1.pre.2 spec/session_spec.rb
nyara-0.0.1.pre.1 spec/session_spec.rb
nyara-0.0.1.pre spec/session_spec.rb