Skip to content

Commit

Permalink
DQA-9217: Align SANITIZE_OPTS on .opts.yml (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva committed Apr 29, 2024
1 parent 5c42d0e commit 86a42d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/TaskRunner/Commands/DrupalSanitiseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ public static function areUserFieldsSanitised(): bool
return true;
}
// By default, the fields are sanitised, skip if not options are defined.
if (empty($opts['dump_options'][0]['SANITIZE_OPTS'])) {
if (empty($opts['dump_options']['SANITIZE_OPTS'])) {
return true;
}
$value = $opts['dump_options'][0]['SANITIZE_OPTS'];
$value = $opts['dump_options']['SANITIZE_OPTS'];
if (preg_match(self::optionPattern('sanitize-password'), $value)) {
return false;
}
Expand Down
20 changes: 11 additions & 9 deletions src/TaskRunner/Commands/ToolCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,20 @@ public function optsReview(ConsoleIO $io, array $options = [

// Check for wrong syntax used for SANITIZE_OPTS.
if (!empty($parseOptsFile['dump_options'])) {
foreach ($parseOptsFile['dump_options'] as $dumpOption) {
if (is_string($dumpOption) && str_contains($dumpOption, 'SANITIZE_OPTS=')) {
$io->say('Invalid syntax detected in dump_options section for the SANITIZE_OPTS. Use:');
$io->writeln(['dump_options:', ' - SANITIZE_OPTS: "--option=no"']);
if (!empty($parseOptsFile['dump_options']['SANITIZE_OPTS'])) {
if (!DrupalSanitiseCommands::areUserFieldsSanitised()) {
$io->error('Detected forbidden usage of --sanitize-email=no and/or --sanitize-password=no');
$reviewOk = false;
} elseif (is_array($dumpOption) && !empty($dumpOption['SANITIZE_OPTS'])) {
if (!DrupalSanitiseCommands::areUserFieldsSanitised()) {
$io->error('Detected forbidden usage of --sanitize-email=no and/or --sanitize-password=no');
$reviewOk = false;
}
}
}
if (!empty($parseOptsFile['dump_options'][0])) {
$io->error([
'Invalid syntax detected in dump_options section for the SANITIZE_OPTS. Use:',
'dump_options:',
' SANITIZE_OPTS: "[email protected]"',
]);
$reviewOk = false;
}
}

if (empty($parseOptsFile['upgrade_commands'])) {
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/commands/drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "[email protected]"
SANITIZE_OPTS: "[email protected]"
expectations:
- string_contains: node-field_test_token (string)
- not_string_contains: user-email (email)
Expand All @@ -399,7 +399,7 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "--sanitize-email=no"
SANITIZE_OPTS: "--sanitize-email=no"
expectations:
- string_contains: node-field_test_token (string)
- string_contains: user-email (email)
Expand All @@ -412,7 +412,7 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "--sanitize-password=no"
SANITIZE_OPTS: "--sanitize-password=no"
expectations:
- string_contains: node-field_test_token (string)
- string_contains: user-email (email)
Expand Down
30 changes: 25 additions & 5 deletions tests/fixtures/commands/opts-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "[email protected] --sanitize-password=123"
SANITIZE_OPTS: "[email protected] --sanitize-password=123"
expectations:
- string_contains: The project is using default deploy instructions.

Expand All @@ -103,7 +103,27 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "--sanitize-password=no --sanitize-email=no"
- SANITIZE_OPTS: "[email protected]"
expectations:
- string_contains: Invalid syntax detected in dump_options section for the SANITIZE_OPTS.

- command: 'toolkit:opts-review'
configuration: []
resources:
- file: .opts.yml
content: |
dump_options:
SANITIZE_OPTS= "[email protected]"
expectations:
- string_contains: Invalid syntax detected in dump_options section for the SANITIZE_OPTS.

- command: 'toolkit:opts-review'
configuration: []
resources:
- file: .opts.yml
content: |
dump_options:
SANITIZE_OPTS: "--sanitize-password=no --sanitize-email=no"
expectations:
- string_contains: "[ERROR] Detected forbidden usage of --sanitize-email=no and"

Expand All @@ -113,7 +133,7 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "--sanitize-password no --sanitize-email no"
SANITIZE_OPTS: "--sanitize-password no --sanitize-email no"
expectations:
- string_contains: "[ERROR] Detected forbidden usage of --sanitize-email=no and"

Expand All @@ -123,7 +143,7 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: "--sanitize-password='no' --sanitize-email='no'"
SANITIZE_OPTS: "--sanitize-password='no' --sanitize-email='no'"
expectations:
- string_contains: "[ERROR] Detected forbidden usage of --sanitize-email=no and"

Expand All @@ -133,6 +153,6 @@
- file: .opts.yml
content: |
dump_options:
- SANITIZE_OPTS: '--sanitize-password="no" --sanitize-email="no"'
SANITIZE_OPTS: '--sanitize-password="no" --sanitize-email="no"'
expectations:
- string_contains: "[ERROR] Detected forbidden usage of --sanitize-email=no and"

0 comments on commit 86a42d3

Please sign in to comment.