2012-05-08 15:01:35 +04:00
|
|
|
Feature: OAuth authentication
|
|
|
|
Background:
|
|
|
|
Given I am in "dotfiles" git repo
|
|
|
|
|
|
|
|
Scenario: Ask for username & password, create authorization
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2014-12-24 00:58:04 +03:00
|
|
|
require 'socket'
|
|
|
|
require 'etc'
|
|
|
|
machine_id = "#{Etc.getlogin}@#{Socket.gethostname}"
|
|
|
|
|
2012-05-08 15:01:35 +04:00
|
|
|
post('/authorizations') {
|
2014-12-24 00:58:04 +03:00
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
2019-09-14 05:02:53 +03:00
|
|
|
assert :scopes => ['repo', 'gist'],
|
2014-12-24 00:58:04 +03:00
|
|
|
:note => "hub for #{machine_id}",
|
2018-11-28 05:20:10 +03:00
|
|
|
:note_url => 'https://hub.github.com/'
|
2018-01-29 20:51:51 +03:00
|
|
|
status 201
|
2012-10-10 15:50:23 +04:00
|
|
|
json :token => 'OTOKEN'
|
2012-05-08 15:01:35 +04:00
|
|
|
}
|
2012-11-24 23:22:22 +04:00
|
|
|
get('/user') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
|
|
|
|
json :login => 'MiSlAv'
|
|
|
|
}
|
2012-11-22 15:55:28 +04:00
|
|
|
post('/user/repos') {
|
2012-11-24 23:22:22 +04:00
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2012-11-22 15:55:28 +04:00
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
2012-05-08 15:01:35 +04:00
|
|
|
"""
|
|
|
|
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
|
2019-08-21 18:28:31 +03:00
|
|
|
And the file "~/.config/hub" should contain "user: MiSlAv"
|
|
|
|
And the file "~/.config/hub" should contain "oauth_token: OTOKEN"
|
|
|
|
And the file "~/.config/hub" should have mode "0600"
|
2012-05-08 15:01:35 +04:00
|
|
|
|
2018-05-16 19:00:19 +03:00
|
|
|
Scenario: Prompt for username & password, receive personal access token
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token 0123456789012345678901234567890123456789'
|
|
|
|
json :login => 'llIMLLib'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token 0123456789012345678901234567890123456789'
|
|
|
|
status 201
|
|
|
|
json :full_name => 'llimllib/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "llimllib"
|
|
|
|
And I type "0123456789012345678901234567890123456789"
|
|
|
|
And the exit status should be 0
|
|
|
|
And the file "../home/.config/hub" should contain "user: llIMLLib"
|
|
|
|
And the file "../home/.config/hub" should contain:
|
|
|
|
"""
|
|
|
|
oauth_token: "0123456789012345678901234567890123456789"
|
|
|
|
"""
|
|
|
|
|
|
|
|
Scenario: Ask for username & password, receive password that looks like a token
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
post('/authorizations') {
|
|
|
|
assert_basic_auth 'llimllib', '0123456789012345678901234567890123456789'
|
|
|
|
status 201
|
|
|
|
json :token => 'OTOKEN'
|
|
|
|
}
|
|
|
|
get('/user') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
|
|
|
|
json :login => 'llIMLLib'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
|
|
|
|
status 201
|
|
|
|
json :full_name => 'llimllib/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "llimllib"
|
|
|
|
And I type "0123456789012345678901234567890123456789"
|
|
|
|
And the exit status should be 0
|
|
|
|
And the file "../home/.config/hub" should contain "user: llIMLLib"
|
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
|
|
|
|
2014-12-24 00:58:04 +03:00
|
|
|
Scenario: Rename & retry creating authorization if there's a token name collision
|
2012-05-08 15:01:35 +04:00
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2014-12-24 00:58:04 +03:00
|
|
|
require 'socket'
|
|
|
|
require 'etc'
|
|
|
|
machine_id = "#{Etc.getlogin}@#{Socket.gethostname}"
|
2012-05-08 15:01:35 +04:00
|
|
|
|
2014-02-28 19:17:01 +04:00
|
|
|
post('/authorizations') {
|
2014-12-24 00:58:04 +03:00
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
|
|
|
if params[:note] == "hub for #{machine_id} 3"
|
2018-01-29 20:51:51 +03:00
|
|
|
status 201
|
2014-12-24 00:58:04 +03:00
|
|
|
json :token => 'OTOKEN'
|
|
|
|
else
|
|
|
|
status 422
|
|
|
|
json :message => 'Validation Failed',
|
|
|
|
:errors => [{
|
|
|
|
:resource => 'OauthAccess',
|
|
|
|
:code => 'already_exists',
|
|
|
|
:field => 'description'
|
|
|
|
}]
|
|
|
|
end
|
2014-02-28 19:17:01 +04:00
|
|
|
}
|
|
|
|
get('/user') {
|
2014-12-24 00:58:04 +03:00
|
|
|
json :login => 'MiSlAv'
|
2014-02-28 19:17:01 +04:00
|
|
|
}
|
|
|
|
post('/user/repos') {
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2014-02-28 19:17:01 +04:00
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "mislav"
|
|
|
|
And I type "kitty"
|
2014-12-24 00:58:04 +03:00
|
|
|
Then the output should contain "github.com username:"
|
2014-02-28 19:17:01 +04:00
|
|
|
And the exit status should be 0
|
2014-09-15 05:35:43 +04:00
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
2014-02-28 19:17:01 +04:00
|
|
|
|
2014-12-24 00:58:04 +03:00
|
|
|
Scenario: Avoid getting caught up in infinite recursion while retrying token names
|
2014-05-15 22:10:44 +04:00
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2014-12-24 00:58:04 +03:00
|
|
|
tries = 0
|
2014-05-15 22:10:44 +04:00
|
|
|
post('/authorizations') {
|
2014-12-24 00:58:04 +03:00
|
|
|
tries += 1
|
|
|
|
halt 400, json(:message => "too many tries") if tries >= 10
|
2014-05-15 22:10:44 +04:00
|
|
|
status 422
|
2014-12-24 00:58:04 +03:00
|
|
|
json :message => 'Validation Failed',
|
|
|
|
:errors => [{
|
|
|
|
:resource => 'OauthAccess',
|
|
|
|
:code => 'already_exists',
|
|
|
|
:field => 'description'
|
|
|
|
}]
|
2014-02-28 19:17:01 +04:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "mislav"
|
|
|
|
And I type "kitty"
|
2014-12-24 00:58:04 +03:00
|
|
|
Then the output should contain:
|
|
|
|
"""
|
|
|
|
Error creating repository: Unprocessable Entity (HTTP 422)
|
|
|
|
Duplicate value for "description"
|
|
|
|
"""
|
|
|
|
And the exit status should be 1
|
2016-10-31 14:31:32 +03:00
|
|
|
And the file "../home/.config/hub" should not exist
|
2014-02-28 19:17:01 +04:00
|
|
|
|
2012-11-06 00:40:12 +04:00
|
|
|
Scenario: Credentials from GITHUB_USER & GITHUB_PASSWORD
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2014-12-24 00:58:04 +03:00
|
|
|
post('/authorizations') {
|
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2014-12-24 00:58:04 +03:00
|
|
|
json :token => 'OTOKEN'
|
2012-11-06 00:40:12 +04:00
|
|
|
}
|
2012-11-24 23:22:22 +04:00
|
|
|
get('/user') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
2012-11-22 15:55:28 +04:00
|
|
|
post('/user/repos') {
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2012-11-22 15:55:28 +04:00
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
2012-11-06 00:40:12 +04:00
|
|
|
"""
|
|
|
|
Given $GITHUB_USER is "mislav"
|
|
|
|
And $GITHUB_PASSWORD is "kitty"
|
|
|
|
When I successfully run `hub create`
|
|
|
|
Then the output should not contain "github.com password for mislav"
|
2014-09-15 05:35:43 +04:00
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
2012-11-06 00:40:12 +04:00
|
|
|
|
2018-06-07 20:57:02 +03:00
|
|
|
Scenario: XDG: legacy config found, credentials from GITHUB_USER & GITHUB_PASSWORD
|
|
|
|
Given I am "mislav" on github.com with OAuth token "LTOKEN"
|
|
|
|
And the GitHub API server:
|
|
|
|
"""
|
|
|
|
post('/authorizations') {
|
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
|
|
|
status 201
|
|
|
|
json :token => 'OTOKEN'
|
|
|
|
}
|
|
|
|
get('/user') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
|
|
|
|
status 201
|
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
And $GITHUB_USER is "mislav"
|
|
|
|
And $GITHUB_PASSWORD is "kitty"
|
|
|
|
And $XDG_CONFIG_HOME is "$HOME/.xdg"
|
|
|
|
When I successfully run `hub create`
|
|
|
|
Then the file "../home/.xdg/hub" should contain "oauth_token: OTOKEN"
|
2019-08-21 19:22:48 +03:00
|
|
|
And the stderr with expanded variables should contain exactly:
|
2018-06-07 20:57:02 +03:00
|
|
|
"""
|
2019-08-21 19:22:48 +03:00
|
|
|
Notice: config file found but not respected at: <$HOME>/.config/hub
|
|
|
|
You might want to move it to `<$HOME>/.xdg/hub' to avoid re-authenticating.\n
|
2018-06-07 20:57:02 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
Scenario: XDG: config from secondary directories
|
|
|
|
Given I am "mislav" on github.com with OAuth token "OTOKEN"
|
|
|
|
And the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
|
|
|
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
|
|
|
|
status 201
|
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
And $GITHUB_USER is "mislav"
|
|
|
|
And $GITHUB_PASSWORD is "kitty"
|
|
|
|
And $XDG_CONFIG_HOME is "$HOME/.xdg"
|
|
|
|
And $XDG_CONFIG_DIRS is "/etc/xdg-nonsense:$HOME/.xdg-dir"
|
|
|
|
When I move the file named "../home/.config/hub" to "../home/.xdg-dir/hub"
|
|
|
|
And I successfully run `hub create`
|
|
|
|
Then the file "../home/.xdg/hub" should not exist
|
|
|
|
And the stderr should contain exactly ""
|
|
|
|
|
2015-07-09 21:51:50 +03:00
|
|
|
Scenario: Credentials from GITHUB_TOKEN
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token OTOKEN"
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
|
|
|
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token OTOKEN"
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2015-07-09 21:51:50 +03:00
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
Given $GITHUB_TOKEN is "OTOKEN"
|
|
|
|
When I successfully run `hub create`
|
|
|
|
Then the output should not contain "github.com password"
|
|
|
|
And the output should not contain "github.com username"
|
|
|
|
And the file "../home/.config/hub" should not exist
|
|
|
|
|
2019-07-19 15:05:36 +03:00
|
|
|
Scenario: Credentials from GITHUB_TOKEN when obtaining username fails
|
|
|
|
Given I am in "git://github.com/monalisa/playground.git" git repo
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
status 403
|
|
|
|
json :message => "Resource not accessible by integration",
|
|
|
|
:documentation_url => "https://developer.github.com/v3/users/#get-the-authenticated-user"
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
Given $GITHUB_TOKEN is "OTOKEN"
|
|
|
|
Given $GITHUB_USER is ""
|
|
|
|
When I run `hub release show v1.2.0`
|
|
|
|
Then the output should not contain "github.com password"
|
|
|
|
And the output should not contain "github.com username"
|
|
|
|
And the file "../home/.config/hub" should not exist
|
|
|
|
And the exit status should be 1
|
|
|
|
And the stderr should contain exactly:
|
|
|
|
"""
|
|
|
|
Error getting current user: Forbidden (HTTP 403)
|
2019-07-19 15:12:08 +03:00
|
|
|
Resource not accessible by integration
|
|
|
|
You must specify GITHUB_USER via environment variable.\n
|
2019-07-19 15:05:36 +03:00
|
|
|
"""
|
|
|
|
|
2019-07-19 15:12:08 +03:00
|
|
|
Scenario: Credentials from GITHUB_TOKEN and GITHUB_USER
|
|
|
|
Given I am in "git://github.com/monalisa/playground.git" git repo
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
status 403
|
|
|
|
json :message => "Resource not accessible by integration",
|
|
|
|
:documentation_url => "https://developer.github.com/v3/users/#get-the-authenticated-user"
|
|
|
|
}
|
|
|
|
get('/repos/monalisa/playground/releases') {
|
|
|
|
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token OTOKEN"
|
|
|
|
json [
|
|
|
|
{ tag_name: 'v1.2.0',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
Given $GITHUB_TOKEN is "OTOKEN"
|
|
|
|
Given $GITHUB_USER is "hubot"
|
|
|
|
When I successfully run `hub release show v1.2.0`
|
|
|
|
Then the output should not contain "github.com password"
|
|
|
|
And the output should not contain "github.com username"
|
|
|
|
And the file "../home/.config/hub" should not exist
|
|
|
|
|
2019-09-04 02:43:08 +03:00
|
|
|
Scenario: Credentials from GITHUB_TOKEN and GITHUB_REPOSITORY
|
|
|
|
Given I am in "git://github.com/monalisa/playground.git" git repo
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
status 403
|
|
|
|
json :message => "Resource not accessible by integration",
|
|
|
|
:documentation_url => "https://developer.github.com/v3/users/#get-the-authenticated-user"
|
|
|
|
}
|
|
|
|
get('/repos/monalisa/playground/releases') {
|
|
|
|
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token OTOKEN"
|
|
|
|
json [
|
|
|
|
{ tag_name: 'v1.2.0',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
Given $GITHUB_TOKEN is "OTOKEN"
|
|
|
|
Given $GITHUB_REPOSITORY is "mona-lisa/play-ground"
|
|
|
|
Given $GITHUB_USER is ""
|
|
|
|
When I successfully run `hub release show v1.2.0`
|
|
|
|
Then the output should not contain "github.com password"
|
|
|
|
And the output should not contain "github.com username"
|
|
|
|
And the file "../home/.config/hub" should not exist
|
|
|
|
|
2015-09-25 04:59:43 +03:00
|
|
|
Scenario: Credentials from GITHUB_TOKEN override those from config file
|
|
|
|
Given I am "mislav" on github.com with OAuth token "OTOKEN"
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/user') {
|
|
|
|
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token PTOKEN"
|
|
|
|
json :login => 'parkr'
|
|
|
|
}
|
|
|
|
get('/repos/parkr/dotfiles') {
|
|
|
|
halt 401 unless request.env["HTTP_AUTHORIZATION"] == "token PTOKEN"
|
|
|
|
json :private => false,
|
2018-01-29 19:17:14 +03:00
|
|
|
:name => 'dotfiles', :owner => { :login => 'parkr' },
|
2015-09-25 04:59:43 +03:00
|
|
|
:permissions => { :push => true }
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
Given $GITHUB_TOKEN is "PTOKEN"
|
|
|
|
When I successfully run `hub clone dotfiles`
|
|
|
|
Then it should clone "git@github.com:parkr/dotfiles.git"
|
|
|
|
And the file "../home/.config/hub" should contain "user: mislav"
|
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
|
|
|
|
2012-05-08 15:01:35 +04:00
|
|
|
Scenario: Wrong password
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2014-12-24 00:58:04 +03:00
|
|
|
post('/authorizations') {
|
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
2012-05-08 15:01:35 +04:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "mislav"
|
|
|
|
And I type "WRONG"
|
2014-12-24 00:58:04 +03:00
|
|
|
Then the stderr should contain exactly:
|
|
|
|
"""
|
|
|
|
Error creating repository: Unauthorized (HTTP 401)
|
|
|
|
Bad credentials
|
|
|
|
|
|
|
|
"""
|
2012-05-08 15:01:35 +04:00
|
|
|
And the exit status should be 1
|
2016-10-31 14:31:32 +03:00
|
|
|
And the file "../home/.config/hub" should not exist
|
2013-09-20 02:29:09 +04:00
|
|
|
|
2014-12-24 00:58:04 +03:00
|
|
|
Scenario: Two-factor authentication, create authorization
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2013-10-01 13:53:29 +04:00
|
|
|
post('/authorizations') {
|
2014-12-24 00:58:04 +03:00
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
|
|
|
if request.env['HTTP_X_GITHUB_OTP'] == '112233'
|
2018-01-29 20:51:51 +03:00
|
|
|
status 201
|
2014-12-24 00:58:04 +03:00
|
|
|
json :token => 'OTOKEN'
|
|
|
|
else
|
|
|
|
response.headers['X-GitHub-OTP'] = 'required; app'
|
|
|
|
status 401
|
|
|
|
json :message => "Must specify two-factor authentication OTP code."
|
2013-10-01 13:53:29 +04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
get('/user') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2013-10-01 13:53:29 +04:00
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "mislav"
|
|
|
|
And I type "kitty"
|
|
|
|
And I type "112233"
|
|
|
|
Then the output should contain "github.com password for mislav (never stored):"
|
|
|
|
Then the output should contain "two-factor authentication code:"
|
2014-12-24 00:58:04 +03:00
|
|
|
And the output should not contain "warning: invalid two-factor code"
|
2013-10-01 13:53:29 +04:00
|
|
|
And the exit status should be 0
|
2014-09-15 05:35:43 +04:00
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
2013-10-01 13:53:29 +04:00
|
|
|
|
2014-12-24 00:58:04 +03:00
|
|
|
Scenario: Retry entering two-factor authentication code
|
2013-09-20 02:29:09 +04:00
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
2014-12-24 00:58:04 +03:00
|
|
|
previous_otp_code = nil
|
2013-12-18 16:56:08 +04:00
|
|
|
post('/authorizations') {
|
|
|
|
assert_basic_auth 'mislav', 'kitty'
|
2014-12-24 00:58:04 +03:00
|
|
|
if request.env['HTTP_X_GITHUB_OTP'] == '112233'
|
|
|
|
halt 400 unless '666' == previous_otp_code
|
2018-01-29 20:51:51 +03:00
|
|
|
status 201
|
2014-12-24 00:58:04 +03:00
|
|
|
json :token => 'OTOKEN'
|
|
|
|
else
|
|
|
|
previous_otp_code = request.env['HTTP_X_GITHUB_OTP']
|
|
|
|
response.headers['X-GitHub-OTP'] = 'required; app'
|
|
|
|
status 401
|
|
|
|
json :message => "Must specify two-factor authentication OTP code."
|
2013-09-20 02:29:09 +04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
get('/user') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
|
|
|
post('/user/repos') {
|
2018-01-29 19:28:50 +03:00
|
|
|
status 201
|
2013-09-20 02:29:09 +04:00
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
|
|
|
When I type "mislav"
|
|
|
|
And I type "kitty"
|
2014-12-24 00:58:04 +03:00
|
|
|
And I type "666"
|
2013-09-20 02:29:09 +04:00
|
|
|
And I type "112233"
|
2014-12-24 00:58:04 +03:00
|
|
|
Then the output should contain "warning: invalid two-factor code"
|
2013-09-20 02:29:09 +04:00
|
|
|
And the exit status should be 0
|
2014-12-24 00:58:04 +03:00
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
2013-09-30 09:25:36 +04:00
|
|
|
|
|
|
|
Scenario: Special characters in username & password
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
post('/authorizations') {
|
2013-10-12 01:15:35 +04:00
|
|
|
assert_basic_auth 'mislav@example.com', 'my pass@phrase ok?'
|
2018-01-29 20:51:51 +03:00
|
|
|
status 201
|
2013-09-30 09:25:36 +04:00
|
|
|
json :token => 'OTOKEN'
|
|
|
|
}
|
|
|
|
get('/user') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
2018-08-31 14:00:04 +03:00
|
|
|
get('/repos/mislav/dotfiles') {
|
|
|
|
json :full_name => 'mislav/dotfiles'
|
|
|
|
}
|
2013-09-30 09:25:36 +04:00
|
|
|
"""
|
|
|
|
When I run `hub create` interactively
|
2013-10-12 01:15:35 +04:00
|
|
|
When I type "mislav@example.com"
|
2013-09-30 09:25:36 +04:00
|
|
|
And I type "my pass@phrase ok?"
|
2013-10-12 01:15:35 +04:00
|
|
|
Then the output should contain "github.com password for mislav@example.com (never stored):"
|
|
|
|
And the exit status should be 0
|
2014-09-15 05:35:43 +04:00
|
|
|
And the file "../home/.config/hub" should contain "user: mislav"
|
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
2014-12-25 02:47:00 +03:00
|
|
|
|
|
|
|
Scenario: Enterprise fork authentication with username & password, re-using existing authorization
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
require 'rack/auth/basic'
|
|
|
|
post('/api/v3/authorizations', :host_name => 'git.my.org') {
|
|
|
|
auth = Rack::Auth::Basic::Request.new(env)
|
|
|
|
halt 401 unless auth.credentials == %w[mislav kitty]
|
2018-01-29 20:51:51 +03:00
|
|
|
status 201
|
2018-11-28 05:20:10 +03:00
|
|
|
json :token => 'OTOKEN', :note_url => 'https://hub.github.com/'
|
2014-12-25 02:47:00 +03:00
|
|
|
}
|
|
|
|
get('/api/v3/user', :host_name => 'git.my.org') {
|
|
|
|
json :login => 'mislav'
|
|
|
|
}
|
2016-08-08 15:20:06 +03:00
|
|
|
post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') {
|
|
|
|
status 202
|
|
|
|
json :name => 'dotfiles', :owner => { :login => 'mislav' }
|
|
|
|
}
|
2014-12-25 02:47:00 +03:00
|
|
|
"""
|
|
|
|
And "git.my.org" is a whitelisted Enterprise host
|
|
|
|
And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
|
|
|
|
When I run `hub fork` interactively
|
|
|
|
And I type "mislav"
|
|
|
|
And I type "kitty"
|
|
|
|
Then the output should contain "git.my.org password for mislav (never stored):"
|
|
|
|
And the exit status should be 0
|
|
|
|
And the file "../home/.config/hub" should contain "git.my.org"
|
|
|
|
And the file "../home/.config/hub" should contain "user: mislav"
|
|
|
|
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
|
|
|
|
And the url for "mislav" should be "git@git.my.org:mislav/dotfiles.git"
|
2016-02-14 03:40:29 +03:00
|
|
|
|
|
|
|
Scenario: Broken config is missing user.
|
|
|
|
Given a file named "../home/.config/hub" with:
|
|
|
|
"""
|
|
|
|
github.com:
|
|
|
|
- oauth_token: OTOKEN
|
|
|
|
protocol: https
|
|
|
|
"""
|
|
|
|
And the "origin" remote has url "git://github.com/mislav/coral.git"
|
|
|
|
When I run `hub browse -u` interactively
|
|
|
|
And I type "pcorpet"
|
|
|
|
Then the output should contain "github.com username:"
|
|
|
|
And the file "../home/.config/hub" should contain "- user: pcorpet"
|
|
|
|
And the file "../home/.config/hub" should contain " oauth_token: OTOKEN"
|
|
|
|
|
|
|
|
Scenario: Broken config is missing user and interactive input is empty.
|
|
|
|
Given a file named "../home/.config/hub" with:
|
|
|
|
"""
|
|
|
|
github.com:
|
|
|
|
- oauth_token: OTOKEN
|
|
|
|
protocol: https
|
|
|
|
"""
|
|
|
|
And the "origin" remote has url "git://github.com/mislav/coral.git"
|
|
|
|
When I run `hub browse -u` interactively
|
|
|
|
And I type ""
|
|
|
|
Then the output should contain "github.com username:"
|
|
|
|
And the output should contain "missing user"
|
|
|
|
And the file "../home/.config/hub" should not contain "user"
|
2016-10-30 19:23:05 +03:00
|
|
|
|
2016-10-31 14:31:32 +03:00
|
|
|
Scenario: Config file is not writeable, should exit before asking for credentials
|
|
|
|
Given $HUB_CONFIG is "/InvalidConfigFile"
|
2016-10-30 19:23:05 +03:00
|
|
|
When I run `hub create` interactively
|
|
|
|
Then the output should contain exactly:
|
|
|
|
"""
|
|
|
|
open /InvalidConfigFile: permission denied\n
|
|
|
|
"""
|
|
|
|
And the exit status should be 1
|
2016-10-31 14:31:32 +03:00
|
|
|
And the file "../home/.config/hub" should not exist
|
|
|
|
|
|
|
|
Scenario: Config file is not writeable on default location, should exit before asking for credentials
|
|
|
|
Given a directory named "../home/.config" with mode "600"
|
|
|
|
When I run `hub create` interactively
|
2019-08-21 19:22:48 +03:00
|
|
|
Then the output with expanded variables should contain:
|
2016-10-31 14:31:32 +03:00
|
|
|
"""
|
2019-08-21 19:22:48 +03:00
|
|
|
<$HOME>/.config/hub: permission denied\n
|
2016-10-31 14:31:32 +03:00
|
|
|
"""
|
|
|
|
And the exit status should be 1
|
|
|
|
And the file "../home/.config/hub" should not exist
|
2020-01-19 16:43:37 +03:00
|
|
|
|
|
|
|
Scenario: GitHub SSO challenge
|
|
|
|
Given I am "monalisa" on github.com with OAuth token "OTOKEN"
|
|
|
|
And I am in "git://github.com/acme/playground.git" git repo
|
|
|
|
Given the GitHub API server:
|
|
|
|
"""
|
|
|
|
get('/repos/acme/playground/releases') {
|
|
|
|
response.headers['X-GitHub-SSO'] = 'required; url=http://example.com?auth=HASH'
|
|
|
|
status 403
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
When I run `hub release show v1.2.0`
|
|
|
|
Then the stderr should contain exactly:
|
|
|
|
"""
|
|
|
|
Error fetching releases: Forbidden (HTTP 403)
|
|
|
|
You must authorize your token to access this organization:
|
|
|
|
http://example.com?auth=HASH
|
|
|
|
"""
|