hancock 0.0.6 → 0.0.7
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.
- data/README.md +0 -2
- data/Rakefile +16 -9
- data/{spec/features → features}/sessions.feature +2 -2
- data/{spec/features → features}/signup.feature +0 -1
- data/{spec/features → features}/sso.feature +0 -0
- data/{spec/features → features}/step_definitions/sessions_steps.rb +7 -13
- data/{spec/features → features}/step_definitions/signup_steps.rb +13 -14
- data/{spec/features → features}/step_definitions/sso_steps.rb +1 -2
- data/{spec/features → features}/support/env.rb +11 -3
- data/lib/hancock.rb +7 -7
- data/lib/mailer.rb +155 -0
- data/spec/acceptance/signing_up_spec.rb +0 -40
- data/spec/matchers.rb +3 -1
- data/spec/spec_helper.rb +5 -6
- metadata +58 -18
    
        data/README.md
    CHANGED
    
    | @@ -27,7 +27,6 @@ Your Rackup File | |
| 27 27 | 
             
            ================
         | 
| 28 28 | 
             
                #  thin start -p PORT -R config.ru
         | 
| 29 29 | 
             
                require 'rubygems'
         | 
| 30 | 
            -
                gem 'sinatra', '~>0.9.1.1'
         | 
| 31 30 | 
             
                require 'hancock'
         | 
| 32 31 | 
             
                gem 'atmos-sinatra-ditties', '~>0.0.3'
         | 
| 33 32 | 
             
                require 'sinatra/ditties'
         | 
| @@ -107,7 +106,6 @@ Here's how you setup most frameworks as consumers.  In a production environment | |
| 107 106 |  | 
| 108 107 | 
             
            Possibilities
         | 
| 109 108 | 
             
            =============
         | 
| 110 | 
            -
            * single sign off
         | 
| 111 109 | 
             
            * some kinda awesome [oauth][oauth] hooks
         | 
| 112 110 |  | 
| 113 111 | 
             
            Sponsored By
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -6,7 +6,7 @@ require 'spec/rake/spectask' | |
| 6 6 | 
             
            require 'cucumber/rake/task'
         | 
| 7 7 |  | 
| 8 8 | 
             
            GEM = "hancock"
         | 
| 9 | 
            -
            GEM_VERSION = "0.0. | 
| 9 | 
            +
            GEM_VERSION = "0.0.7"
         | 
| 10 10 | 
             
            AUTHOR = ["Corey Donohoe", "Tim Carey-Smith"]
         | 
| 11 11 | 
             
            EMAIL = [ "atmos@atmos.org", "tim@spork.in" ]
         | 
| 12 12 | 
             
            HOMEPAGE = "http://github.com/atmos/hancock"
         | 
| @@ -25,18 +25,27 @@ spec = Gem::Specification.new do |s| | |
| 25 25 | 
             
              s.homepage = HOMEPAGE
         | 
| 26 26 |  | 
| 27 27 | 
             
              # Uncomment this to add a dependency
         | 
| 28 | 
            -
              s.add_dependency " | 
| 29 | 
            -
              s.add_dependency " | 
| 30 | 
            -
              s.add_dependency " | 
| 31 | 
            -
              s.add_dependency "guid", | 
| 28 | 
            +
              s.add_dependency "ruby-openid",     "~>2.1.4"
         | 
| 29 | 
            +
              s.add_dependency "sinatra",         "~>0.9.2"
         | 
| 30 | 
            +
              s.add_dependency "haml",            "~>2.0.9"
         | 
| 31 | 
            +
              s.add_dependency "guid",            "~>0.1.1"
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              s.add_dependency "dm-core",         "~>0.9.11"
         | 
| 34 | 
            +
              s.add_dependency "dm-types",        "~>0.9.11"
         | 
| 35 | 
            +
              s.add_dependency "dm-timestamps",   "~>0.9.11"
         | 
| 36 | 
            +
              s.add_dependency "dm-validations",  "~>0.9.11"
         | 
| 32 37 |  | 
| 33 38 | 
             
              s.require_path = 'lib'
         | 
| 34 39 | 
             
              s.autorequire = GEM
         | 
| 35 | 
            -
              s.files = %w(LICENSE README.md Rakefile) + Dir.glob("{lib,spec}/**/*")
         | 
| 40 | 
            +
              s.files = %w(LICENSE README.md Rakefile) + Dir.glob("{features,lib,spec}/**/*")
         | 
| 36 41 | 
             
            end
         | 
| 37 42 |  | 
| 38 43 | 
             
            task :default => [:spec, :features]
         | 
| 39 44 |  | 
| 45 | 
            +
            task :development_deps do |t|
         | 
| 46 | 
            +
              system("sudo gem install webrat rack-test do_sqlite3")
         | 
| 47 | 
            +
            end
         | 
| 48 | 
            +
             | 
| 40 49 | 
             
            desc "Run specs"
         | 
| 41 50 | 
             
            Spec::Rake::SpecTask.new do |t|
         | 
| 42 51 | 
             
              t.spec_files = FileList['spec/**/*_spec.rb']
         | 
| @@ -63,10 +72,8 @@ end | |
| 63 72 | 
             
            Cucumber::Rake::Task.new(:features) do |t|
         | 
| 64 73 | 
             
              t.libs << 'lib'
         | 
| 65 74 | 
             
              t.cucumber_opts = "--format pretty"
         | 
| 66 | 
            -
              t.step_list    = 'spec/features/**/*.rb'
         | 
| 67 | 
            -
              t.feature_list = 'spec/features/**/*.feature'
         | 
| 68 75 | 
             
              t.rcov = true
         | 
| 69 76 | 
             
              t.rcov_opts << '--text-summary'
         | 
| 70 77 | 
             
              t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
         | 
| 71 | 
            -
              t.rcov_opts << '--exclude' << '.gem/,spec,examples'
         | 
| 78 | 
            +
              t.rcov_opts << '--exclude' << '.gem/,spec,features,examples'
         | 
| 72 79 | 
             
            end
         | 
| @@ -21,9 +21,9 @@ Feature: Logging In to an SSO Account | |
| 21 21 | 
             
                  When I request authentication
         | 
| 22 22 | 
             
                  Then I should see the login form
         | 
| 23 23 | 
             
                  When I login
         | 
| 24 | 
            -
                  Then I should  | 
| 24 | 
            +
                  Then I should see a list of consumers
         | 
| 25 25 | 
             
                Scenario: logging in with a bad return_to cookie set
         | 
| 26 26 | 
             
                  Given a valid consumer and user exists
         | 
| 27 27 | 
             
                  Then I login
         | 
| 28 28 | 
             
                  When I request the login page
         | 
| 29 | 
            -
                  Then I should  | 
| 29 | 
            +
                  Then I should see a list of consumers
         | 
| 
            File without changes
         | 
| @@ -1,12 +1,13 @@ | |
| 1 1 | 
             
            Given /^a valid consumer and user exists$/ do
         | 
| 2 2 | 
             
              @consumer = ::Hancock::Consumer.gen(:internal)
         | 
| 3 3 | 
             
              @user     = ::Hancock::User.gen
         | 
| 4 | 
            -
              get '/sso/logout'  # log us out if we're logged in
         | 
| 5 4 | 
             
            end
         | 
| 6 5 |  | 
| 7 6 | 
             
            Then /^I login$/ do
         | 
| 8 | 
            -
               | 
| 9 | 
            -
             | 
| 7 | 
            +
              fill_in :email,    :with => @user.email
         | 
| 8 | 
            +
              fill_in :password, :with => @user.password
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              click_button 'Login'
         | 
| 10 11 | 
             
            end
         | 
| 11 12 |  | 
| 12 13 | 
             
            Then /^I should be redirected to the consumer app to start the handshake$/ do
         | 
| @@ -16,21 +17,14 @@ Then /^I should be redirected to the consumer app to start the handshake$/ do | |
| 16 17 | 
             
              redirection.query_values['id'].to_i.should eql(@user.id)
         | 
| 17 18 | 
             
            end
         | 
| 18 19 |  | 
| 19 | 
            -
            Then /^I should be redirected to the sso provider root on login$/ do
         | 
| 20 | 
            -
              last_response.headers['Location'].should eql('/')
         | 
| 21 | 
            -
              follow_redirect!
         | 
| 22 | 
            -
            end
         | 
| 23 | 
            -
             | 
| 24 20 | 
             
            When /^I request the landing page$/ do
         | 
| 25 | 
            -
               | 
| 21 | 
            +
              visit '/'
         | 
| 26 22 | 
             
            end
         | 
| 27 23 |  | 
| 28 24 | 
             
            Then /^I should see a list of consumers$/ do
         | 
| 29 | 
            -
              last_response. | 
| 30 | 
            -
              follow_redirect!
         | 
| 25 | 
            +
              last_response.should have_selector("h3:contains('#{@user.first_name} #{@user.last_name}')")
         | 
| 31 26 | 
             
            end
         | 
| 32 27 |  | 
| 33 28 | 
             
            When /^I request the login page$/ do
         | 
| 34 | 
            -
               | 
| 35 | 
            -
              pp last_response
         | 
| 29 | 
            +
              visit '/sso/login'
         | 
| 36 30 | 
             
            end
         | 
| @@ -2,7 +2,6 @@ Given /^I am not logged in on the sso provider$/ do | |
| 2 2 | 
             
              @user = Hancock::User.new(:email      => /\w+@\w+\.\w{2,3}/.gen.downcase,
         | 
| 3 3 | 
             
                                        :first_name => /\w+/.gen.capitalize,
         | 
| 4 4 | 
             
                                        :last_name  => /\w+/.gen.capitalize)
         | 
