Skip to content

Commit

Permalink
closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Kiger committed Apr 23, 2012
1 parent 4656143 commit 046b015
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/restful_api_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def authenticated?
# client must have is_master flag set to true to pass authentication
# returns a 401 not authorized if the authentication headers are missing or invalid
def authenticated_master?
checker = RestfulApiAuthentication::Checker.new(request.headers, request.fullpath, :require_master => true)
if checker.authorized?
checker = RestfulApiAuthentication::Checker.new(request.headers, request.fullpath)
if checker.authorized?({:require_master => true})
return true
else
respond_with(["not authorized"], :status => 401, :location => nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/restful_api_authentication/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module RestfulApiAuthentication
VERSION = "0.1.0"
VERSION = "0.1.1"
end
2 changes: 1 addition & 1 deletion test/dummy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gem 'jquery-rails'
gem 'uuid', '2.3.5'
gem 'chronic', '0.6.7'
gem 'sqlite3'
gem 'restful_api_authentication', '0.1.0', :path => '/Users/dkiger/git_repos/restful_api_authentication'
gem 'restful_api_authentication', '0.1.1', :path => '/Users/dkiger/git_repos/restful_api_authentication'

group :assets do
gem 'sass-rails', '~> 3.2.3'
Expand Down
6 changes: 6 additions & 0 deletions test/dummy/app/controllers/help_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
class HelpController < ApplicationController
skip_before_filter :authenticated?, :only => [:master_authentication]
before_filter :authenticated_master?, :only => [:master_authentication]
def authentication
respond_with(["authorized"], :status => 200, :location => nil)
end

def master_authentication
respond_with(["authorized"], :status => 200, :location => nil)
end
end
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resources :help, :only => [] do
collection do
get "authentication"
get "master_authentication"
end
end
end
23 changes: 23 additions & 0 deletions test/dummy/features/api/master_authentication.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Authentication Testing
The web service provides a way to test authentication.

Scenario: When I post a request as JSON with valid authentication credentials, then the app will say I am authorized.
Given I am authenticated
Given I have master permissions
When I perform a GET to "/help/master_authentication" as JSON
Then the HTTP status code should be "200"
And the response at index 0 of the JSON response data should be "authorized"

Scenario: When I post a request as XML with valid authentication credentials, then the app will say I am authorized.
Given I am authenticated
Given I have master permissions
When I perform a GET to "/help/master_authentication" as XML
Then the HTTP status code should be "200"
And the response at index 0 of the XML response data should be "authorized"

Scenario: When I post a request as HTTP with valid authentication credentials, then the app will say I am authorized.
Given I am authenticated
Given I have master permissions
When I perform a GET to "/help/master_authentication" as HTTP
Then the HTTP status code should be "200"
And the response at index 0 of the JSON response data should be "authorized"

0 comments on commit 046b015

Please sign in to comment.