Skip to content

Commit

Permalink
[REFACTOR] Ensure user_pass not included in export.
Browse files Browse the repository at this point in the history
Although user_pass would have been hashed, it still made little to no
sense including it in the export.

A common use case is to export from one environment to impose on to
another and if not careful this would include the hashed password as the
users password and thus set as the password (it would get re-hashed of
course). Storing passwords in text files is generally frowned upon, so
make sure we don't incldue it in the export.
  • Loading branch information
Ian Jenkins committed Apr 8, 2021
1 parent 8b45810 commit 0ff11dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
20 changes: 20 additions & 0 deletions features/users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ Feature: Site / Network Users Region
| Admin One | adminone@example.com | administrator |
| Editor One | editorone@example.com | editor |

When I run `wp dictator export site export.yml`
Then STDOUT should contain:
"""
Success: State written to file.
"""
And the export.yml file should not contain:
"""
user_pass:
"""

Scenario: Impose Network Users
Given a WP multisite install
And a network-users.yml file:
Expand All @@ -50,3 +60,13 @@ Feature: Site / Network Users Region
| display_name | user_email |
| Admin One | adminone@example.com |
| Editor One | editorone@example.com |

When I run `wp dictator export network export.yml`
Then STDOUT should contain:
"""
Success: State written to file.
"""
And the export.yml file should not contain:
"""
user_pass:
"""
7 changes: 1 addition & 6 deletions php/regions/class-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ abstract class Users extends Region {
'_required' => false,
'_get_callback' => 'get_user_value',
),
'user_pass' => array(
'_type' => 'text',
'_required' => false,
'_get_callback' => 'get_user_value',
),
'role' => array(
'_type' => 'text',
'_required' => false,
Expand Down Expand Up @@ -149,7 +144,7 @@ public function impose( $key, $value ) {
$user_obj = array(
'user_login' => $key,
'user_email' => $value['email'], // 'email' is required.
'user_pass' => isset( $value['user_pass'] ) ? $value['user_pass'] : wp_generate_password( 24 ), // if no password supplied, generate random password.
'user_pass' => wp_generate_password( 24 ),
);
$user_id = wp_insert_user( $user_obj );
if ( is_wp_error( $user_id ) ) {
Expand Down

0 comments on commit 0ff11dc

Please sign in to comment.