Chubbies is working with local diaspora-client gem

This commit is contained in:
Raphael Sofaer 2011-06-09 14:50:30 -07:00
parent 775dbda2b2
commit 6d5169d707
6 changed files with 88 additions and 53 deletions

View file

@ -37,6 +37,15 @@ GIT
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
PATH
remote: ~/workspace/diaspora-client
specs:
diaspora-client (0.0.0)
activerecord
faraday
oauth2
sinatra
GEM
remote: http://rubygems.org/
specs:
@ -414,6 +423,7 @@ DEPENDENCIES
database_cleaner (= 0.6.0)
devise (~> 1.3.1)
devise_invitable (= 0.5.0)
diaspora-client!
em-websocket!
excon (= 0.2.4)
factory_girl_rails

View file

@ -5,6 +5,7 @@ class AddOauth2Tables < ActiveRecord::Migration
t.string 'oauth_identifier', :limit => 32, :null => false
t.string 'oauth_secret', :limit => 32, :null => false
end
add_index :oauth_clients, :name, :unique => true
create_table 'oauth_authorization_codes', :force => true do |t|
t.integer 'authorization_id', :null => false

View file

@ -230,6 +230,8 @@ ActiveRecord::Schema.define(:version => 20110603212633) do
t.string "icon_url"
end
add_index "oauth_clients", ["name"], :name => "index_oauth_clients_on_name", :unique => true
create_table "people", :force => true do |t|
t.string "guid", :null => false
t.text "url", :null => false

View file

@ -5,38 +5,36 @@ Feature: oauth
Background:
Given Chubbies has been killed
And Chubbies is running
When I visit "/" on Chubbies
And I visit "/reset" on Chubbies
And a user with username "bob" and password "secret"
Scenario: Authorize Chubbies
When I visit "/" on Chubbies
And I try to authorize Chubbies
Then I should see "Authorize Chubbies?"
And I should see "Chubbies tests Diaspora's OAuth capabilities."
When I try to authorize Chubbies
Then I should see "Chubbies"
And I should see "The best way to chub."
When I press "Yes"
When I press "Authorize"
Then I should be on "/account" on Chubbies
And I should see my "profile.birthday"
And I should see my "name"
Scenario: Not authorize Chubbies
When I visit "/" on Chubbies
And I try to authorize Chubbies
Then I should see "Authorize Chubbies?"
And I should see "Chubbies tests Diaspora's OAuth capabilities."
When I try to authorize Chubbies
Then I should see "Chubbies"
And I should see "The best way to chub."
When I press "No"
Then I should be on "/callback" on Chubbies
Then I should see "What is your major malfunction?"
Then I should be on "/account" on Chubbies
Then I should see "No access token."
Scenario: Authorize Chubbies
Given Chubbies is registered on my pod
When I visit "/" on Chubbies
And I try to authorize Chubbies
Then I should see "Authorize Chubbies?"
And I should see "Chubbies tests Diaspora's OAuth capabilities."
When I try to authorize Chubbies
Then I should see "Chubbies"
And I should see "The best way to chub."
And there is only one Chubbies
When I press "Yes"
When I press "Authorize"
Then I should be on "/account" on Chubbies
And I should see my "profile.birthday"
And I should see my "name"

View file

@ -7,23 +7,28 @@ Given /^Chubbies has been killed$/ do
end
Given /^Chubbies is registered on my pod$/ do
OAuth2::Provider.client_class.create! :name => 'Chubbies',
:oauth_identifier => 'abcdefgh12345678',
:oauth_secret => 'secret'
client = OAuth2::Provider.client_class.create_from_manifest!("localhost:#{Chubbies::PORT}/manifest.json")
params = {:client_id => client.oauth_identifier,
:client_secret => client.oauth_secret,
:host => "localhost:9887"}
RestClient.post("localhost:#{Chubbies::PORT}/register", params)
end
And /^I should see my "([^"]+)"/ do |code|
page.should have_content(@me.person.instance_eval(code).to_s)
end
And /^there is only one Chubbies$/ do
OAuth2::Provider.client_class.where(:name => "Chubbies").count.should == 1
end
When /^I try to authorize Chubbies$/ do
# We need to reset the tokens saved in Chubbies,
# as we are clearing the Diaspora DB every scenario
Then 'I visit "/reset" on Chubbies'
Then 'I visit "/" on Chubbies'
Then 'I visit "/new" on Chubbies'
###
And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\""
And 'I press "Log in with Diaspora"'
And 'I press "Connect to 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}\""
@ -44,7 +49,7 @@ class Chubbies
def self.run
@pid = fork do
Process.exec "cd #{Rails.root}/spec/chubbies/ && BUNDLE_GEMFILE=Gemfile DIASPORA_PORT=9887 bundle exec rackup -p #{PORT} 2> /dev/null"
Process.exec "cd #{Rails.root}/spec/chubbies/ && BUNDLE_GEMFILE=Gemfile bundle exec rackup -p #{PORT} 2> /dev/null 1> /dev/null"
end
at_exit do
@ -69,7 +74,10 @@ class Chubbies
def self.running?
begin
RestClient.get("localhost:#{PORT}")
begin
RestClient.get("localhost:#{PORT}/running")
rescue RestClient::ResourceNotFound
end
true
rescue Errno::ECONNREFUSED
false

View file

@ -1,6 +1,8 @@
module Chubbies
require 'active_record'
require 'diaspora-client'
def self.reset_db
`rm -f #{File.expand_path('../chubbies.sqlite3', __FILE__)}`
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
@ -30,6 +32,9 @@ module Chubbies
t.timestamps
end
end
end
self.reset_db
class User < ActiveRecord::Base
has_one :access_token, :class_name => "DiasporaClient::AccessToken", :dependent => :destroy
@ -51,8 +56,12 @@ module Chubbies
get '/account' do
if params['id'] && user = User.where(:id => params['id']).first
if user.access_token
@resource_response = user.access_token.token.get("/api/v0/me")
haml :response
else
"No access token."
end
else
"No user with id #{params['id']}"
end
@ -71,5 +80,12 @@ module Chubbies
"icon_url" => "#"
}.to_json
end
get '/reset' do
Chubbies.reset_db
end
post '/register' do
DiasporaClient::ResourceServer.create!(params)
end
end
end