| 5 | 
            -
              get "/sso/logout"
         | 
| 6 5 | 
             
            end
         | 
| 7 6 |  | 
| 8 7 | 
             
            Given /^a valid consumer exists$/ do
         | 
| @@ -10,11 +9,11 @@ Given /^a valid consumer exists$/ do | |
| 10 9 | 
             
            end
         | 
| 11 10 |  | 
| 12 11 | 
             
            Given /^I request authentication$/ do
         | 
| 13 | 
            -
               | 
| 12 | 
            +
              visit "/sso/login"
         | 
| 14 13 | 
             
            end
         | 
| 15 14 |  | 
| 16 15 | 
             
            Given /^I request authentication returning to the consumer app$/ do
         | 
| 17 | 
            -
               | 
| 16 | 
            +
              visit "/sso/login?return_to=#{@consumer.url}"
         | 
| 18 17 | 
             
            end
         | 
| 19 18 |  | 
| 20 19 | 
             
            Then /^I should see the login form$/ do
         | 
| @@ -22,7 +21,7 @@ Then /^I should see the login form$/ do | |
| 22 21 | 
             
            end
         | 
| 23 22 |  | 
| 24 23 | 
             
            Given /^I click signup$/ do
         | 
| 25 | 
            -
               | 
| 24 | 
            +
              visit "/sso/signup"
         | 
| 26 25 | 
             
            end
         | 
| 27 26 |  | 
| 28 27 | 
             
            Then /^I should see the signup form$/ do
         | 
| @@ -30,10 +29,11 @@ Then /^I should see the signup form$/ do | |
| 30 29 | 
             
            end
         | 
| 31 30 |  | 
| 32 31 | 
             
            Given /^I signup with valid info$/ do
         | 
| 33 | 
            -
               | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 32 | 
            +
              fill_in :email,      :with => @user.email
         | 
| 33 | 
            +
              fill_in :first_name, :with => @user.first_name
         | 
| 34 | 
            +
              fill_in :last_name,  :with => @user.last_name
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              click_button 'Signup'
         | 
| 37 37 | 
             
            end
         | 
| 38 38 |  | 
| 39 39 | 
             
            Then /^I should receive a registration url via email$/ do
         | 
| @@ -42,13 +42,12 @@ Then /^I should receive a registration url via email$/ do | |
| 42 42 | 
             
            end
         | 
| 43 43 |  | 
| 44 44 | 
             
            Given /^I hit the registration url and provide a password$/ do
         | 
| 45 | 
            -
               | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 45 | 
            +
              visit @confirmation_url
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              fill_in :password,               :with => @user.password
         | 
| 48 | 
            +
              fill_in :password_confirmation,  :with => @user.password
         | 
| 49 49 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
              last_response.headers['Location'].should eql('/')
         | 
| 50 | 
            +
              click_button 'Am I Done Yet?'
         | 
| 52 51 | 
             
            end
         | 
| 53 52 |  | 
| 54 53 | 
             
            Then /^I should be redirected to the consumer app$/ do
         | 
| @@ -1,7 +1,6 @@ | |
| 1 1 | 
             
            When /^I am logged in on the sso provider$/ do
         | 
| 2 2 | 
             
              @identity_url = "http://example.org/sso/users/#{@user.id}"
         | 
| 3 | 
            -
               | 
| 4 | 
            -
                                 :password => @user.password
         | 
| 3 | 
            +
              Then "I login"
         | 
| 5 4 | 
             
            end
         | 
| 6 5 |  | 
| 7 6 | 
             
            When /^I request the sso page with a checkid mode of checkIDSetup$/ do
         | 
| @@ -1,8 +1,6 @@ | |
| 1 | 
            -
            require File.expand_path(File.dirname(__FILE__)+'/../../spec_helper')
         | 
| 1 | 
            +
            require File.expand_path(File.dirname(__FILE__)+'/../../spec/spec_helper')
         | 
| 2 2 | 
             
            require 'haml'
         | 
| 3 3 |  | 
| 4 | 
            -
            Hancock::App.set :environment, :development
         | 
| 5 | 
            -
             | 
| 6 4 | 
             
            World do
         | 
| 7 5 | 
             
              def app
         | 
| 8 6 | 
             
                @app = Rack::Builder.new do
         | 
| @@ -14,3 +12,13 @@ World do | |
| 14 12 | 
             
              include Webrat::Matchers
         | 
| 15 13 | 
             
              include Hancock::Matchers
         | 
| 16 14 | 
             
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            class Webrat::Field
         | 
| 17 | 
            +
              def escaped_value
         | 
| 18 | 
            +
                @value.to_s
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            Before do
         | 
