Skip to content
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

updated file permission for event_writer.py #493

Merged
merged 12 commits into from
Nov 14, 2022
Empty file modified splunklib/modularinput/event_writer.py
100755 → 100644
Empty file.
90 changes: 60 additions & 30 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
from __future__ import absolute_import
from tests import testlib

import unittest
import os
import sys

try:
from utils import *
except ImportError:
raise Exception("Add the SDK repository to your PYTHONPATH to run the test cases "
"(e.g., export PYTHONPATH=~/splunk-sdk-python.")


TEST_DICT = {
'username':'admin',
'password':'changeme',
'port' : 8089,
'host' : 'localhost',
'scheme': 'https'
}
'username': 'admin',
'password': 'changeme',
'port': 8089,
'host': 'localhost',
'scheme': 'https'
}


class TestUtils(testlib.SDKTestCase):
def setUp(self):
Expand All @@ -23,16 +27,16 @@ def setUp(self):
# Test dslice when a dict is passed to change key names
def test_dslice_dict_args(self):
args = {
'username':'user-name',
'password':'new_password',
'port': 'admin_port',
'foo':'bar'
}
'username': 'user-name',
'password': 'new_password',
'port': 'admin_port',
'foo': 'bar'
}
expected = {
'user-name':'admin',
'new_password':'changeme',
'admin_port':8089
}
'user-name': 'admin',
'new_password': 'changeme',
'admin_port': 8089
}
self.assertTrue(expected == dslice(TEST_DICT, args))

# Test dslice when a list is passed
Expand All @@ -43,40 +47,66 @@ def test_dslice_list_args(self):
'port',
'host',
'foo'
]
]
expected = {
'username':'admin',
'password':'changeme',
'port':8089,
'host':'localhost'
}
'username': 'admin',
'password': 'changeme',
'port': 8089,
'host': 'localhost'
}
self.assertTrue(expected == dslice(TEST_DICT, test_list))

# Test dslice when a single string is passed
def test_dslice_arg(self):
test_arg = 'username'
expected = {
'username':'admin'
}
'username': 'admin'
}
self.assertTrue(expected == dslice(TEST_DICT, test_arg))

# Test dslice using all three types of arguments
def test_dslice_all_args(self):
test_args = [
{'username':'new_username'},
{'username': 'new_username'},
['password',
'host'],
'host'],
'port'
]
expected = {
'new_username':'admin',
'password':'changeme',
'host':'localhost',
'port':8089
'new_username': 'admin',
'password': 'changeme',
'host': 'localhost',
'port': 8089
}
self.assertTrue(expected == dslice(TEST_DICT, *test_args))


class FilePermissionTest(unittest.TestCase):

def setUp(self):
super(FilePermissionTest, self).setUp()

# Check for any change in the default file permission(i.e 644) for all files within splunklib
def test_filePermissions(self):

def checkFilePermissions(dir_path):
for file in os.listdir(dir_path):
if file.__contains__('pycache'):
continue
path = os.path.join(dir_path, file)
if os.path.isfile(path):
permission = oct(os.stat(path).st_mode)
if sys.version_info >= (3, 0):
self.assertEqual(permission, '0o100644')
else :
self.assertEqual(permission, '0100644')
else:
checkFilePermissions(path)

dir_path = os.path.join('..', 'splunklib')
checkFilePermissions(dir_path)


if __name__ == "__main__":
try:
import unittest2 as unittest
Expand Down