diff --git a/app/controllers/authorizations_controller.rb b/app/controllers/authorizations_controller.rb index d580c7c82e801372f5c244d55f9741bf934eeda1..3dc99174453fc72efb7f68f73380fa45d533772d 100644 --- a/app/controllers/authorizations_controller.rb +++ b/app/controllers/authorizations_controller.rb @@ -35,7 +35,6 @@ end OAuth2::Provider.client_class.instance_eval do def self.create_from_manifest! manifest_url - puts manifest_url manifest = JSON.parse(RestClient.get(manifest_url).body) create!(manifest) end diff --git a/db/schema.rb b/db/schema.rb index 9f7bfa013a86393869b671ee97747efabce129cc..9ed970010250d5e3388c575eb1de5bbc4f009b56 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -283,6 +283,7 @@ ActiveRecord::Schema.define(:version => 20110603212633) do t.string "provider_display_name" t.string "actor_url" t.integer "objectId" + t.integer "root_id" t.string "status_message_guid" end diff --git a/features/oauth.feature b/features/oauth.feature index 5f585dbcf46ddfb5034c066487ef68c46a5eb084..b4ca72831eaecf1d0d25afac2b228cbd9b52aece 100644 --- a/features/oauth.feature +++ b/features/oauth.feature @@ -4,6 +4,7 @@ Feature: oauth Background: Given Chubbies is running + When I visit "/" on Chubbies And a user with username "bob" and password "secret" Scenario: Authorize Chubbies diff --git a/features/step_definitions/oauth_steps.rb b/features/step_definitions/oauth_steps.rb index d059ee0501408dd30048a54552b829f653511208..cef6dfb69573f57154d7bb9af1e71ce7f5dcaf16 100644 --- a/features/step_definitions/oauth_steps.rb +++ b/features/step_definitions/oauth_steps.rb @@ -25,7 +25,8 @@ When /^I try to authorize Chubbies$/ do Then 'I visit "/reset" on Chubbies' Then 'I visit "/" on Chubbies' ### - And 'I follow "Log in with Diaspora"' + And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\"" + And 'I press "Log in with Diaspora"' Then 'I should be on the new user session page' And "I fill in \"Username\" with \"#{@me.username}\"" And "I fill in \"Password\" with \"#{@me.password}\"" @@ -34,6 +35,7 @@ When /^I try to authorize Chubbies$/ do end When /^I visit "([^"]+)" on Chubbies$/ do |path| + former_host = Capybara.app_host Capybara.app_host = "localhost:#{Chubbies::PORT}" visit(path) diff --git a/features/support/env.rb b/features/support/env.rb index b0bb208b8ddf85161f09bc1b20ed3bc91b91f950..50a591bcac90b414804b8a45b014804d38635224 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -45,7 +45,6 @@ require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_r require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods") require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods") include HelperMethods - Before do DatabaseCleaner.clean Devise.mailer.deliveries = [] diff --git a/spec/support/chubbies/Gemfile b/spec/support/chubbies/Gemfile index 5c17d3d4eb5149004a4c1485b1b7c84f7e12c6e0..cae954b3301323504569ceec520b165e721206fe 100644 --- a/spec/support/chubbies/Gemfile +++ b/spec/support/chubbies/Gemfile @@ -5,3 +5,4 @@ gem 'haml' gem 'httparty' gem 'json' +gem 'shotgun' diff --git a/spec/support/chubbies/Gemfile.lock b/spec/support/chubbies/Gemfile.lock index ef6042d2855aad0727c5c4a7bb555aadaf2c0ce6..636e24e358cfbc97f4478d78400b8ecd1d58af6d 100644 --- a/spec/support/chubbies/Gemfile.lock +++ b/spec/support/chubbies/Gemfile.lock @@ -7,6 +7,8 @@ GEM crack (= 0.1.8) json (1.4.6) rack (1.2.2) + shotgun (0.9) + rack (>= 1.0) sinatra (1.2.6) rack (~> 1.1) tilt (>= 1.2.2, < 2.0) @@ -19,4 +21,5 @@ DEPENDENCIES haml httparty json + shotgun sinatra diff --git a/spec/support/chubbies/app.rb b/spec/support/chubbies/app.rb index af54e1141b34003b55ec975dc21192fda7359d3f..b30733db92ed23ebc9ee70167d3914d59b4d5787 100644 --- a/spec/support/chubbies/app.rb +++ b/spec/support/chubbies/app.rb @@ -23,7 +23,7 @@ enable :sessions helpers do def redirect_uri - "http://" + request.host_with_port + "/callback" + "http://" + request.host_with_port + "/callback" << "?diaspora_handle=#{params['diaspora_handle']}" end def access_token @@ -31,19 +31,19 @@ helpers do end def get_with_access_token(path) - HTTParty.get(RESOURCE_HOST + path, :query => {:oauth_token => access_token}) + HTTParty.get('http://' + domain_from_handle + path, :query => {:oauth_token => access_token}) end def authorize_url - RESOURCE_HOST + "/oauth/authorize?client_id=#{@@client_id}&client_secret=#{@@client_secret}&redirect_uri=#{redirect_uri}" + "http://" + domain_from_handle + "/oauth/authorize?client_id=#{@@client_id}&client_secret=#{@@client_secret}&redirect_uri=#{redirect_uri}" end def token_url - RESOURCE_HOST + "/oauth/token" + "http://" + domain_from_handle + "/oauth/token" end def access_token_url - RESOURCE_HOST + "/oauth/access_token" + "http://" + domain_from_handle + "/oauth/access_token" end end @@ -69,7 +69,7 @@ get '/callback' do ) session[:access_token] = response["access_token"] - redirect '/account' + redirect "/account?diaspora_handle=#{params['diaspora_handle']}" end else "What is your major malfunction?" @@ -78,24 +78,14 @@ end get '/account' do if !@@client_id && !@@client_secret - response = HTTParty.post(token_url, :body => { - :type => :client_associate, - :manifest_url => "http://" + request.host_with_port + "/manifest" - }) - - json = JSON.parse(response.body) + register_with_pod + end - @@client_id = json["client_id"] - @@client_secret = json["client_secret"] - - redirect '/account' + if access_token + @resource_response = get_with_access_token("/api/v0/me") + haml :response else - if access_token - @resource_response = get_with_access_token("/api/v0/me") - haml :response - else - redirect authorize_url - end + redirect authorize_url end end @@ -112,3 +102,26 @@ get '/reset' do @@client_id = nil @@client_secret = nil end + + +#============================= +#helpers +# +def domain_from_handle + m = params['diaspora_handle'].match(/\@(.+)/) + m = m[1] if m +end + +def register_with_pod + response = HTTParty.post(token_url, :body => { + :type => :client_associate, + :manifest_url => "http://" + request.host_with_port + "/manifest" + }) + + json = JSON.parse(response.body) + + @@client_id = json["client_id"] + @@client_secret = json["client_secret"] +end + + diff --git a/spec/support/chubbies/views/home.haml b/spec/support/chubbies/views/home.haml index 3b5832e0889ed9d869126bc888780a1118499f95..547f814a068bb1add4ca7c17ac17ac0b507abf88 100644 --- a/spec/support/chubbies/views/home.haml +++ b/spec/support/chubbies/views/home.haml @@ -1,2 +1,11 @@ -%a{:href => '/account'} - Log in with Diaspora +%html + %head + %body + %form{:action => '/account', :id => 'login', :method => 'get'} + %label{:for => 'diaspora_handle'} + Diaspora Handle + %input{:type=>'text', :id => 'diaspora_handle', :name => 'diaspora_handle'} + %input{:type => 'submit', :value => "Log in with Diaspora" } + + +