Skip to content

Commit 676c29c

Browse files
authored
Merge pull request #24 from iMattPro/bug-asterix
Fix masked private key trick
2 parents 979065d + 887dc2b commit 676c29c

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

acp/wpn_acp_module.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class wpn_acp_module
4444
/** @var array $errors */
4545
protected $errors = [];
4646

47+
/** @var string Hide/replace private key with asterisks */
48+
public const MASKED_PRIVATE_KEY = '********';
49+
4750
/**
4851
* Main ACP module
4952
*
@@ -97,7 +100,7 @@ public function display_settings()
97100
$this->template->assign_vars([
98101
'S_WEBPUSH_ENABLE' => $this->config['wpn_webpush_enable'],
99102
'WEBPUSH_VAPID_PUBLIC' => $this->config['wpn_webpush_vapid_public'],
100-
'WEBPUSH_VAPID_PRIVATE' => !$this->config['wpn_webpush_vapid_private'] ?: '********', // Replace private key with asterixes
103+
'WEBPUSH_VAPID_PRIVATE' => $this->config['wpn_webpush_vapid_private'] ? self::MASKED_PRIVATE_KEY : '',
101104
'U_ACTION' => $this->u_action,
102105
]);
103106
}
@@ -117,7 +120,7 @@ public function save_settings()
117120
];
118121

119122
// Do not validate and update private key field if the content is ******** and the key was already set
120-
if ($config_array['wpn_webpush_vapid_private'] == '********' && $this->config['wpn_webpush_vapid_private'])
123+
if ($config_array['wpn_webpush_vapid_private'] === self::MASKED_PRIVATE_KEY && $this->config['wpn_webpush_vapid_private'])
121124
{
122125
unset($display_settings['wpn_webpush_vapid_private'], $config_array['wpn_webpush_vapid_private']);
123126
}

tests/functional/functional_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function test_acp_module()
5757

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

0 commit comments

Comments
 (0)