Skip to content

Commit

Permalink
Merge pull request #24 from iMattPro/bug-asterix
Browse files Browse the repository at this point in the history
Fix masked private key trick
  • Loading branch information
iMattPro authored Jan 19, 2024
2 parents 979065d + 887dc2b commit 676c29c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions acp/wpn_acp_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class wpn_acp_module
/** @var array $errors */
protected $errors = [];

/** @var string Hide/replace private key with asterisks */
public const MASKED_PRIVATE_KEY = '********';

/**
* Main ACP module
*
Expand Down Expand Up @@ -97,7 +100,7 @@ public function display_settings()
$this->template->assign_vars([
'S_WEBPUSH_ENABLE' => $this->config['wpn_webpush_enable'],
'WEBPUSH_VAPID_PUBLIC' => $this->config['wpn_webpush_vapid_public'],
'WEBPUSH_VAPID_PRIVATE' => !$this->config['wpn_webpush_vapid_private'] ?: '********', // Replace private key with asterixes
'WEBPUSH_VAPID_PRIVATE' => $this->config['wpn_webpush_vapid_private'] ? self::MASKED_PRIVATE_KEY : '',
'U_ACTION' => $this->u_action,
]);
}
Expand All @@ -117,7 +120,7 @@ public function save_settings()
];

// Do not validate and update private key field if the content is ******** and the key was already set
if ($config_array['wpn_webpush_vapid_private'] == '********' && $this->config['wpn_webpush_vapid_private'])
if ($config_array['wpn_webpush_vapid_private'] === self::MASKED_PRIVATE_KEY && $this->config['wpn_webpush_vapid_private'])
{
unset($display_settings['wpn_webpush_vapid_private'], $config_array['wpn_webpush_vapid_private']);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/functional_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function test_acp_module()

foreach ($form_data as $config_name => $config_value)
{
$config_value = ($config_name === 'config[wpn_webpush_vapid_private]') ? '********' : $config_value;
$config_value = ($config_name === 'config[wpn_webpush_vapid_private]') ? \phpbb\webpushnotifications\acp\wpn_acp_module::MASKED_PRIVATE_KEY : $config_value;
$this->assertEquals($config_value, $crawler->filter('input[name="' . $config_name . '"]')->attr('value'));
}
}
Expand Down

0 comments on commit 676c29c

Please sign in to comment.