forked from pelle/oauth-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OAuth2 support in Rack Filter. First step to refactoring to rack. Specs.
- Loading branch information
Showing
8 changed files
with
261 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ pkg | |
*.gem | ||
.bundle | ||
.swp | ||
.idea | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
oauth-plugin (0.4.0.pre4) | ||
multi_json | ||
oauth (~> 0.4.4) | ||
rack | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
addressable (2.2.2) | ||
configuration (1.2.0) | ||
diff-lcs (1.1.2) | ||
fakeweb (1.3.0) | ||
faraday (0.5.4) | ||
addressable (~> 2.2.2) | ||
multipart-post (~> 1.1.0) | ||
rack (>= 1.1.0, < 2) | ||
faraday_middleware (0.3.1) | ||
faraday (~> 0.5.3) | ||
fuubar (0.0.3) | ||
rspec (~> 2.0) | ||
rspec-instafail (~> 0.1.4) | ||
ruby-progressbar (~> 0.0.9) | ||
growl (1.0.3) | ||
guard (0.2.2) | ||
open_gem (~> 1.4.2) | ||
thor (~> 0.14.3) | ||
guard-rspec (0.1.9) | ||
guard (>= 0.2.2) | ||
hashie (0.4.0) | ||
launchy (0.3.7) | ||
configuration (>= 0.0.5) | ||
rake (>= 0.8.1) | ||
multi_json (0.0.5) | ||
multi_xml (0.2.0) | ||
multipart-post (1.1.0) | ||
oauth (0.4.4) | ||
open_gem (1.4.2) | ||
launchy (~> 0.3.5) | ||
opentransact (0.1.0) | ||
multi_json | ||
multi_xml | ||
oauth (~> 0.4.4) | ||
rack (1.2.1) | ||
rack-test (0.5.6) | ||
rack (>= 1.0) | ||
rake (0.8.7) | ||
rspec (2.4.0) | ||
rspec-core (~> 2.4.0) | ||
rspec-expectations (~> 2.4.0) | ||
rspec-mocks (~> 2.4.0) | ||
rspec-core (2.4.0) | ||
rspec-expectations (2.4.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-instafail (0.1.5) | ||
rspec-mocks (2.4.0) | ||
ruby-progressbar (0.0.9) | ||
simple_oauth (0.1.3) | ||
thor (0.14.6) | ||
twitter (1.1.0) | ||
faraday (~> 0.5.3) | ||
faraday_middleware (~> 0.3.1) | ||
hashie (~> 0.4.0) | ||
multi_json (~> 0.0.5) | ||
multi_xml (~> 0.2.0) | ||
simple_oauth (~> 0.1.3) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
fakeweb | ||
fuubar | ||
growl | ||
guard-rspec | ||
multi_json | ||
oauth (~> 0.4.4) | ||
oauth-plugin! | ||
opentransact | ||
rack | ||
rack-test | ||
rspec (~> 2.4.0) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# A sample Guardfile | ||
# More info at http://github.com/guard/guard#readme | ||
|
||
guard 'rspec', :version => 2 do | ||
watch('^spec/(.*)_spec.rb') | ||
watch('^lib/oauth/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('^spec/spec_helper.rb') { "spec" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
require 'spec_helper' | ||
require 'rack/test' | ||
require 'oauth/rack/oauth_filter' | ||
require 'multi_json' | ||
require 'forwardable' | ||
class OAuthEcho | ||
def call(env) | ||
response = {} | ||
response[:oauth_token] = env["oauth.token"].token if env["oauth.token"] | ||
response[:client_application] = env["oauth.client_application"].key if env["oauth.client_application"] | ||
response[:oauth_version] = env["oauth.version"] if env["oauth.version"] | ||
[200 ,{"Accept"=>"application/json"}, [MultiJson.encode(response)] ] | ||
end | ||
end | ||
|
||
# Dummy implementation | ||
class ClientApplication | ||
attr_accessor :key | ||
|
||
def self.find_by_key(key) | ||
ClientApplication.new(key) | ||
end | ||
|
||
def initialize(key) | ||
@key = key | ||
end | ||
|
||
def secret | ||
"secret" | ||
end | ||
end | ||
|
||
class OauthToken | ||
attr_accessor :token | ||
|
||
def self.find_by_token(token) | ||
OauthToken.new(token) | ||
end | ||
|
||
def initialize(token) | ||
@token = token | ||
end | ||
|
||
def secret | ||
"secret" | ||
end | ||
end | ||
|
||
class Oauth2Token < OauthToken ; end | ||
|
||
class OauthNonce | ||
# Always remember | ||
def self.remember(nonce,timestamp) | ||
true | ||
end | ||
end | ||
|
||
describe OAuth::Rack::OAuthFilter do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
@app ||= OAuth::Rack::OAuthFilter.new(OAuthEcho.new) | ||
end | ||
|
||
it "should pass through without oauth" do | ||
get '/' | ||
last_response.should be_ok | ||
response = MultiJson.decode(last_response.body) | ||
response.should == {} | ||
end | ||
|
||
# it "should sign with consumer" do | ||
# consumer = "consumer" | ||
# get '/' | ||
# last_response.should be_ok | ||
# response = MultiJson.decode(last_response.body) | ||
# response.should == {"client_application" => consumer} | ||
# end | ||
|
||
it "should authenticate with oauth2 auth header" do | ||
get '/',{},{"HTTP_AUTHORIZATION"=>"OAuth my_token"} | ||
last_response.should be_ok | ||
response = MultiJson.decode(last_response.body) | ||
response.should == {"oauth_token" => "my_token", "oauth_version"=>2} | ||
end | ||
|
||
it "should authenticate with pre draft 10 oauth2 auth header" do | ||
get '/',{},{"HTTP_AUTHORIZATION"=>"Token my_token"} | ||
last_response.should be_ok | ||
response = MultiJson.decode(last_response.body) | ||
response.should == {"oauth_token" => "my_token", "oauth_version"=>2} | ||
end | ||
|
||
it "should authenticate with oauth2 query parameter" do | ||
get '/?oauth_token=my_token' | ||
last_response.should be_ok | ||
response = MultiJson.decode(last_response.body) | ||
response.should == {"oauth_token" => "my_token", "oauth_version"=>2} | ||
end | ||
|
||
it "should authenticate with oauth2 post parameter" do | ||
post '/', :oauth_token=>'my_token' | ||
last_response.should be_ok | ||
response = MultiJson.decode(last_response.body) | ||
response.should == {"oauth_token" => "my_token", "oauth_version"=>2} | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
require 'rspec' |