| 23 | 
            +
              visit '/sso/logout'  # log us out if we're logged in
         | 
| 24 | 
            +
            end
         | 
    
        data/lib/hancock.rb
    CHANGED
    
    | @@ -1,26 +1,27 @@ | |
| 1 1 | 
             
            require 'rubygems'
         | 
| 2 2 |  | 
| 3 | 
            -
            gem 'dm-core', '~>0.9. | 
| 3 | 
            +
            gem 'dm-core', '~>0.9.11'
         | 
| 4 4 | 
             
            require 'dm-core'
         | 
| 5 5 | 
             
            require 'dm-validations'
         | 
| 6 6 | 
             
            require 'dm-timestamps'
         | 
| 7 7 |  | 
| 8 | 
            -
            gem 'ruby-openid', '~>2.1. | 
| 8 | 
            +
            gem 'ruby-openid', '~>2.1.4'
         | 
| 9 9 | 
             
            require 'openid'
         | 
| 10 10 | 
             
            require 'openid/store/filesystem'
         | 
| 11 11 | 
             
            require 'openid/extensions/sreg'
         | 
| 12 12 |  | 
| 13 | 
            -
            gem 'sinatra', '~>0.9. | 
| 13 | 
            +
            gem 'sinatra', '~>0.9.2'
         | 
| 14 14 | 
             
            require 'sinatra/base'
         | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
            require ' | 
| 15 | 
            +
            gem 'haml'
         | 
| 16 | 
            +
            require 'haml/engine'
         | 
| 17 | 
            +
            require 'sass'
         | 
| 18 18 |  | 
| 19 19 | 
             
            gem 'guid', '~>0.1.1'
         | 
| 20 20 | 
             
            require 'guid'
         | 
| 21 21 |  | 
| 22 22 | 
             
            module Hancock; end
         | 
| 23 23 |  | 
| 24 | 
            +
            require File.expand_path(File.dirname(__FILE__)+'/mailer')
         | 
| 24 25 | 
             
            require File.expand_path(File.dirname(__FILE__)+'/models/user')
         | 
| 25 26 | 
             
            require File.expand_path(File.dirname(__FILE__)+'/models/consumer')
         | 
| 26 27 | 
             
            require File.expand_path(File.dirname(__FILE__)+'/sinatra/hancock/defaults')
         | 
| @@ -44,4 +45,3 @@ module Hancock | |
| 44 45 | 
             
                register Sinatra::Hancock::OpenIDServer
         | 
| 45 46 | 
             
              end
         | 
| 46 47 | 
             
            end
         | 
| 47 | 
            -
             | 
    
        data/lib/mailer.rb
    ADDED
    
    | @@ -0,0 +1,155 @@ | |
| 1 | 
            +
            # Shamelssly stolen from Merb::Mailer
         | 
| 2 | 
            +
            # http://merbivore.com
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require 'net/smtp'
         | 
| 5 | 
            +
            require 'mailfactory'
         | 
| 6 | 
            +
            require 'tlsmail'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            class MailFactory
         | 
| 11 | 
            +
              attr_reader :html, :text
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            module Sinatra
         | 
| 15 | 
            +
              # = Sinatra::Mailer
         | 
| 16 | 
            +
              #
         | 
| 17 | 
            +
              # Adds an #email method to your email handlers, that receives a hash of
         | 
| 18 | 
            +
              # values to create your email.
         | 
| 19 | 
            +
              #
         | 
| 20 | 
            +
              # For example:
         | 
| 21 | 
            +
              #
         | 
| 22 | 
            +
              #   post "/signup" do
         | 
| 23 | 
            +
              #     # sign up the user, and then:
         | 
| 24 | 
            +
              #     email :to      => @user.email,
         | 
| 25 | 
            +
              #           :from    => "awesomeness@example.com",
         | 
| 26 | 
            +
              #           :subject => "Welcome to Awesomeness!",
         | 
| 27 | 
            +
              #           :body    => haml(:some_template)
         | 
| 28 | 
            +
              #   end
         | 
| 29 | 
            +
              #
         | 
| 30 | 
            +
              # == Configuration
         | 
| 31 | 
            +
              #
         | 
| 32 | 
            +
              # This plugin is very dirty yet :) Since it's just a port to Sinatra of
         | 
| 33 | 
            +
              # Merb::Mailer[merbivore.com/documentation/1.0/doc/rdoc/merb-mailer-1.0].
         | 
| 34 | 
            +
              # So the configuration is not Sinatra-y, yet. But we'll get to that.
         | 
| 35 | 
            +
              #
         | 
| 36 | 
            +
              # == Using SMTP
         | 
| 37 | 
            +
              #
         | 
| 38 | 
            +
              #  Sinatra::Mailer.config = {
         | 
| 39 | 
            +
              #    :host   => 'smtp.yourserver.com',
         | 
