Page MenuHomePhabricator

Add DB Updater to update scratch token string to arrays
Closed, ResolvedPublic

Description

I note that nothing specifically seems to migrate scratch tokens from a string to an array

As noted in https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/OATHAuth/+/538154/

https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/OATHAuth/+/538154/11/src/Key/TOTPKey.php@97

Hence the need for some of the defensive code

Event Timeline

Change 548481 had a related patch set uploaded (by Reedy; owner: Reedy):
[mediawiki/extensions/OATHAuth@master] Update TOTP Scrach Tokens to array

https://gerrit.wikimedia.org/r/548481

Testing:

$res = $db->select( 'oathauth_users', [ 'id', 'data' ], [ 'module' => 'totp' ] );

foreach ( $res as $row ) { $data = FormatJson::decode( $row->data, true ); var_dump( $data ); foreach ( $data['keys'] as &$k ) { if ( is_string( $k['scratch_tokens'] ) ) { $k['scratch_tokens'] = explode( ',', $k['scratch_tokens'] ); } } var_dump( $data ); }

/var/www/wiki/mediawiki/core/maintenance/eval.php(78) : eval()'d code:1:
array(1) {
  'keys' =>
  array(1) {
    [0] =>
    array(2) {
      'secret' =>
      string(16) "4CX6VOMYXQ3NFTCB"
      'scratch_tokens' =>
      string(169) "ZJCXGXLUDZAO64CW,3DT2R4C4ARK6W4UG,VNB5Z57OV5L5PIZP,O4DKBII7GXV2YH6C,TXKBYKDAHFM4U5AL,3WNWUG2RTZUK3HNC,T2QT4DBIZM7OYRGK,TUWJQ4HOWMW3PRLG,THIPW37Z5DR3UVTE,K6P475UCJFKYICZR"
    }
  }
}
/var/www/wiki/mediawiki/core/maintenance/eval.php(78) : eval()'d code:1:
array(1) {
  'keys' =>
  array(1) {
    [0] =>
    array(2) {
      'secret' =>
      string(16) "4CX6VOMYXQ3NFTCB"
      'scratch_tokens' =>
      array(10) {
        ...
      }
    }
  }
}

Change 548481 merged by jenkins-bot:
[mediawiki/extensions/OATHAuth@master] Update TOTP Scratch Tokens to array

https://gerrit.wikimedia.org/r/548481

Reedy claimed this task.