Skip to content

Commit

Permalink
test OAuth authentication flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed May 8, 2012
1 parent efff54b commit b90b16b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
61 changes: 61 additions & 0 deletions features/authentication.feature
@@ -0,0 +1,61 @@
Feature: OAuth authentication
Background:
Given I am in "dotfiles" git repo

Scenario: Ask for username & password, create authorization
Given the GitHub API server:
"""
require 'rack/auth/basic'
get('/authorizations') { '[]' }
post('/authorizations') {
auth = Rack::Auth::Basic::Request.new(env)
halt 401 unless auth.credentials == %w[mislav kitty]
halt 400 unless params[:scopes] == ['repo']
body :token => 'OTOKEN'
}
post('/user/repos') { status 200 }
"""
When I run `hub create` interactively
When I type "mislav"
And I type "kitty"
Then the output should contain "github.com username:"
And the output should contain "github.com password for mislav (never stored):"
And the exit status should be 0
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"

Scenario: Ask for username & password, re-use existing authorization
Given the GitHub API server:
"""
require 'rack/auth/basic'
get('/authorizations') {
auth = Rack::Auth::Basic::Request.new(env)
halt 401 unless auth.credentials == %w[mislav kitty]
body [
{:token => 'SKIPPD', :app => {:url => 'http://example.com'}},
{:token => 'OTOKEN', :app => {:url => 'http://defunkt.io/hub/'}}
]
}
post('/user/repos') { status 200 }
"""
When I run `hub create` interactively
When I type "mislav"
And I type "kitty"
Then the output should contain "github.com password for mislav (never stored):"
And the exit status should be 0
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"

Scenario: Wrong password
Given the GitHub API server:
"""
require 'rack/auth/basic'
get('/authorizations') {
auth = Rack::Auth::Basic::Request.new(env)
halt 401 unless auth.credentials == %w[mislav kitty]
}
"""
When I run `hub create` interactively
When I type "mislav"
And I type "WRONG"
Then the stderr should contain "Error creating repository: Unauthorized (HTTP 401)"
And the exit status should be 1
And the file "../home/.config/hub" should not exist
11 changes: 8 additions & 3 deletions lib/hub/github_api.rb
Expand Up @@ -343,9 +343,14 @@ def prompt what
# special prompt that has hidden input
def prompt_password host, user
print "#{host} password for #{user} (never stored): "
password = askpass
puts ''
password
if $stdin.tty?
password = askpass
puts ''
password
else
# in testing
$stdin.gets.chomp
end
end

# FIXME: probably not cross-platform
Expand Down

0 comments on commit b90b16b

Please sign in to comment.