| 40 | 
            +
              #    :port   => '25',
         | 
| 41 | 
            +
              #    :user   => 'user',
         | 
| 42 | 
            +
              #    :pass   => 'pass',
         | 
| 43 | 
            +
              #    :auth   => :plain # :plain, :login, :cram_md5, the default is no auth
         | 
| 44 | 
            +
              #    :domain => "localhost.localdomain" # HELO domain provided by the client
         | 
| 45 | 
            +
              #  }
         | 
| 46 | 
            +
              #
         | 
| 47 | 
            +
              # == Using Gmail SMTP
         | 
| 48 | 
            +
              #
         | 
| 49 | 
            +
              # You need smtp-tls[http://github.com/ambethia/smtp-tls], a gem that improves
         | 
| 50 | 
            +
              # Net::HTTP to add support for secure servers such as Gmail.
         | 
| 51 | 
            +
              #
         | 
| 52 | 
            +
              #  require "smtp-tls"
         | 
| 53 | 
            +
              #
         | 
| 54 | 
            +
              #  Sinatra::Mailer.config = {
         | 
| 55 | 
            +
              #    :host => 'smtp.gmail.com',
         | 
| 56 | 
            +
              #    :port => '587',
         | 
| 57 | 
            +
              #    :user => 'user@gmail.com',
         | 
| 58 | 
            +
              #    :pass => 'pass',
         | 
| 59 | 
            +
              #    :auth => :plain
         | 
| 60 | 
            +
              #  }
         | 
| 61 | 
            +
              #
         | 
| 62 | 
            +
              # Make sure that when you call your #email method you pass the
         | 
| 63 | 
            +
              # +:text+ option and not +:body+.
         | 
| 64 | 
            +
              #
         | 
| 65 | 
            +
              # == Using sendmail
         | 
| 66 | 
            +
              #
         | 
| 67 | 
            +
              #  Sinatra::Mailer.config = {:sendmail_path => '/somewhere/odd'}
         | 
| 68 | 
            +
              #  Sinatra::Mailer.delivery_method = :sendmail
         | 
| 69 | 
            +
              #
         | 
| 70 | 
            +
              # == Credits
         | 
| 71 | 
            +
              #
         | 
| 72 | 
            +
              # This has been blatantly adapted from
         | 
| 73 | 
            +
              # Merb::Mailer[merbivore.com/documentation/1.0/doc/rdoc/merb-mailer-1.0]
         | 
| 74 | 
            +
              # so all credit is theirs, I just ported it to Sinatra.
         | 
| 75 | 
            +
              module Mailer
         | 
| 76 | 
            +
                class << self
         | 
| 77 | 
            +
                  attr_accessor :config, :delivery_method
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                def email(mail_options={})
         | 
| 81 | 
            +
                  Email.new(mail_options).deliver!
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                class Email
         | 
| 85 | 
            +
                  attr_accessor :mail, :config
         | 
| 86 | 
            +
                  def self.deliveries=(value)
         | 
| 87 | 
            +
                    @deliveries = value
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
                  def self.deliveries
         | 
| 90 | 
            +
                    @deliveries ||= [ ]
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                  # Sends the mail using sendmail.
         | 
| 94 | 
            +
                  def sendmail
         | 
| 95 | 
            +
                    sendmail = IO.popen("#{config[:sendmail_path]} #{@mail.to}", 'w+')
         | 
| 96 | 
            +
                    sendmail.puts @mail.to_s
         | 
| 97 | 
            +
                    sendmail.close
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  # Sends the mail using SMTP.
         | 
| 101 | 
            +
                  def net_smtp
         | 
| 102 | 
            +
                    Net::SMTP.start(config[:host], config[:port].to_i, config[:domain],
         | 
| 103 | 
            +
                                    config[:user], config[:pass], config[:auth]) { |smtp|
         | 
| 104 | 
            +
                      smtp.send_message(@mail.to_s, @mail.from.first, @mail.to.to_s.split(/[,;]/))
         | 
| 105 | 
            +
                    }
         | 
| 106 | 
            +
                  end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                  def test_send
         | 
| 109 | 
            +
                    self.class.deliveries << @mail
         | 
| 110 | 
            +
                  end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                  # Delivers the mail with the specified delivery method, defaulting to
         | 
| 113 | 
            +
                  # net_smtp.
         | 
| 114 | 
            +
                  def deliver!
         | 
| 115 | 
            +
                    send(Mailer.delivery_method || :net_smtp)
         | 
| 116 | 
            +
                  end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                  # ==== Parameters
         | 
| 119 | 
            +
                  # file_or_files<File, Array[File]>:: File(s) to attach.
         | 
| 120 | 
            +
                  # filename<String>::
         | 
| 121 | 
            +
                  # type<~to_s>::
         | 
| 122 | 
            +
                  #   The attachment MIME type. If left out, it will be determined from
         | 
