Validate that HTTPS is used by default for API requests

Since we use a test server representing the GitHub API, all requests get
transformed to HTTP in tests. Make a check that the original requests
really was intended to go over HTTPS.
This commit is contained in:
Mislav Marohnić 2014-02-16 03:05:25 +01:00
Родитель aacc92f5ff
Коммит e6841d6848
2 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -7,7 +7,10 @@ Feature: hub fork
Scenario: Fork the repository
Given the GitHub API server:
"""
before { halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN' }
before {
halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'https'
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token OTOKEN'
}
get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
"""
@ -121,7 +124,10 @@ Scenario: Related fork already exists
Scenario: Enterprise fork
Given the GitHub API server:
"""
before { halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN' }
before {
halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'https'
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
}
post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' }
"""
And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"

Просмотреть файл

@ -248,6 +248,7 @@ module Hub
def configure_connection req, url
if ENV['HUB_TEST_HOST']
req['Host'] = url.host
req['X-Original-Scheme'] = url.scheme
url = url.dup
url.scheme = 'http'
url.host, test_port = ENV['HUB_TEST_HOST'].split(':')