Skip to content

Commit

Permalink
Merge ff98fc2 into 51da685
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanagtmaal committed Jun 14, 2018
2 parents 51da685 + ff98fc2 commit 7544027
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion proxmoxer/backends/https.py
Expand Up @@ -109,7 +109,11 @@ def request(self, method, url, params=None, data=None, headers=None, cookies=Non
class Backend(object):
def __init__(self, host, user, password, port=8006, verify_ssl=True,
mode='json', timeout=5, auth_token=None, csrf_token=None):
self.base_url = "https://{0}:{1}/api2/{2}".format(host, port, mode)
if ':' in host and host.split(':')[1].isdigit():
self.base_url = "https://{0}/api2/{1}".format(host, mode)
else:
self.base_url = "https://{0}:{1}/api2/{2}".format(host, port, mode)

if auth_token is not None:
self.auth = ProxmoxHTTPTokenAuth(auth_token, csrf_token)
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/https_tests.py
Expand Up @@ -20,6 +20,19 @@ def test_https_connection(req_session):
eq_(call['verify'], False)


@patch('requests.sessions.Session')
def test_https_connection_wth_port_in_host(req_session):
response = {'ticket': 'ticket',
'CSRFPreventionToken': 'CSRFPreventionToken'}
req_session.request.return_value = response
ProxmoxAPI('proxmox:123', user='root@pam', password='secret', port=124, verify_ssl=False)
call = req_session.return_value.request.call_args[1]
eq_(call['url'], 'https://proxmox:123/api2/json/access/ticket')
eq_(call['data'], {'username': 'root@pam', 'password': 'secret'})
eq_(call['method'], 'post')
eq_(call['verify'], False)


class TestSuite():
proxmox = None
serializer = None
Expand Down

0 comments on commit 7544027

Please sign in to comment.