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.
The show pages are handled with a polymorphic_path.
The actual user creation and login steps are handled here.
The secret is validated with:
All of the coded can be found at http://github.com/perry3819/mysecrets
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.
This file contains hidden or 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
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 |
The show pages are handled with a polymorphic_path.
This file contains hidden or 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
when /the show page for (.+)/ | |
polymorphic_path(model($1)) |
The actual user creation and login steps are handled here.
This file contains hidden or 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
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 |
The secret is validated with:
This file contains hidden or 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
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 |
All of the coded can be found at http://github.com/perry3819/mysecrets
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
Determine password strength
The SrandSeedGenerator is interesting because it uses the current time and currently running processes to generate random seeds.
pwfoo can be installed from gemcutter.org.
Generate password
This file contains hidden or 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
# 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 | |
Determine password strength
This file contains hidden or 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
my_pw = 'secret' | |
my_pw_score = PwFoo::PasswordStrength.new.calculate_score(my_pw) |
The SrandSeedGenerator is interesting because it uses the current time and currently running processes to generate random seeds.
This file contains hidden or 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
# = 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.
This file contains hidden or 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
$ sudo gem install gemcutter | |
$ gem tumble | |
$ sudo gem install pwfoo |
Subscribe to Posts [Atom]