Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed out how encrypted data is stored, added tests, docs
- Loading branch information
Showing
14 changed files
with
243 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
3-25-2009 | ||
== 3-26-2009 | ||
|
||
* Changed how encrypted data is saved, now put on separate column in the same table as encrypted model | ||
* Added tests | ||
* Can configure name of encrypted column | ||
* Added documentation | ||
* Log warning if default sample keys are being used while in production mode | ||
|
||
|
||
== 3-25-2009 | ||
|
||
* Initial build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
|
||
namespace :gem do | ||
|
||
task :default => :build | ||
|
||
desc 'Build the acts_as_encryptable gem' | ||
task :build do | ||
Dir['*.gem'].each do |gem_filename| | ||
sh "rm -rf #{gem_filename}" | ||
end | ||
sh "gem build acts_as_encryptable.gemspec" | ||
end | ||
|
||
desc 'Install the acts_as_encryptable gem' | ||
task :install do | ||
gem_filename = Dir['*.gem'].first | ||
sh "sudo gem install --local #{gem_filename}" | ||
end | ||
|
||
end | ||
|
||
task :default => ['gem:build', 'gem:install'] | ||
task :default => ['gem:build', 'gem:install'] | ||
|
||
namespace :test do | ||
Rake::TestTask.new(:unit) do |t| | ||
t.libs << 'test' | ||
t.pattern = 'test/unit/*_test.rb' | ||
t.verbose = true | ||
end | ||
end | ||
|
||
task :test do | ||
Rake::Task['test:unit'].invoke | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 21 additions & 3 deletions
24
generators/acts_as_encryptable_migration/acts_as_encryptable_migration_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
class ActsAsEncryptableMigrationGenerator < Rails::Generator::Base | ||
def manifest | ||
class ActsAsEncryptableMigrationGenerator < Rails::Generator::NamedBase | ||
def manifest | ||
record do |m| | ||
m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "acts_as_encryptable_migration" | ||
m.migration_template 'migration:migration.rb', 'db/migrate', { | ||
:assigns => migration_local_assigns, | ||
:migration_file_name => "add_encryption_field_to_#{model_name}" | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def model_name | ||
return ARGV.first | ||
end | ||
|
||
def migration_local_assigns | ||
returning(assigns = {}) do | ||
assigns[:migration_action] = "add" | ||
assigns[:class_name] = "add_encryption_field_to_#{model_name}" | ||
assigns[:table_name] = model_name | ||
assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new("encrypted", "text")] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
require 'acts_as_encryptable/base' | ||
require 'acts_as_encryptable/crypto' | ||
require 'acts_as_encryptable/encrypted_chunk' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ def key_type | |
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'rubygems' | ||
require 'test/unit' | ||
require 'activerecord' | ||
|
||
ENV['RAILS_ENV'] = 'test' | ||
require File.dirname(__FILE__) + '/../lib/acts_as_encryptable' | ||
|
||
class Test::Unit::TestCase | ||
|
||
def establish_connection(db_file = nil) | ||
db_file = File.join(File.dirname(__FILE__), '/tmp/tests.sqlite') unless db_file | ||
ActiveRecord::Base.configurations = { 'ActiveRecord::Base' => { :adapter => 'sqlite3', :database => db_file, :timeout => 5000 } } | ||
ActiveRecord::Base.establish_connection('ActiveRecord::Base') | ||
ActiveRecord::Base.connection.execute('drop table if exists credit_cards') | ||
ActiveRecord::Base.connection.execute('create table credit_cards (id integer, encrypted text)') | ||
ActiveRecord::Base.connection.execute('drop table if exists people') | ||
ActiveRecord::Base.connection.execute('create table people (id integer, important_data text)') | ||
ActiveRecord::Base.connection | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require File.dirname(__FILE__) + '/../test_helper' | ||
|
||
class BaseTest < Test::Unit::TestCase | ||
|
||
class CreditCard < ActiveRecord::Base | ||
attr_accessor :name_on_card, :number, :expiration | ||
acts_as_encryptable :name_on_card, :number, :expiration | ||
end | ||
|
||
class Person < ActiveRecord::Base | ||
attr_accessor :first_name, :last_name, :ssn | ||
acts_as_encryptable :first_name, :last_name, :ssn, :column => 'important_data' | ||
end | ||
|
||
def setup | ||
@connection = establish_connection | ||
end | ||
|
||
def test_a_credit_card | ||
card = CreditCard.new(valid_credit_card) | ||
assert card.save | ||
end | ||
|
||
def test_data_is_encrypted | ||
test_a_credit_card | ||
card = CreditCard.last | ||
assert !card.name_on_card | ||
assert !card.number | ||
assert !card.expiration | ||
end | ||
|
||
def test_data_is_decrypted | ||
test_a_credit_card | ||
card = CreditCard.last | ||
card.decrypt! | ||
assert card.name_on_card == valid_credit_card[:name_on_card] | ||
assert card.number == valid_credit_card[:number] | ||
assert card.expiration == valid_credit_card[:expiration] | ||
end | ||
|
||
def test_set_encrypted_column_name | ||
person = Person.new(valid_person) | ||
assert person.save! | ||
person = Person.last | ||
person.decrypt! | ||
assert person.first_name = valid_person[:first_name] | ||
assert person.last_name = valid_person[:last_name] | ||
assert person.ssn = valid_person[:ssn] | ||
end | ||
|
||
private | ||
|
||
def valid_credit_card | ||
{ | ||
:name_on_card => 'Test User', | ||
:number => '1234567890123456', | ||
:expiration => (Date.today + 1.year).strftime("%i/%y") | ||
} | ||
end | ||
|
||
def valid_person | ||
{ | ||
:first_name => 'Test', | ||
:last_name => 'User', | ||
:ssn => '111223333' | ||
} | ||
end | ||
|
||
end |
Oops, something went wrong.