Project

General

Profile

Actions

Bug #19199

closed

Techniques using a condition containing a variable are not canonified correctly with dsc agent

Added by Félix DALLIDET over 3 years ago. Updated over 3 years ago.

Status:
Released
Priority:
N/A
Category:
Web - Technique editor
Target version:
Severity:
UX impact:
User visibility:
Effort required:
Priority:
0
Name check:
To do
Fix check:
Checked
Regression:

Description

When creating a technique, if you use a condition based on a variable content, it will not canonify its value, leading to malformed conditions.
The logic should already be written since on the CfEngine technique side it is properly canonified.

We currently generate something like:

function Test-Technique {
  [CmdletBinding()]
  param (
      [parameter(Mandatory=$true)]
      [string]$reportId,
      [parameter(Mandatory=$true)]
      [string]$techniqueName,
      [parameter(Mandatory=$true)]
      [string]$File,
      [switch]$auditOnly
  )

  $local_classes = New-ClassContext
  $resources_dir = $PSScriptRoot + "\resources" 

  $local_classes = Merge-ClassContext $local_classes $(File-Content -File "${file}" -Lines "my_content" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")

  $class = "any.(file_lines_present_${file}_repaired)" 
  if (Evaluate-Class $class $local_classes $system_classes) {
    $local_classes = Merge-ClassContext $local_classes $(File-Content -File "C:\result.txt" -Lines "un peu de contenu
sur
plusieurs lignes" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")
  } else {
    _rudder_common_report_na -componentName "File content" -componentKey "C:\result.txt" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
  }

}

And we want something like:

function Test-Technique {
  [CmdletBinding()]
  param (
      [parameter(Mandatory=$true)]
      [string]$reportId,
      [parameter(Mandatory=$true)]
      [string]$techniqueName,
      [parameter(Mandatory=$true)]
      [string]$File,
      [switch]$auditOnly
  )

  $local_classes = New-ClassContext
  $resources_dir = $PSScriptRoot + "\resources" 

  $local_classes = Merge-ClassContext $local_classes $(File-Content -File "${file}" -Lines "my_content" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")

  $class = "any.(file_lines_present_" + $(Canonify-Class $file) + "_repaired)" 
  if (Evaluate-Class $class $local_classes $system_classes) {
    $local_classes = Merge-ClassContext $local_classes $(File-Content -File "C:\result.txt" -Lines "un peu de contenu
sur
plusieurs lignes" -Enforce "true" -componentName "File content" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly).get_item("classes")
  } else {
    _rudder_common_report_na -componentName "File content" -componentKey "C:\result.txt" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
  }

}

The diff is on the lines:

$class = "any.(file_lines_present_${file}_repaired)" 

and

$class = "any.(file_lines_present_" + $(Canonify-Class $file) + "_repaired)" 
Actions #1

Updated by Vincent MEMBRÉ over 3 years ago

  • Project changed from 78 to Rudder
  • Subject changed from Conditions containing a variable are not properly canonified to Conditions containing a variable are not canonfied with dsc agnt
  • Category changed from Generic methods to Web - Technique editor
  • Target version changed from 6.1-1.22 to 6.1.13
Actions #2

Updated by Vincent MEMBRÉ over 3 years ago

  • Status changed from New to In progress
Actions #3

Updated by Vincent MEMBRÉ over 3 years ago

  • Assignee changed from Vincent MEMBRÉ to François ARMAND
  • Pull Request set to https://github.com/Normation/rudder/pull/3608
Actions #4

Updated by Vincent MEMBRÉ over 3 years ago

  • Status changed from In progress to Pending technical review
Actions #5

Updated by Vincent MEMBRÉ over 3 years ago

  • Subject changed from Conditions containing a variable are not canonfied with dsc agnt to Techniques using a condition containing a variable are not canonified correctly with dsc agent
Actions #6

Updated by Vincent MEMBRÉ over 3 years ago

  • Status changed from Pending technical review to Pending release
Actions #7

Updated by Benoît PECCATTE over 3 years ago

  • Fix check changed from To do to Checked
Actions #8

Updated by Vincent MEMBRÉ over 3 years ago

  • Status changed from Pending release to Released

This bug has been fixed in Rudder 6.1.13 and 6.2.7 which were released today.

Actions

Also available in: Atom PDF