Skip to content

Commit fc9b7c0

Browse files
committed
Merge branch 'develop' into py3-code-migration
2 parents 8cc4c21 + 418a174 commit fc9b7c0

File tree

7 files changed

+90
-5
lines changed

7 files changed

+90
-5
lines changed

.github/dependabot.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
target-branch: "master"
6+
schedule:
7+
interval: "weekly"

.github/workflows/release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ jobs:
2929
run: |
3030
rm -rf ./docs/_build
3131
tox -e docs
32-
cd ./docs/_build/html && zip -r ../docs_html.zip . -x ".*" -x "__MACOSX"
3332
- name : Docs Upload
3433
uses: actions/upload-artifact@v3
3534
with:
36-
name: apidocs
37-
path: docs/_build/docs_html.zip
35+
name: python_sdk_docs
36+
path: docs/_build/html
3837
# Test upload
3938
# - name: Publish package to TestPyPI
4039
# uses: pypa/gh-action-pypi-publish@master

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
- ubuntu-latest
1414
python: [ 3.7, 3.9, 3.10.7]
1515
splunk-version:
16+
- "8.1"
1617
- "8.2"
1718
- "latest"
1819
fail-fast: false

splunklib/binding.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
from http import client
3939
from http.cookies import SimpleCookie
4040
from xml.etree.ElementTree import XML, ParseError
41-
4241
from splunklib.data import record
42+
from splunklib import __version__
43+
4344

4445
logger = logging.getLogger(__name__)
4546

@@ -1443,7 +1444,7 @@ def request(url, message, **kwargs):
14431444
head = {
14441445
"Content-Length": str(len(body)),
14451446
"Host": host,
1446-
"User-Agent": "splunk-sdk-python/1.7.2",
1447+
"User-Agent": "splunk-sdk-python/%s" % __version__,
14471448
"Accept": "*/*",
14481449
"Connection": "Close",
14491450
} # defaults

splunklib/modularinput/event_writer.py

100755100644
File mode changed.

tests/test_binding.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,54 @@ def test_handlers(self):
488488
self.assertTrue(isatom(body))
489489

490490

491+
def urllib2_insert_cookie_handler(url, message, **kwargs):
492+
method = message['method'].lower()
493+
data = message.get('body', b"") if method == 'post' else None
494+
headers = dict(message.get('headers', []))
495+
req = Request(url, data, headers)
496+
try:
497+
response = urlopen(req, context=ssl._create_unverified_context())
498+
except HTTPError as response:
499+
pass # Propagate HTTP errors via the returned response message
500+
501+
# Mimic the insertion of 3rd party cookies into the response.
502+
# An example is "sticky session"/"insert cookie" persistence
503+
# of a load balancer for a SHC.
504+
header_list = [(k, v) for k, v in response.info().items()]
505+
header_list.append(("Set-Cookie", "BIGipServer_splunk-shc-8089=1234567890.12345.0000; path=/; Httponly; Secure"))
506+
header_list.append(("Set-Cookie", "home_made=yummy"))
507+
508+
return {
509+
'status': response.code,
510+
'reason': response.msg,
511+
'headers': header_list,
512+
'body': BytesIO(response.read())
513+
}
514+
515+
516+
class TestCookiePersistence(testlib.SDKTestCase):
517+
# Verify persistence of 3rd party inserted cookies.
518+
def test_3rdPartyInsertedCookiePersistence(self):
519+
paths = ["/services", "authentication/users",
520+
"search/jobs"]
521+
logging.debug("Connecting with urllib2_insert_cookie_handler %s", urllib2_insert_cookie_handler)
522+
context = binding.connect(
523+
handler=urllib2_insert_cookie_handler,
524+
**self.opts.kwargs)
525+
526+
persisted_cookies = context.get_cookies()
527+
528+
splunk_token_found = False
529+
for k, v in persisted_cookies.items():
530+
if k[:8] == "splunkd_":
531+
splunk_token_found = True
532+
break
533+
534+
self.assertEqual(splunk_token_found, True)
535+
self.assertEqual(persisted_cookies['BIGipServer_splunk-shc-8089'], "1234567890.12345.0000")
536+
self.assertEqual(persisted_cookies['home_made'], "yummy")
537+
538+
491539
@pytest.mark.smoke
492540
class TestLogout(BindingTestCase):
493541
def test_logout(self):

tests/test_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import unittest
2+
import os
3+
import sys
14
from tests import testlib
25
from utils import dslice
36

@@ -71,6 +74,32 @@ def test_dslice_all_args(self):
7174
self.assertTrue(expected == dslice(TEST_DICT, *test_args))
7275

7376

77+
class FilePermissionTest(unittest.TestCase):
78+
79+
def setUp(self):
80+
super(FilePermissionTest, self).setUp()
81+
82+
# Check for any change in the default file permission(i.e 644) for all files within splunklib
83+
def test_filePermissions(self):
84+
85+
def checkFilePermissions(dir_path):
86+
for file in os.listdir(dir_path):
87+
if file.__contains__('pycache'):
88+
continue
89+
path = os.path.join(dir_path, file)
90+
if os.path.isfile(path):
91+
permission = oct(os.stat(path).st_mode)
92+
if sys.version_info >= (3, 0):
93+
self.assertEqual(permission, '0o100644')
94+
else :
95+
self.assertEqual(permission, '0100644')
96+
else:
97+
checkFilePermissions(path)
98+
99+
dir_path = os.path.join('..', 'splunklib')
100+
checkFilePermissions(dir_path)
101+
102+
74103
if __name__ == "__main__":
75104
import unittest
76105

0 commit comments

Comments
 (0)