chubbies tests mow take diaspora handle

This commit is contained in:
Maxwell Salzberg 2011-06-03 14:41:38 -07:00
parent 01edfeee03
commit e720fc097d
9 changed files with 55 additions and 27 deletions

View file

@ -35,7 +35,6 @@ end
OAuth2::Provider.client_class.instance_eval do OAuth2::Provider.client_class.instance_eval do
def self.create_from_manifest! manifest_url def self.create_from_manifest! manifest_url
puts manifest_url
manifest = JSON.parse(RestClient.get(manifest_url).body) manifest = JSON.parse(RestClient.get(manifest_url).body)
create!(manifest) create!(manifest)
end end

View file

@ -283,6 +283,7 @@ ActiveRecord::Schema.define(:version => 20110603212633) do
t.string "provider_display_name" t.string "provider_display_name"
t.string "actor_url" t.string "actor_url"
t.integer "objectId" t.integer "objectId"
t.integer "root_id"
t.string "status_message_guid" t.string "status_message_guid"
end end

View file

@ -4,6 +4,7 @@ Feature: oauth
Background: Background:
Given Chubbies is running Given Chubbies is running
When I visit "/" on Chubbies
And a user with username "bob" and password "secret" And a user with username "bob" and password "secret"
Scenario: Authorize Chubbies Scenario: Authorize Chubbies

View file

@ -25,7 +25,8 @@ When /^I try to authorize Chubbies$/ do
Then 'I visit "/reset" on Chubbies' Then 'I visit "/reset" on Chubbies'
Then 'I visit "/" 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' Then 'I should be on the new user session page'
And "I fill in \"Username\" with \"#{@me.username}\"" And "I fill in \"Username\" with \"#{@me.username}\""
And "I fill in \"Password\" with \"#{@me.password}\"" And "I fill in \"Password\" with \"#{@me.password}\""
@ -34,6 +35,7 @@ When /^I try to authorize Chubbies$/ do
end end
When /^I visit "([^"]+)" on Chubbies$/ do |path| When /^I visit "([^"]+)" on Chubbies$/ do |path|
former_host = Capybara.app_host former_host = Capybara.app_host
Capybara.app_host = "localhost:#{Chubbies::PORT}" Capybara.app_host = "localhost:#{Chubbies::PORT}"
visit(path) visit(path)

View file

@ -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", "helper_methods")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods") require File.join(File.dirname(__FILE__), "..", "..", "spec", "support","user_methods")
include HelperMethods include HelperMethods
Before do Before do
DatabaseCleaner.clean DatabaseCleaner.clean
Devise.mailer.deliveries = [] Devise.mailer.deliveries = []

View file

@ -5,3 +5,4 @@ gem 'haml'
gem 'httparty' gem 'httparty'
gem 'json' gem 'json'
gem 'shotgun'

View file

@ -7,6 +7,8 @@ GEM
crack (= 0.1.8) crack (= 0.1.8)
json (1.4.6) json (1.4.6)
rack (1.2.2) rack (1.2.2)
shotgun (0.9)
rack (>= 1.0)
sinatra (1.2.6) sinatra (1.2.6)
rack (~> 1.1) rack (~> 1.1)
tilt (>= 1.2.2, < 2.0) tilt (>= 1.2.2, < 2.0)
@ -19,4 +21,5 @@ DEPENDENCIES
haml haml
httparty httparty
json json
shotgun
sinatra sinatra

View file

@ -23,7 +23,7 @@ enable :sessions
helpers do helpers do
def redirect_uri def redirect_uri
"http://" + request.host_with_port + "/callback" "http://" + request.host_with_port + "/callback" << "?diaspora_handle=#{params['diaspora_handle']}"
end end
def access_token def access_token
@ -31,19 +31,19 @@ helpers do
end end
def get_with_access_token(path) 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 end
def authorize_url 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 end
def token_url def token_url
RESOURCE_HOST + "/oauth/token" "http://" + domain_from_handle + "/oauth/token"
end end
def access_token_url def access_token_url
RESOURCE_HOST + "/oauth/access_token" "http://" + domain_from_handle + "/oauth/access_token"
end end
end end
@ -69,7 +69,7 @@ get '/callback' do
) )
session[:access_token] = response["access_token"] session[:access_token] = response["access_token"]
redirect '/account' redirect "/account?diaspora_handle=#{params['diaspora_handle']}"
end end
else else
"What is your major malfunction?" "What is your major malfunction?"
@ -78,24 +78,14 @@ end
get '/account' do get '/account' do
if !@@client_id && !@@client_secret if !@@client_id && !@@client_secret
response = HTTParty.post(token_url, :body => { register_with_pod
:type => :client_associate, end
:manifest_url => "http://" + request.host_with_port + "/manifest"
})
json = JSON.parse(response.body) if access_token
@resource_response = get_with_access_token("/api/v0/me")
@@client_id = json["client_id"] haml :response
@@client_secret = json["client_secret"]
redirect '/account'
else else
if access_token redirect authorize_url
@resource_response = get_with_access_token("/api/v0/me")
haml :response
else
redirect authorize_url
end
end end
end end
@ -112,3 +102,26 @@ get '/reset' do
@@client_id = nil @@client_id = nil
@@client_secret = nil @@client_secret = nil
end 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

View file

@ -1,2 +1,11 @@
%a{:href => '/account'} %html
Log in with Diaspora %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" }