Chubbies is working with local diaspora-client gem
This commit is contained in:
parent
775dbda2b2
commit
6d5169d707
6 changed files with 88 additions and 53 deletions
10
Gemfile.lock
10
Gemfile.lock
|
|
@ -37,6 +37,15 @@ GIT
|
||||||
addressable (>= 2.1.1)
|
addressable (>= 2.1.1)
|
||||||
eventmachine (>= 0.12.9)
|
eventmachine (>= 0.12.9)
|
||||||
|
|
||||||
|
PATH
|
||||||
|
remote: ~/workspace/diaspora-client
|
||||||
|
specs:
|
||||||
|
diaspora-client (0.0.0)
|
||||||
|
activerecord
|
||||||
|
faraday
|
||||||
|
oauth2
|
||||||
|
sinatra
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
|
@ -414,6 +423,7 @@ DEPENDENCIES
|
||||||
database_cleaner (= 0.6.0)
|
database_cleaner (= 0.6.0)
|
||||||
devise (~> 1.3.1)
|
devise (~> 1.3.1)
|
||||||
devise_invitable (= 0.5.0)
|
devise_invitable (= 0.5.0)
|
||||||
|
diaspora-client!
|
||||||
em-websocket!
|
em-websocket!
|
||||||
excon (= 0.2.4)
|
excon (= 0.2.4)
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ class AddOauth2Tables < ActiveRecord::Migration
|
||||||
t.string 'oauth_identifier', :limit => 32, :null => false
|
t.string 'oauth_identifier', :limit => 32, :null => false
|
||||||
t.string 'oauth_secret', :limit => 32, :null => false
|
t.string 'oauth_secret', :limit => 32, :null => false
|
||||||
end
|
end
|
||||||
|
add_index :oauth_clients, :name, :unique => true
|
||||||
|
|
||||||
create_table 'oauth_authorization_codes', :force => true do |t|
|
create_table 'oauth_authorization_codes', :force => true do |t|
|
||||||
t.integer 'authorization_id', :null => false
|
t.integer 'authorization_id', :null => false
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,8 @@ ActiveRecord::Schema.define(:version => 20110603212633) do
|
||||||
t.string "icon_url"
|
t.string "icon_url"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "oauth_clients", ["name"], :name => "index_oauth_clients_on_name", :unique => true
|
||||||
|
|
||||||
create_table "people", :force => true do |t|
|
create_table "people", :force => true do |t|
|
||||||
t.string "guid", :null => false
|
t.string "guid", :null => false
|
||||||
t.text "url", :null => false
|
t.text "url", :null => false
|
||||||
|
|
|
||||||
|
|
@ -5,38 +5,36 @@ Feature: oauth
|
||||||
Background:
|
Background:
|
||||||
Given Chubbies has been killed
|
Given Chubbies has been killed
|
||||||
And Chubbies is running
|
And Chubbies is running
|
||||||
When I visit "/" on Chubbies
|
And I visit "/reset" 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
|
||||||
When I visit "/" on Chubbies
|
When I try to authorize Chubbies
|
||||||
And I try to authorize Chubbies
|
Then I should see "Chubbies"
|
||||||
Then I should see "Authorize Chubbies?"
|
And I should see "The best way to chub."
|
||||||
And I should see "Chubbies tests Diaspora's OAuth capabilities."
|
|
||||||
|
|
||||||
When I press "Yes"
|
When I press "Authorize"
|
||||||
Then I should be on "/account" on Chubbies
|
Then I should be on "/account" on Chubbies
|
||||||
And I should see my "profile.birthday"
|
And I should see my "profile.birthday"
|
||||||
And I should see my "name"
|
And I should see my "name"
|
||||||
|
|
||||||
Scenario: Not authorize Chubbies
|
Scenario: Not authorize Chubbies
|
||||||
When I visit "/" on Chubbies
|
When I try to authorize Chubbies
|
||||||
And I try to authorize Chubbies
|
Then I should see "Chubbies"
|
||||||
Then I should see "Authorize Chubbies?"
|
And I should see "The best way to chub."
|
||||||
And I should see "Chubbies tests Diaspora's OAuth capabilities."
|
|
||||||
|
|
||||||
When I press "No"
|
When I press "No"
|
||||||
Then I should be on "/callback" on Chubbies
|
Then I should be on "/account" on Chubbies
|
||||||
Then I should see "What is your major malfunction?"
|
Then I should see "No access token."
|
||||||
|
|
||||||
Scenario: Authorize Chubbies
|
Scenario: Authorize Chubbies
|
||||||
Given Chubbies is registered on my pod
|
Given Chubbies is registered on my pod
|
||||||
When I visit "/" on Chubbies
|
When I try to authorize Chubbies
|
||||||
And I try to authorize Chubbies
|
Then I should see "Chubbies"
|
||||||
Then I should see "Authorize Chubbies?"
|
And I should see "The best way to chub."
|
||||||
And I should see "Chubbies tests Diaspora's OAuth capabilities."
|
And there is only one Chubbies
|
||||||
|
|
||||||
When I press "Yes"
|
When I press "Authorize"
|
||||||
Then I should be on "/account" on Chubbies
|
Then I should be on "/account" on Chubbies
|
||||||
And I should see my "profile.birthday"
|
And I should see my "profile.birthday"
|
||||||
And I should see my "name"
|
And I should see my "name"
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,28 @@ Given /^Chubbies has been killed$/ do
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^Chubbies is registered on my pod$/ do
|
Given /^Chubbies is registered on my pod$/ do
|
||||||
OAuth2::Provider.client_class.create! :name => 'Chubbies',
|
client = OAuth2::Provider.client_class.create_from_manifest!("localhost:#{Chubbies::PORT}/manifest.json")
|
||||||
:oauth_identifier => 'abcdefgh12345678',
|
params = {:client_id => client.oauth_identifier,
|
||||||
:oauth_secret => 'secret'
|
:client_secret => client.oauth_secret,
|
||||||
|
:host => "localhost:9887"}
|
||||||
|
RestClient.post("localhost:#{Chubbies::PORT}/register", params)
|
||||||
end
|
end
|
||||||
|
|
||||||
And /^I should see my "([^"]+)"/ do |code|
|
And /^I should see my "([^"]+)"/ do |code|
|
||||||
page.should have_content(@me.person.instance_eval(code).to_s)
|
page.should have_content(@me.person.instance_eval(code).to_s)
|
||||||
end
|
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
|
When /^I try to authorize Chubbies$/ do
|
||||||
# We need to reset the tokens saved in Chubbies,
|
# We need to reset the tokens saved in Chubbies,
|
||||||
# as we are clearing the Diaspora DB every scenario
|
# as we are clearing the Diaspora DB every scenario
|
||||||
Then 'I visit "/reset" on Chubbies'
|
Then 'I visit "/new" on Chubbies'
|
||||||
Then 'I visit "/" on Chubbies'
|
|
||||||
###
|
###
|
||||||
And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\""
|
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'
|
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}\""
|
||||||
|
|
@ -44,7 +49,7 @@ class Chubbies
|
||||||
|
|
||||||
def self.run
|
def self.run
|
||||||
@pid = fork do
|
@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
|
end
|
||||||
|
|
||||||
at_exit do
|
at_exit do
|
||||||
|
|
@ -69,7 +74,10 @@ class Chubbies
|
||||||
|
|
||||||
def self.running?
|
def self.running?
|
||||||
begin
|
begin
|
||||||
RestClient.get("localhost:#{PORT}")
|
begin
|
||||||
|
RestClient.get("localhost:#{PORT}/running")
|
||||||
|
rescue RestClient::ResourceNotFound
|
||||||
|
end
|
||||||
true
|
true
|
||||||
rescue Errno::ECONNREFUSED
|
rescue Errno::ECONNREFUSED
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,41 @@
|
||||||
module Chubbies
|
module Chubbies
|
||||||
require 'active_record'
|
require 'active_record'
|
||||||
require 'diaspora-client'
|
require 'diaspora-client'
|
||||||
`rm -f #{File.expand_path('../chubbies.sqlite3', __FILE__)}`
|
|
||||||
ActiveRecord::Base.establish_connection(
|
|
||||||
:adapter => "sqlite3",
|
|
||||||
:database => "chubbies.sqlite3"
|
|
||||||
)
|
|
||||||
|
|
||||||
ActiveRecord::Schema.define do
|
def self.reset_db
|
||||||
create_table :resource_servers do |t|
|
`rm -f #{File.expand_path('../chubbies.sqlite3', __FILE__)}`
|
||||||
t.string :client_id, :limit => 40, :null => false
|
ActiveRecord::Base.establish_connection(
|
||||||
t.string :client_secret, :limit => 40, :null => false
|
:adapter => "sqlite3",
|
||||||
t.string :host, :limit => 127, :null => false
|
:database => "chubbies.sqlite3"
|
||||||
t.timestamps
|
)
|
||||||
end
|
|
||||||
add_index :resource_servers, :host, :unique => true
|
|
||||||
|
|
||||||
create_table :access_tokens do |t|
|
ActiveRecord::Schema.define do
|
||||||
t.integer :user_id, :null => false
|
create_table :resource_servers do |t|
|
||||||
t.integer :resource_server_id, :null => false
|
t.string :client_id, :limit => 40, :null => false
|
||||||
t.string :access_token, :limit => 40, :null => false
|
t.string :client_secret, :limit => 40, :null => false
|
||||||
t.string :refresh_token, :limit => 40, :null => false
|
t.string :host, :limit => 127, :null => false
|
||||||
t.string :uid, :limit => 40, :null => false
|
t.timestamps
|
||||||
t.datetime :expires_at
|
end
|
||||||
t.timestamps
|
add_index :resource_servers, :host, :unique => true
|
||||||
end
|
|
||||||
add_index :access_tokens, :user_id, :unique => true
|
create_table :access_tokens do |t|
|
||||||
create_table :users do |t|
|
t.integer :user_id, :null => false
|
||||||
t.timestamps
|
t.integer :resource_server_id, :null => false
|
||||||
|
t.string :access_token, :limit => 40, :null => false
|
||||||
|
t.string :refresh_token, :limit => 40, :null => false
|
||||||
|
t.string :uid, :limit => 40, :null => false
|
||||||
|
t.datetime :expires_at
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :access_tokens, :user_id, :unique => true
|
||||||
|
create_table :users do |t|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.reset_db
|
||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
has_one :access_token, :class_name => "DiasporaClient::AccessToken", :dependent => :destroy
|
has_one :access_token, :class_name => "DiasporaClient::AccessToken", :dependent => :destroy
|
||||||
end
|
end
|
||||||
|
|
@ -51,8 +56,12 @@ module Chubbies
|
||||||
|
|
||||||
get '/account' do
|
get '/account' do
|
||||||
if params['id'] && user = User.where(:id => params['id']).first
|
if params['id'] && user = User.where(:id => params['id']).first
|
||||||
@resource_response = user.access_token.token.get("/api/v0/me")
|
if user.access_token
|
||||||
haml :response
|
@resource_response = user.access_token.token.get("/api/v0/me")
|
||||||
|
haml :response
|
||||||
|
else
|
||||||
|
"No access token."
|
||||||
|
end
|
||||||
else
|
else
|
||||||
"No user with id #{params['id']}"
|
"No user with id #{params['id']}"
|
||||||
end
|
end
|
||||||
|
|
@ -71,5 +80,12 @@ module Chubbies
|
||||||
"icon_url" => "#"
|
"icon_url" => "#"
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
get '/reset' do
|
||||||
|
Chubbies.reset_db
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/register' do
|
||||||
|
DiasporaClient::ResourceServer.create!(params)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue