@@ -643,7 +643,7 @@ TEST_F(SystemdConfigTest, BlockParameterFoundInCorrectBlock)
643643 params.parameter = " Restart" ;
644644 params.valueRegex = regex (" ^always$" );
645645 params.file = " test.conf" ;
646- params.block = std::string (" [ Service] " );
646+ params.block = std::string (" Service" );
647647
648648 auto result = AuditSystemdParameter (params, mIndicators , mContext );
649649 ASSERT_TRUE (result.HasValue ());
@@ -666,7 +666,7 @@ TEST_F(SystemdConfigTest, BlockParameterNotFoundInWrongBlock)
666666 params.parameter = " Restart" ;
667667 params.valueRegex = regex (" ^always$" );
668668 params.file = " test.conf" ;
669- params.block = std::string (" [ Unit] " );
669+ params.block = std::string (" Unit" );
670670
671671 auto result = AuditSystemdParameter (params, mIndicators , mContext );
672672 ASSERT_TRUE (result.HasValue ());
@@ -686,7 +686,7 @@ TEST_F(SystemdConfigTest, BlockParameterNotFoundInNonexistentBlock)
686686 params.parameter = " ExecStart" ;
687687 params.valueRegex = regex (" .*" );
688688 params.file = " test.conf" ;
689- params.block = std::string (" [ Install] " );
689+ params.block = std::string (" Install" );
690690
691691 auto result = AuditSystemdParameter (params, mIndicators , mContext );
692692 ASSERT_TRUE (result.HasValue ());
@@ -709,7 +709,7 @@ TEST_F(SystemdConfigTest, SameParameterInDifferentBlocksWithBlockFilter)
709709 params.op = SystemdParameterOperator::Equal;
710710 params.value = std::string (" stream" );
711711 params.file = " test.conf" ;
712- params.block = std::string (" [ Socket] " );
712+ params.block = std::string (" Socket" );
713713
714714 auto result = AuditSystemdParameter (params, mIndicators , mContext );
715715 ASSERT_TRUE (result.HasValue ());
@@ -755,7 +755,7 @@ TEST_F(SystemdConfigTest, BlockWithOperatorComparison)
755755 params.op = SystemdParameterOperator::GreaterOrEqual;
756756 params.value = std::string (" 1024" );
757757 params.file = " test.conf" ;
758- params.block = std::string (" [ Service] " );
758+ params.block = std::string (" Service" );
759759
760760 auto result = AuditSystemdParameter (params, mIndicators , mContext );
761761 ASSERT_TRUE (result.HasValue ());
@@ -783,3 +783,83 @@ TEST_F(SystemdConfigTest, ParameterWithoutBlockHeaderFoundWithoutBlockFilter)
783783 ASSERT_TRUE (result.HasValue ());
784784 ASSERT_EQ (result.Value (), Status::Compliant);
785785}
786+
787+ TEST_F (SystemdConfigTest, JournalCompressUsesPassOnNotFoundWhenOutputHasNoJournalSection)
788+ {
789+ std::string systemdOutput = " # /etc/systemd/journald.conf\n " ;
790+
791+ EXPECT_CALL (mContext , ExecuteCommand (::testing::HasSubstr (" /usr/bin/systemd-analyze cat-config journald.conf" ))).WillOnce (Return (Result<std::string>(systemdOutput)));
792+
793+ SystemdParameterParams params;
794+ params.parameter = " Compress" ;
795+ params.valueRegex = regex (" ^yes$" );
796+ params.file = " journald.conf" ;
797+ params.block = std::string (" Journal" );
798+ params.passOnNotFound = true ;
799+
800+ auto result = AuditSystemdParameter (params, mIndicators , mContext );
801+ ASSERT_TRUE (result.HasValue ());
802+ ASSERT_EQ (result.Value (), Status::Compliant);
803+ }
804+
805+ TEST_F (SystemdConfigTest, JournalCompressUsesPassOnNotFoundWhenJournalSectionHasNoCompressLine)
806+ {
807+ std::string systemdOutput =
808+ " # /etc/systemd/journald.conf\n "
809+ " [Journal]\n "
810+ " Storage=auto\n " ;
811+
812+ EXPECT_CALL (mContext , ExecuteCommand (::testing::HasSubstr (" /usr/bin/systemd-analyze cat-config journald.conf" ))).WillOnce (Return (Result<std::string>(systemdOutput)));
813+
814+ SystemdParameterParams params;
815+ params.parameter = " Compress" ;
816+ params.valueRegex = regex (" ^yes$" );
817+ params.file = " journald.conf" ;
818+ params.block = std::string (" Journal" );
819+ params.passOnNotFound = true ;
820+
821+ auto result = AuditSystemdParameter (params, mIndicators , mContext );
822+ ASSERT_TRUE (result.HasValue ());
823+ ASSERT_EQ (result.Value (), Status::Compliant);
824+ }
825+
826+ TEST_F (SystemdConfigTest, JournalCompressWinsOverPassOnNotFound)
827+ {
828+ std::string systemdOutput =
829+ " # /etc/systemd/journald.conf\n "
830+ " [Journal]\n "
831+ " Compress=no\n " ;
832+
833+ EXPECT_CALL (mContext , ExecuteCommand (::testing::HasSubstr (" /usr/bin/systemd-analyze cat-config journald.conf" ))).WillOnce (Return (Result<std::string>(systemdOutput)));
834+
835+ SystemdParameterParams params;
836+ params.parameter = " Compress" ;
837+ params.valueRegex = regex (" ^yes$" );
838+ params.file = " journald.conf" ;
839+ params.block = std::string (" Journal" );
840+ params.passOnNotFound = true ;
841+
842+ auto result = AuditSystemdParameter (params, mIndicators , mContext );
843+ ASSERT_TRUE (result.HasValue ());
844+ ASSERT_EQ (result.Value (), Status::NonCompliant);
845+ }
846+
847+ TEST_F (SystemdConfigTest, FileParameterNotFoundButPassOnNotFound)
848+ {
849+ std::string systemdOutput =
850+ " # /etc/systemd/test.conf\n "
851+ " OtherParam=value1\n "
852+ " AnotherParam=value2\n " ;
853+
854+ EXPECT_CALL (mContext , ExecuteCommand (::testing::HasSubstr (" /usr/bin/systemd-analyze cat-config test.conf" ))).WillOnce (Return (Result<std::string>(systemdOutput)));
855+
856+ SystemdParameterParams params;
857+ params.parameter = " TestParam" ;
858+ params.valueRegex = regex (" .*" );
859+ params.file = " test.conf" ;
860+ params.passOnNotFound = true ;
861+
862+ auto result = AuditSystemdParameter (params, mIndicators , mContext );
863+ ASSERT_TRUE (result.HasValue ());
864+ ASSERT_EQ (result.Value (), Status::Compliant);
865+ }
0 commit comments