cirandas.net

ref: master

vendor/ezcrypto/test/key_holder_test.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$:.unshift(File.dirname(__FILE__) + "/../lib/")
require_relative '../test_helper'
require 'active_crypto'

class KeyHolderSubject
  include ActiveCrypto::KeyHolder
end

class KeyHolderTest < Test::Unit::TestCase

  attr :key_holder

  def setup
    @key_holder=KeyHolderSubject.new
  end

  def test_session_key_should_not_be_set_on_new
    assert_nil key_holder.session_key
  end

  def test_set_session_key_should_set_session_key
    key=EzCrypto::Key.generate
    key_holder.set_session_key key
    assert_not_nil key_holder.session_key
    assert_equal key.raw,key_holder.session_key.raw
  end

  def test_set_encoded_key_should_set_session_key
    key=EzCrypto::Key.generate
    key_holder.set_encoded_key key.encode
    assert_not_nil key_holder.session_key
    assert_equal key.raw,key_holder.session_key.raw
  end

  def test_enter_password_should_set_session_key
    key=EzCrypto::Key.with_password "test","onetwothree"
    key_holder.enter_password "test"
    assert_not_nil key_holder.session_key
    assert_equal key.raw,key_holder.session_key.raw
  end


end