honkster-attr_encrypted 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ DataMapper.setup(:default, 'sqlite3::memory:')
4
+
5
+ class Client
6
+ include DataMapper::Resource
7
+
8
+ property :id, Serial
9
+ property :encrypted_email, String
10
+ property :encrypted_credentials, Text
11
+ property :salt, String
12
+
13
+ attr_encrypted :email, :key => 'a secret key'
14
+ attr_encrypted :credentials, :key => Proc.new { |client| Encryptor.encrypt(:value => client.salt, :key => 'some private key') }, :marshal => true
15
+
16
+ def initialize(attrs = {})
17
+ super attrs
18
+ self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
19
+ self.credentials ||= { :username => 'example', :password => 'test' }
20
+ end
21
+ end
22
+
23
+ DataMapper.auto_migrate!
24
+
25
+ class DataMapperTest < Test::Unit::TestCase
26
+
27
+ def setup
28
+ Client.all.each(&:destroy)
29
+ end
30
+
31
+ def test_should_encrypt_email
32
+ @client = Client.new :email => 'test@example.com'
33
+ assert @client.save
34
+ assert_not_nil @client.encrypted_email
35
+ assert_not_equal @client.email, @client.encrypted_email
36
+ assert_equal @client.email, Client.first.email
37
+ end
38
+
39
+ def test_should_marshal_and_encrypt_credentials
40
+ @client = Client.new
41
+ assert @client.save
42
+ assert_not_nil @client.encrypted_credentials
43
+ assert_not_equal @client.credentials, @client.encrypted_credentials
44
+ assert_equal @client.credentials, Client.first.credentials
45
+ assert Client.first.credentials.is_a?(Hash)
46
+ end
47
+
48
+ def test_should_encode_by_default
49
+ assert Client.attr_encrypted_options[:encode]
50
+ end
51
+
52
+ end
@@ -0,0 +1,11 @@
1
+ #require File.expand_path('../test_helper', __FILE__)
2
+ #
3
+ #class MongoTest
4
+ # include MongoMapper::Document
5
+ #
6
+ #
7
+ #end
8
+ #
9
+ #class MongoMapperTest < Test::Unit::TestCase
10
+ #
11
+ #end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ DB = Sequel.sqlite
4
+
5
+ DB.create_table :humans do
6
+ primary_key :id
7
+ column :encrypted_email, :string
8
+ column :password, :string
9
+ column :encrypted_credentials, :string
10
+ column :salt, :string
11
+ end
12
+
13
+ class Human < Sequel::Model(:humans)
14
+ attr_encrypted :email, :key => 'a secret key'
15
+ attr_encrypted :credentials, :key => Proc.new { |human| Encryptor.encrypt(:value => human.salt, :key => 'some private key') }, :marshal => true
16
+
17
+ def after_initialize(attrs = {})
18
+ self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
19
+ self.credentials ||= { :username => 'example', :password => 'test' }
20
+ end
21
+ end
22
+
23
+ class SequelTest < Test::Unit::TestCase
24
+
25
+ def setup
26
+ Human.all.each(&:destroy)
27
+ end
28
+
29
+ def test_should_encrypt_email
30
+ @human = Human.new :email => 'test@example.com'
31
+ assert @human.save
32
+ assert_not_nil @human.encrypted_email
33
+ assert_not_equal @human.email, @human.encrypted_email
34
+ assert_equal @human.email, Human.first.email
35
+ end
36
+
37
+ def test_should_marshal_and_encrypt_credentials
38
+ @human = Human.new
39
+ assert @human.save
40
+ assert_not_nil @human.encrypted_credentials
41
+ assert_not_equal @human.credentials, @human.encrypted_credentials
42
+ assert_equal @human.credentials, Human.first.credentials
43
+ assert Human.first.credentials.is_a?(Hash)
44
+ end
45
+
46
+ def test_should_encode_by_default
47
+ assert Human.attr_encrypted_options[:encode]
48
+ end
49
+
50
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require :development
5
+ Bundler.require :default
6
+
7
+ require 'test/unit'
8
+ require 'digest/sha2'
9
+
10
+ puts "\nTesting with ActiveRecord #{ActiveRecord::VERSION::STRING rescue ENV['ACTIVE_RECORD_VERSION']}"
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honkster-attr_encrypted
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.2.0
6
+ platform: ruby
7
+ authors:
8
+ - Sean Huber
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-23 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: encryptor
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 1.1.3
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Generates attr_accessors that encrypt and decrypt attributes transparently
28
+ email: shuber@huberry.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/attr_encrypted/version.rb
37
+ - lib/attr_encrypted/adapters/mongo_mapper.rb
38
+ - lib/attr_encrypted/adapters/sequel.rb
39
+ - lib/attr_encrypted/adapters/active_record.rb
40
+ - lib/attr_encrypted/adapters/data_mapper.rb
41
+ - lib/attr_encrypted.rb
42
+ - MIT-LICENSE
43
+ - Rakefile
44
+ - README.rdoc
45
+ - test/data_mapper_test.rb
46
+ - test/mongo_mapper_test.rb
47
+ - test/sequel_test.rb
48
+ - test/test_helper.rb
49
+ - test/attr_encrypted_test.rb
50
+ - test/active_record_test.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/shuber/attr_encrypted
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --line-numbers
58
+ - --inline-source
59
+ - --main
60
+ - README.rdoc
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.5.2
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Encrypt and decrypt attributes
82
+ test_files:
83
+ - test/data_mapper_test.rb
84
+ - test/mongo_mapper_test.rb
85
+ - test/sequel_test.rb
86
+ - test/test_helper.rb
87
+ - test/attr_encrypted_test.rb
88
+ - test/active_record_test.rb