Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed Apr 27, 2021
1 parent f2d7aa7 commit 053e651
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
Expand Up @@ -45,6 +45,11 @@
<VALUE>openssh-server</VALUE>
</REPORTKEYS>
</SECTION>
<SECTION component="true" multivalued="true" name="Test https://issues.rudder.io/issues/19173">
<REPORTKEYS>
<VALUE>sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info-&gt;{\x27issuer_o\x27} !~ /Let\x27s\s\\\s+Encrypt/i);#g'</VALUE>
</REPORTKEYS>
</SECTION>
<SECTION name="Technique parameters">
<INPUT>
<NAME>1AAACD71-C2D5-482C-BCFF-5EEE6F8DA9C2</NAME>
Expand Down
Expand Up @@ -19,4 +19,8 @@ bundle agent technique_by_Rudder_rudder_reporting(technique_parameter)
unless => concat("redhat");
"dummy_report_3" usebundle => log_na_rudder("Skipping method 'Package install' with key parameter 'openssh-server' since condition 'redhat' is not reached", "openssh-server", "${class_prefix}_package_install_openssh-server", @{args}),
unless => concat("redhat");
"dummy_report_5" usebundle => _method_reporting_context("Test https://issues.rudder.io/issues/19173", "sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\\x27issuer_o\\x27} !~ /Let\\x27s\\s\\\s+Encrypt/i);#g'"),
unless => concat("redhat");
"dummy_report_5" usebundle => log_na_rudder("Skipping method 'Command execution' with key parameter 'sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\\x27issuer_o\\x27} !~ /Let\\x27s\\s\\\s+Encrypt/i);#g'' since condition 'redhat' is not reached", "sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\\x27issuer_o\\x27} !~ /Let\\x27s\\s\\\s+Encrypt/i);#g'", "${class_prefix}_command_execution_sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\\x27issuer_o\\x27} !~ /Let\\x27s\\s\\\s+Encrypt/i);#g'", @{args}),
unless => concat("redhat");
}
Expand Up @@ -29,8 +29,12 @@ bundle agent technique_by_Rudder(technique_parameter)
if => concat("cfengine-community");
"Command execution_${report_data.directive_id}_4" usebundle => command_execution("/bin/echo \"testing special characters ` è &é 'à é \"\\"),
if => concat("cfengine-community");
"Not sure we should test it ..._${report_data.directive_id}_5" usebundle => _method_reporting_context("Not sure we should test it ...", "NA"),
"Test https://issues.rudder.io/issues/19173_${report_data.directive_id}_5" usebundle => _method_reporting_context("Test https://issues.rudder.io/issues/19173", "sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\\x27issuer_o\\x27} !~ /Let\\x27s\\s\\\s+Encrypt/i);#g'"),
if => concat("redhat");
"Test https://issues.rudder.io/issues/19173_${report_data.directive_id}_5" usebundle => command_execution("sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\\x27issuer_o\\x27} !~ /Let\\x27s\\s\\\s+Encrypt/i);#g'"),
if => concat("redhat");
"Not sure we should test it ..._${report_data.directive_id}_6" usebundle => _method_reporting_context("Not sure we should test it ...", "NA"),
if => concat("any");
"Not sure we should test it ..._${report_data.directive_id}_5" usebundle => _logger("NA", "NA"),
"Not sure we should test it ..._${report_data.directive_id}_6" usebundle => _logger("NA", "NA"),
if => concat("any");
}
Expand Up @@ -38,4 +38,11 @@
_rudder_common_report_na -componentName "Command execution" -componentKey "/bin/echo `"testing special characters ` è &é 'à é `"\" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
}

$class = "redhat"
if (Evaluate-Class $class $local_classes $system_classes) {
$local_classes = Merge-ClassContext $local_classes $(Command-Execution -Command "sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\x27issuer_o\x27} !~ /Let\x27s\s\\\s+Encrypt/i);#g'" -componentName "Test https://issues.rudder.io/issues/19173" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")
} else {
_rudder_common_report_na -componentName "Test https://issues.rudder.io/issues/19173" -componentKey "sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\x27issuer_o\x27} !~ /Let\x27s\s\\\s+Encrypt/i);#g'" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
}

}
Expand Up @@ -102,7 +102,7 @@ import org.specs2.specification.BeforeAfterAll
@RunWith(classOf[JUnitRunner])
class TestTechniqueWriter extends Specification with ContentMatchers with Loggable with BeforeAfterAll {
sequential
lazy val basePath = "/tmp/test-technique-writer-" + DateTime.now.toString()
lazy val basePath = "/tmp/rudder-test-technique-writer-" + DateTime.now.toString()

override def beforeAll(): Unit = {
new File(basePath).mkdirs()
Expand All @@ -127,37 +127,21 @@ class TestTechniqueWriter extends Specification with ContentMatchers with Loggab

// Not used in test for now
def readDirectives : RoDirectiveRepository = new RoDirectiveRepository {

def getFullDirectiveLibrary(): IOResult[FullActiveTechniqueCategory] = ???

def getDirective(directiveId: DirectiveId): IOResult[Option[Directive]] = ???

def getDirectiveWithContext(directiveId: DirectiveId): IOResult[Option[(domain.Technique, ActiveTechnique, Directive)]] = ???

def getActiveTechniqueAndDirective(id: DirectiveId): IOResult[Option[(ActiveTechnique, Directive)]] = ???

def getDirectives(activeTechniqueId: ActiveTechniqueId, includeSystem: Boolean): IOResult[Seq[Directive]] = ???

def getActiveTechniqueByCategory(includeSystem: Boolean): IOResult[SortedMap[List[ActiveTechniqueCategoryId], CategoryWithActiveTechniques]] = ???

def getActiveTechniqueByActiveTechnique(id: ActiveTechniqueId): IOResult[Option[ActiveTechnique]] = ???

def getActiveTechnique(techniqueName: TechniqueName): IOResult[Option[ActiveTechnique]] = ???

def activeTechniqueBreadCrump(id: ActiveTechniqueId): IOResult[List[ActiveTechniqueCategory]] = ???

def getActiveTechniqueLibrary: IOResult[ActiveTechniqueCategory] = ???

def getAllActiveTechniqueCategories(includeSystem: Boolean): IOResult[Seq[ActiveTechniqueCategory]] = ???

def getActiveTechniqueCategory(id: ActiveTechniqueCategoryId): IOResult[Option[ActiveTechniqueCategory]] = ???

def getParentActiveTechniqueCategory(id: ActiveTechniqueCategoryId): IOResult[ActiveTechniqueCategory] = ???

def getParentsForActiveTechniqueCategory(id: ActiveTechniqueCategoryId): IOResult[List[ActiveTechniqueCategory]] = ???

def getParentsForActiveTechnique(id: ActiveTechniqueId): IOResult[ActiveTechniqueCategory] = ???

def containsDirective(id: ActiveTechniqueCategoryId): UIO[Boolean] = ???
}

Expand All @@ -179,25 +163,15 @@ class TestTechniqueWriter extends Specification with ContentMatchers with Loggab

def workflowLevelService: WorkflowLevelService = new WorkflowLevelService {
def workflowLevelAllowsEnable: Boolean = ???

def workflowEnabled: Boolean = ???

def name: String = ???

def getWorkflowService(): WorkflowService = ???

def getForRule(actor: EventActor, change: RuleChangeRequest): Box[WorkflowService] = ???

def getForDirective(actor: EventActor, change: DirectiveChangeRequest): Box[WorkflowService] = ???

def getForNodeGroup(actor: EventActor, change: NodeGroupChangeRequest): Box[WorkflowService] = ???

def getForGlobalParam(actor: EventActor, change: GlobalParamChangeRequest): Box[WorkflowService] = ???

def getByDirective(id: DirectiveId, onlyPending: Boolean): Box[Vector[ChangeRequest]] = ???

def getByNodeGroup(id: NodeGroupId, onlyPending: Boolean): Box[Vector[ChangeRequest]] = ???

def getByRule(id: RuleId, onlyPending: Boolean): Box[Vector[ChangeRequest]] = ???
}

Expand Down Expand Up @@ -341,6 +315,17 @@ class TestTechniqueWriter extends Specification with ContentMatchers with Loggab
, "cfengine-community"
, "Command execution"
) ::
MethodCall(
/*
* Test escape of \, see: https://issues.rudder.io/issues/19173
* We don't do it correctly (we don't consistently escape '\' when there is 2 or more, but we can't change it.
* The problem is the consistancy between what we have in expected reports and in `rudder_reporting.cf`
*/
BundleName("command_execution")
, List((ParameterId("command"),"""sed -i 's#next if .*issuer_cn.*Let.*Encrypt.*#next if ($info->{\x27issuer_o\x27} !~ /Let\x27s\s\\\s+Encrypt/i);#g'"""))
, "redhat"
, "Test #19173"
) ::
MethodCall(
BundleName("_logger")
, List((ParameterId("message"),"NA"),(ParameterId("old_class_prefix"),"NA"))
Expand Down
Expand Up @@ -48,7 +48,6 @@ import com.normation.rudder.domain.reports.ComplianceLevel
import com.normation.rudder.domain.reports.NodeConfigId
import com.normation.rudder.domain.reports.NodeExpectedReports
import com.normation.rudder.domain.reports.NodeStatusReport
import com.normation.rudder.domain.reports.RuleStatusReport
import com.normation.rudder.domain.reports.RunComplianceInfo
import com.normation.rudder.reports.GlobalComplianceMode
import com.normation.rudder.reports.execution.RoReportsExecutionRepository
Expand Down

0 comments on commit 053e651

Please sign in to comment.