-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow unverified SSL and additional HTTP headers #89
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# pylint: disable=protected-access,too-few-public-methods | ||
|
||
import ssl | ||
import sys | ||
from typing import Optional | ||
import urllib.parse | ||
|
||
from base64 import b64encode | ||
|
@@ -114,7 +116,14 @@ class TCMSXmlrpc: | |
session_cookie_name = "sessionid" | ||
transport = None | ||
|
||
def __init__(self, username, password, url): | ||
def __init__( | ||
self, | ||
username, | ||
password, | ||
url, | ||
allow_unverified_ssl: bool = False, | ||
extra_headers: list[tuple[str, str]] = [], | ||
): | ||
if self.transport is None: | ||
if url.startswith("https://"): | ||
self.transport = SafeCookieTransport() | ||
|
@@ -123,6 +132,12 @@ def __init__(self, username, password, url): | |
else: | ||
raise RuntimeError("Unrecognized URL scheme") | ||
|
||
if allow_unverified_ssl: | ||
ssl._create_default_https_context = ssl._create_unverified_context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is modifying the global state of the ssl module which potentially can lead to side effects depending on how that module and the tcms_api module are used by the developer. This could lead to very difficult to debug issues. This also affects the SSL module even if for whatever reason the user is connecting to a plain-text endpoint (e.g. reusing the same code base). Instead of doing it like this, see the |
||
|
||
if len(extra_headers) > 0: | ||
self.transport._headers += extra_headers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This possibly overrides an existing value set for this attribute. You can pass headers in |
||
|
||
self.server = TCMSProxy( | ||
url, transport=self.transport, verbose=VERBOSE, allow_none=1 | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will have to define these for the inherited class TCMSKerbXmlrpc, and take care to pass them down appropriately otherwise we have broken method signatures in the inheritance chain.