提交 e6841d68 编写于 作者: M Mislav Marohnić

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.
上级 aacc92f5
...@@ -7,7 +7,10 @@ Feature: hub fork ...@@ -7,7 +7,10 @@ Feature: hub fork
Scenario: Fork the repository Scenario: Fork the repository
Given the GitHub API server: 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 } get('/repos/mislav/dotfiles', :host_name => 'api.github.com') { 404 }
post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' } post('/repos/evilchelu/dotfiles/forks', :host_name => 'api.github.com') { '' }
""" """
...@@ -121,7 +124,10 @@ Scenario: Related fork already exists ...@@ -121,7 +124,10 @@ Scenario: Related fork already exists
Scenario: Enterprise fork Scenario: Enterprise fork
Given the GitHub API server: 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') { '' } 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" And the "origin" remote has url "git@git.my.org:evilchelu/dotfiles.git"
......
...@@ -248,6 +248,7 @@ module Hub ...@@ -248,6 +248,7 @@ module Hub
def configure_connection req, url def configure_connection req, url
if ENV['HUB_TEST_HOST'] if ENV['HUB_TEST_HOST']
req['Host'] = url.host req['Host'] = url.host
req['X-Original-Scheme'] = url.scheme
url = url.dup url = url.dup
url.scheme = 'http' url.scheme = 'http'
url.host, test_port = ENV['HUB_TEST_HOST'].split(':') url.host, test_port = ENV['HUB_TEST_HOST'].split(':')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册