| 123 | 
            +
                  #   file_or_files.
         | 
| 124 | 
            +
                  # headers<String, Array>:: Additional attachment headers.
         | 
| 125 | 
            +
                  #
         | 
| 126 | 
            +
                  # ==== Raises
         | 
| 127 | 
            +
                  # ArgumentError::
         | 
| 128 | 
            +
                  #   file_or_files was not a File or an Array of File instances.
         | 
| 129 | 
            +
                  def attach(file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil,
         | 
| 130 | 
            +
                    type = nil, headers = nil)
         | 
| 131 | 
            +
                    if file_or_files.is_a?(Array)
         | 
| 132 | 
            +
                      file_or_files.each {|k,v| @mail.add_attachment_as k, *v}
         | 
| 133 | 
            +
                    else
         | 
| 134 | 
            +
                      raise ArgumentError, "You did not pass in a file. Instead, you sent a #{file_or_files.class}" if !file_or_files.is_a?(File)
         | 
| 135 | 
            +
                      @mail.add_attachment_as(file_or_files, filename, type, headers)
         | 
| 136 | 
            +
                    end
         | 
| 137 | 
            +
                  end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                  # ==== Parameters
         | 
| 140 | 
            +
                  # o<Hash{~to_s => Object}>:: Configuration commands to send to MailFactory.
         | 
| 141 | 
            +
                  def initialize(o={})
         | 
| 142 | 
            +
                    self.config = Mailer.config || {:sendmail_path => '/usr/sbin/sendmail'}
         | 
| 143 | 
            +
                    o[:rawhtml] = o.delete(:html)
         | 
| 144 | 
            +
                    m = MailFactory.new()
         | 
| 145 | 
            +
                    o.each { |k,v| m.send "#{k}=", v }
         | 
| 146 | 
            +
                    @mail = m
         | 
| 147 | 
            +
                  end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
              end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
              class EventContext
         | 
| 153 | 
            +
                include Mailer
         | 
| 154 | 
            +
              end
         | 
| 155 | 
            +
            end
         | 
| @@ -1,51 +1,11 @@ | |
| 1 1 | 
             
            require File.expand_path(File.dirname(__FILE__)+'/../spec_helper')
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe "visiting /sso/signup" do
         | 
| 4 | 
            -
              def app
         | 
| 5 | 
            -
                Hancock::App
         | 
| 6 | 
            -
              end
         | 
| 7 4 | 
             
              before(:each) do
         | 
| 8 5 | 
             
                @user = Hancock::User.new(:email      => /\w+@\w+\.\w{2,3}/.gen.downcase,
         | 
| 9 6 | 
             
                                          :first_name => /\w+/.gen.capitalize,
         | 
| 10 7 | 
             
                                          :last_name  => /\w+/.gen.capitalize)
         | 
| 11 8 | 
             
              end
         | 
| 12 | 
            -
              describe "when signing up" do
         | 
| 13 | 
            -
                it "should sign the user up" do
         | 
| 14 | 
            -
                  get '/sso/signup'
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  post '/sso/signup', :email => @user.email,
         | 
| 17 | 
            -
                                      :first_name => @user.first_name,
         | 
| 18 | 
            -
                                      :last_name => @user.last_name
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  confirmation_url = last_response.body.to_s.match(%r!/sso/register/\w{40}!)
         | 
| 21 | 
            -
                  confirmation_url.should_not be_nil
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  get "#{confirmation_url}"
         | 
| 24 | 
            -
                  password = /\w+{9,32}/.gen
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  last_response.body.to_s.should have_selector("form[action='#{confirmation_url}']")
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  post "#{confirmation_url}", :password => password, :password_confirmation => password
         | 
| 29 | 
            -
                  follow_redirect!
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  last_response.body.to_s.should have_selector("h3:contains('Hello #{@user.first_name} #{@user.last_name}')")
         | 
| 32 | 
            -
                end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                describe "and form hacking" do
         | 
| 35 | 
            -
                  it "should be unauthorized" do
         | 
| 36 | 
            -
                    get '/sso/signup'
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                    post '/sso/signup', :email => @user.email,
         | 
| 39 | 
            -
                                        :first_name => @user.first_name,
         | 
| 40 | 
            -
                                        :last_name => @user.last_name
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                    fake_url = /\w+{9,40}/.gen
         | 
| 43 | 
            -
                    get "/sso/register/#{fake_url}"
         | 
| 44 | 
            -
                    last_response.body.to_s.should match(/BadRequest/)
         | 
| 45 | 
            -
                  end
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
              end
         | 
| 48 | 
            -
             | 
| 49 9 | 
             
              if ENV['WATIR']
         | 
| 50 10 | 
             
                begin
         | 
| 51 11 | 
             
                  require 'safariwatir'
         | 
    
        data/spec/matchers.rb
    CHANGED
    
    | @@ -42,12 +42,14 @@ module Hancock | |
