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
def self.create_from_manifest! manifest_url
puts manifest_url
manifest = JSON.parse(RestClient.get(manifest_url).body)
create!(manifest)
end

View file

@ -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

View file

@ -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

View file

@ -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)

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", "support","user_methods")
include HelperMethods
Before do
DatabaseCleaner.clean
Devise.mailer.deliveries = []

View file

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

View file

@ -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

View file

@ -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

View file

@ -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" }