TST: Appropriately mark JournalMatch transmitter test as skipped

pull/491/head
Steven Hiscocks 11 years ago
parent a60fbcc116
commit 43689d6470

@ -526,75 +526,79 @@ class Transmitter(TransmitterBase):
self.assertEqual( self.assertEqual(
self.transm.proceed(["status", "INVALID", "COMMAND"])[0],1) self.transm.proceed(["status", "INVALID", "COMMAND"])[0],1)
if filtersystemd: # pragma: systemd no cover def testJournalMatch(self):
def testJournalMatch(self): if not filtersystemd:
jailName = "TestJail2" if sys.version_info >= (2, 7):
self.server.addJail(jailName, "systemd") raise unittest.SkipTest(
values = [ "systemd python interface not avilable")
"_SYSTEMD_UNIT=sshd.service", return
"TEST_FIELD1=ABC", jailName = "TestJail2"
"_HOSTNAME=example.com", self.server.addJail(jailName, "systemd")
] values = [
for n, value in enumerate(values): "_SYSTEMD_UNIT=sshd.service",
self.assertEqual( "TEST_FIELD1=ABC",
self.transm.proceed( "_HOSTNAME=example.com",
["set", jailName, "addjournalmatch", value]), ]
(0, [[val] for val in values[:n+1]])) for n, value in enumerate(values):
for n, value in enumerate(values):
self.assertEqual(
self.transm.proceed(
["set", jailName, "deljournalmatch", value]),
(0, [[val] for val in values[n+1:]]))
# Try duplicates
value = "_COMM=sshd"
self.assertEqual(
self.transm.proceed(
["set", jailName, "addjournalmatch", value]),
(0, [[value]]))
# Duplicates are accepted, as automatically OR'd, and journalctl
# also accepts them without issue.
self.assertEqual( self.assertEqual(
self.transm.proceed( self.transm.proceed(
["set", jailName, "addjournalmatch", value]), ["set", jailName, "addjournalmatch", value]),
(0, [[value], [value]])) (0, [[val] for val in values[:n+1]]))
# Remove first instance for n, value in enumerate(values):
self.assertEqual(
self.transm.proceed(
["set", jailName, "deljournalmatch", value]),
(0, [[value]]))
# Remove second instance
self.assertEqual( self.assertEqual(
self.transm.proceed( self.transm.proceed(
["set", jailName, "deljournalmatch", value]), ["set", jailName, "deljournalmatch", value]),
(0, [])) (0, [[val] for val in values[n+1:]]))
value = [ # Try duplicates
"_COMM=sshd", "+", "_SYSTEMD_UNIT=sshd.service", "_UID=0"] value = "_COMM=sshd"
self.assertEqual( self.assertEqual(
self.transm.proceed( self.transm.proceed(
["set", jailName, "addjournalmatch"] + value), ["set", jailName, "addjournalmatch", value]),
(0, [["_COMM=sshd"], ["_SYSTEMD_UNIT=sshd.service", "_UID=0"]])) (0, [[value]]))
self.assertEqual( # Duplicates are accepted, as automatically OR'd, and journalctl
self.transm.proceed( # also accepts them without issue.
["set", jailName, "deljournalmatch"] + value[:1]), self.assertEqual(
(0, [["_SYSTEMD_UNIT=sshd.service", "_UID=0"]])) self.transm.proceed(
self.assertEqual( ["set", jailName, "addjournalmatch", value]),
self.transm.proceed( (0, [[value], [value]]))
["set", jailName, "deljournalmatch"] + value[2:]), # Remove first instance
(0, [])) self.assertEqual(
self.transm.proceed(
# Invalid match ["set", jailName, "deljournalmatch", value]),
value = "This isn't valid!" (0, [[value]]))
result = self.transm.proceed( # Remove second instance
["set", jailName, "addjournalmatch", value]) self.assertEqual(
self.assertTrue(isinstance(result[1], ValueError)) self.transm.proceed(
["set", jailName, "deljournalmatch", value]),
# Delete invalid match (0, []))
value = "FIELD=NotPresent"
result = self.transm.proceed( value = [
["set", jailName, "deljournalmatch", value]) "_COMM=sshd", "+", "_SYSTEMD_UNIT=sshd.service", "_UID=0"]
self.assertTrue(isinstance(result[1], ValueError)) self.assertEqual(
self.transm.proceed(
["set", jailName, "addjournalmatch"] + value),
(0, [["_COMM=sshd"], ["_SYSTEMD_UNIT=sshd.service", "_UID=0"]]))
self.assertEqual(
self.transm.proceed(
["set", jailName, "deljournalmatch"] + value[:1]),
(0, [["_SYSTEMD_UNIT=sshd.service", "_UID=0"]]))
self.assertEqual(
self.transm.proceed(
["set", jailName, "deljournalmatch"] + value[2:]),
(0, []))
# Invalid match
value = "This isn't valid!"
result = self.transm.proceed(
["set", jailName, "addjournalmatch", value])
self.assertTrue(isinstance(result[1], ValueError))
# Delete invalid match
value = "FIELD=NotPresent"
result = self.transm.proceed(
["set", jailName, "deljournalmatch", value])
self.assertTrue(isinstance(result[1], ValueError))
class TransmitterLogging(TransmitterBase): class TransmitterLogging(TransmitterBase):

Loading…
Cancel
Save