| 42 42 | 
             
                  include Webrat::Methods
         | 
| 43 43 | 
             
                  include Webrat::Matchers
         | 
| 44 44 | 
             
                  include Spec::Matchers
         | 
| 45 | 
            +
             | 
| 45 46 | 
             
                  def matches?(target)
         | 
| 46 | 
            -
                    target. | 
| 47 | 
            +
                    target.headers['Content-Type'].should eql('application/xrds+xml')
         | 
| 47 48 | 
             
                    target.body.should have_xpath("//xrd/service[uri='http://example.org/sso']")
         | 
| 48 49 | 
             
                    target.body.should have_xpath("//xrd/service[type='http://specs.openid.net/auth/2.0/server']")
         | 
| 49 50 | 
             
                    true
         | 
| 50 51 | 
             
                  end
         | 
| 52 | 
            +
             | 
| 51 53 | 
             
                  def failure_message
         | 
| 52 54 | 
             
                    puts "Expected a identity provider yadis document"
         | 
| 53 55 | 
             
                  end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -2,15 +2,14 @@ require 'rubygems' | |
| 2 2 | 
             
            require 'pp'
         | 
| 3 3 | 
             
            gem 'rspec', '~>1.2.0'
         | 
| 4 4 | 
             
            require 'spec'
         | 
| 5 | 
            -
            require 'sinatra/test'
         | 
| 6 5 | 
             
            require 'dm-sweatshop'
         | 
| 7 6 |  | 
| 8 7 | 
             
            $:.push File.join(File.dirname(__FILE__), '..', 'lib')
         | 
| 9 8 | 
             
            require 'hancock'
         | 
| 10 | 
            -
            gem 'webrat', '~>0.4. | 
| 11 | 
            -
            require 'webrat | 
| 9 | 
            +
            gem 'webrat', '~>0.4.4'
         | 
| 10 | 
            +
            require 'webrat'
         | 
| 12 11 |  | 
| 13 | 
            -
            gem 'rack-test', '~>0. | 
| 12 | 
            +
            gem 'rack-test', '~>0.3.0'
         | 
| 14 13 | 
             
            require 'rack/test'
         | 
| 15 14 |  | 
| 16 15 | 
             
            require File.expand_path(File.dirname(__FILE__) + '/app')
         | 
| @@ -23,9 +22,9 @@ Sinatra::Mailer.delivery_method = :test_send | |
| 23 22 |  | 
| 24 23 | 
             
            Webrat.configure do |config|
         | 
| 25 24 | 
             
              if ENV['SELENIUM'].nil?
         | 
| 26 | 
            -
                config.mode = : | 
| 25 | 
            +
                config.mode = :rack_test
         | 
| 27 26 | 
             
              else
         | 
| 28 | 
            -
                gem 'selenium-client', '~>1.2. | 
| 27 | 
            +
                gem 'selenium-client', '~>1.2.15'
         | 
| 29 28 | 
             
                config.mode = :selenium
         | 
| 30 29 | 
             
                config.application_framework = :sinatra
         | 
| 31 30 | 
             
                config.application_port = 4567
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: hancock
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Corey Donohoe
         | 
| @@ -10,38 +10,38 @@ autorequire: hancock | |
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 12 |  | 
| 13 | 
            -
            date: 2009- | 
| 13 | 
            +
            date: 2009-06-15 00:00:00 -07:00
         | 
| 14 14 | 
             
            default_executable: 
         | 
| 15 15 | 
             
            dependencies: 
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 17 | 
            -
              name:  | 
| 17 | 
            +
              name: ruby-openid
         | 
| 18 18 | 
             
              type: :runtime
         | 
| 19 19 | 
             
              version_requirement: 
         | 
| 20 20 | 
             
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 21 21 | 
             
                requirements: 
         | 
| 22 22 | 
             
                - - ~>
         | 
| 23 23 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 24 | 
            -
                    version:  | 
| 24 | 
            +
                    version: 2.1.4
         | 
| 25 25 | 
             
                version: 
         | 
| 26 26 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 27 | 
            -
              name:  | 
| 27 | 
            +
              name: sinatra
         | 
| 28 28 | 
             
              type: :runtime
         | 
| 29 29 | 
             
              version_requirement: 
         | 
| 30 30 | 
             
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 31 31 | 
             
                requirements: 
         | 
| 32 32 | 
             
                - - ~>
         | 
| 33 33 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 34 | 
            -
                    version:  | 
| 34 | 
            +
                    version: 0.9.2
         | 
| 35 35 | 
             
                version: 
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 37 | 
            -
              name:  | 
| 37 | 
            +
              name: haml
         | 
| 38 38 | 
             
              type: :runtime
         | 
| 39 39 | 
             
              version_requirement: 
         | 
