From e720fc097d84ea15ced1cb8fc99ffbe54ee0a560 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Fri, 3 Jun 2011 14:41:38 -0700 Subject: [PATCH] chubbies tests mow take diaspora handle --- app/controllers/authorizations_controller.rb | 1 - db/schema.rb | 1 + features/oauth.feature | 1 + features/step_definitions/oauth_steps.rb | 4 +- features/support/env.rb | 1 - spec/support/chubbies/Gemfile | 1 + spec/support/chubbies/Gemfile.lock | 3 ++ spec/support/chubbies/app.rb | 57 ++++++++++++-------- spec/support/chubbies/views/home.haml | 13 ++++- 9 files changed, 55 insertions(+), 27 deletions(-) diff --git a/app/controllers/authorizations_controller.rb b/app/controllers/authorizations_controller.rb index d580c7c82..3dc991744 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 9f7bfa013..9ed970010 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 5f585dbcf..b4ca72831 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 d059ee050..cef6dfb69 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 b0bb208b8..50a591bca 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 5c17d3d4e..cae954b33 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 ef6042d28..636e24e35 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 af54e1141..b30733db9 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" - }) + register_with_pod + end - json = JSON.parse(response.body) - - @@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 3b5832e08..547f814a0 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" } + + +