Thursday, November 12, 2009

MySecrets


I developed MySecrets to manages my personal secrets/passwords. I had a lot of fun doing BDD with cucumber. Pickle works very nicely with Machinist to reduce step definition code. I used authlogic for authentication and formtastic to reduce the boiler plate code in my views.

I had some trouble integrating cucumber, pickle, machinist, and authlogic. A user has 0 to many secrets and secrets are protected by authlogic. So cucumber features that needed to add secrets and validate them were a little tricky.

This scenario creates a user, login in, creates a secret, shows the secret, and finally validates the secret.
Scenario: Show Secret
Given a user exists with username: "myuser", password: "secret", password_confirmation: "secret"
And a secret exists with user: the user
And the user is logged in with myuser/secret
When I go to the show page for that secret
Then I should see the secret
view raw gistfile1.rb hosted with ❤ by GitHub


The show pages are handled with a polymorphic_path.
when /the show page for (.+)/
polymorphic_path(model($1))
view raw paths.rb hosted with ❤ by GitHub


The actual user creation and login steps are handled here.
module UserHelpers
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
end
World(UserHelpers)
def do_login(uname, pw)
visit '/login'
fill_in("username", :with => uname)
fill_in("Password", :with => pw)
click_button("Log in")
end
When /^I login with (.+)$/ do |unamepw|
split = unamepw.split(/\//)
do_login(split[0], split[1])
end
view raw user_steps.rb hosted with ❤ by GitHub


The secret is validated with:
Then /^I should see the secret$/ do
secret = model('secret')
response.should contain(secret.title)
response.should contain(secret.user_name)
response.should contain(secret.url)
response.should contain(secret.label)
end
view raw secret_step.rb hosted with ❤ by GitHub


All of the coded can be found at http://github.com/perry3819/mysecrets

Labels: , ,


pwfoo - Ruby Gem

pwfoo is a gemcutter.org hosted gem that I developed to generate random passwords, score the strength of passwords, and generate random seeds.

Generate password
# get ready to generate passwords of length *12* with lower case letters and numbers
generate_password = PwFoo::GeneratePassword.new(12, PwFoo::GeneratePassword.LOWER_CASE, PwFoo::GeneratePassword.NUMBERS )
# generate password with a minimum strength score of 80
my_new_password = generate_password.generate_with_min_strength 80
# generate password with a minimum strength score of 100
my_new_password = generate_password.generate_with_min_strength 100
view raw gen_pw.rb hosted with ❤ by GitHub


Determine password strength
my_pw = 'secret'
my_pw_score = PwFoo::PasswordStrength.new.calculate_score(my_pw)
view raw score_pw.rb hosted with ❤ by GitHub


The SrandSeedGenerator is interesting because it uses the current time and currently running processes to generate random seeds.
# = srand_seed_generator.rb - Random seed generator uses the system time and currently running processes to generate a highly random seed.
#
# Perry Hertler mailto:perry@hertler.org
#
# == Example
#
# my_seed = PwFoo::SrandSeedGenerator.new.get_next_seed
module PwFoo
require 'digest/md5'
class SrandSeedGenerator
def initialize
end
def get_next_seed
time_in_micro = Time.new().to_f * 100000
checksum = _get_checksum
time_in_micro * time_in_micro + checksum.to_i
end
def _get_checksum
Digest::MD5.hexdigest(`ps axww | gzip`)
end
end
end


pwfoo can be installed from gemcutter.org.
$ sudo gem install gemcutter
$ gem tumble
$ sudo gem install pwfoo
view raw gistfile1.sh hosted with ❤ by GitHub

Labels: ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]