| 40 40 | 
             
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 41 41 | 
             
                requirements: 
         | 
| 42 42 | 
             
                - - ~>
         | 
| 43 43 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 44 | 
            -
                    version: 0.9 | 
| 44 | 
            +
                    version: 2.0.9
         | 
| 45 45 | 
             
                version: 
         | 
| 46 46 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 47 47 | 
             
              name: guid
         | 
| @@ -53,6 +53,46 @@ dependencies: | |
| 53 53 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 54 54 | 
             
                    version: 0.1.1
         | 
| 55 55 | 
             
                version: 
         | 
| 56 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 57 | 
            +
              name: dm-core
         | 
| 58 | 
            +
              type: :runtime
         | 
| 59 | 
            +
              version_requirement: 
         | 
| 60 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 61 | 
            +
                requirements: 
         | 
| 62 | 
            +
                - - ~>
         | 
| 63 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 64 | 
            +
                    version: 0.9.11
         | 
| 65 | 
            +
                version: 
         | 
| 66 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 67 | 
            +
              name: dm-types
         | 
| 68 | 
            +
              type: :runtime
         | 
| 69 | 
            +
              version_requirement: 
         | 
| 70 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 71 | 
            +
                requirements: 
         | 
| 72 | 
            +
                - - ~>
         | 
| 73 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 74 | 
            +
                    version: 0.9.11
         | 
| 75 | 
            +
                version: 
         | 
| 76 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 77 | 
            +
              name: dm-timestamps
         | 
| 78 | 
            +
              type: :runtime
         | 
| 79 | 
            +
              version_requirement: 
         | 
| 80 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 81 | 
            +
                requirements: 
         | 
| 82 | 
            +
                - - ~>
         | 
| 83 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 84 | 
            +
                    version: 0.9.11
         | 
| 85 | 
            +
                version: 
         | 
| 86 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 87 | 
            +
              name: dm-validations
         | 
| 88 | 
            +
              type: :runtime
         | 
| 89 | 
            +
              version_requirement: 
         | 
| 90 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 91 | 
            +
                requirements: 
         | 
| 92 | 
            +
                - - ~>
         | 
| 93 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 94 | 
            +
                    version: 0.9.11
         | 
| 95 | 
            +
                version: 
         | 
| 56 96 | 
             
            description: A gem that provides a Single Sign On server
         | 
| 57 97 | 
             
            email: 
         | 
| 58 98 | 
             
            - atmos@atmos.org
         | 
| @@ -68,7 +108,17 @@ files: | |
| 68 108 | 
             
            - LICENSE
         | 
| 69 109 | 
             
            - README.md
         | 
| 70 110 | 
             
            - Rakefile
         | 
| 111 | 
            +
            - features/sessions.feature
         | 
| 112 | 
            +
            - features/signup.feature
         | 
| 113 | 
            +
            - features/sso.feature
         | 
| 114 | 
            +
            - features/step_definitions
         | 
| 115 | 
            +
            - features/step_definitions/sessions_steps.rb
         | 
| 116 | 
            +
            - features/step_definitions/signup_steps.rb
         | 
| 117 | 
            +
            - features/step_definitions/sso_steps.rb
         | 
| 118 | 
            +
            - features/support
         | 
| 119 | 
            +
            - features/support/env.rb
         | 
| 71 120 | 
             
            - lib/hancock.rb
         | 
| 121 | 
            +
            - lib/mailer.rb
         | 
| 72 122 | 
             
            - lib/models
         | 
| 73 123 | 
             
            - lib/models/consumer.rb
         | 
| 74 124 | 
             
            - lib/models/user.rb
         | 
| @@ -90,16 +140,6 @@ files: | |
| 90 140 | 
             
            - spec/acceptance
         | 
| 91 141 | 
             
            - spec/acceptance/signing_up_spec.rb
         | 
| 92 142 | 
             
            - spec/app.rb
         | 
| 93 | 
            -
            - spec/features
         | 
| 94 | 
            -
            - spec/features/sessions.feature
         | 
| 95 | 
            -
            - spec/features/signup.feature
         | 
| 96 | 
            -
            - spec/features/sso.feature
         | 
| 97 | 
            -
            - spec/features/step_definitions
         | 
| 98 | 
            -
            - spec/features/step_definitions/sessions_steps.rb
         | 
| 99 | 
            -
            - spec/features/step_definitions/signup_steps.rb
         | 
| 100 | 
            -
            - spec/features/step_definitions/sso_steps.rb
         | 
| 101 | 
            -
            - spec/features/support
         | 
| 102 | 
            -
            - spec/features/support/env.rb
         | 
| 103 143 | 
             
            - spec/fixtures.rb
         | 
| 104 144 | 
             
            - spec/matchers.rb
         | 
| 105 145 | 
             
            - spec/spec_helper.rb
         |