Steps required to reproduce the bug
1. Create a new view from users entities.
2. Add field "The password of this user (hashed)"
What behavior were you expecting?
I'd expect to see hashed password of user. Same information as in users_field_data table in pass column.
Motivation
I'm migrating users from various Drupal 8 sites to a single Drupal 8 site. I've found Views to be easiest way to generate the source data in desired format.
Proposed resolution
Remove the pass field from views. Add test coverage for this issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #32 | 3082006-9.0.x.patch | 2.06 KB | alexpott |
| #32 | 24-32-interdiff.txt | 655 bytes | alexpott |
| #24 | user-view-pass-field-is-empty-3082006-24-D8.patch | 2.05 KB | cambraca |
Comments
Comment #2
id.aleks commentedComment #3
id.aleks commentedI think that is better to remove this field from views, because of:
Please review and test. Thanks.
Comment #4
sokru commentedComment #5
larowlanThanks, as this is a bug report, we need a new test to assert the behaviour (i.e. that this field is not available to views).
We can use \Drupal\Tests\user\Kernel\Views\UserKernelTestBase as a base class and the test would be something like so:
Thanks!
Comment #6
id.aleks commented@larowlan Thanks for your advice. I agree with you.
I have updated the patch. Please test and review. Thanks.
Comment #7
id.aleks commentedUpdated patch, because the previous one failed to apply.
Comment #8
sokru commentedAs tests are passing & I did manual testing, setting back to RTBC.
Comment #9
alexpottThis is a nice bug fix in terms of views - I don't think providing a view that displays password hashes is a great use case for views. We need the issue summary to updated with the solution we've chosen - ie. to remove the field from views.
This test is about \Drupal\user\Plugin\views\field\Permissions which is not the as UserViewsData.
Perhaps this belongs in its own test. Also this test is only asserting for the absence of something which makes the test likely to produce false positives. I think we need at least a positive assertion that the user entity has a field called 'pass' and then the corresponding assert that this field is not in views data.
Let's not add a service as a class property to a TestBase class for a single testAssertion.
Comment #10
id.aleks commented@alexpott Thanks for your full review.
1. About issue summary - ok, I will update it after updating the patch.
2,3 It's clear, I agree with you.
I'm going to update the patch shortly.
Comment #11
id.aleks commentedComment #12
id.aleks commentedI updated the patch and issue summary according to the @alexpott feedback. Please test and review.
Comment #14
id.aleks commentedUpdated patch, because the previous one failed to apply.
Comment #16
mr.baileysAssertions in PHPUnit do not have return values. They either pass, or they throw an exception and abort the test in which the failed assertion was executed. In this case, the second assertion is not evaluated. You can verify this by running the test, which will output "OK (1 test, 1 assertion)" (note that it only counts one assertion instead of 2). Since you expect both assertions to pass, just execute them sequentually and remove the if-statement.
However, if I do that, the second assertions fails with:
So the test still needs some tweaking.
Comment #17
cambraca commentedWorking on this from DrupalCon Amsterdam!
I've taken a look at this, and apparently the
action_entity_type_build()function from theactionmodule is being called fromviews.views.inc:views_views_data(), and fails because theactionmodule isn't enabled in the test.I updated the main test as per #16, and tried just adding the module to the
UserViewsDataTest::$modulesarray, without much luck (got an error from inside theaction_entity_type_build()function), but this change inviews.views.incseems to work and hopefully even makes sense.Also, I'm not sure if this thing should be split into its own issue on the "views" project.
Comment #18
mr.baileysThanks for working on this @cambraca!
The action entity type is not provided by the action module (which is why adding it to
UserViewsDataTest::$modulesdid not fix your issue), but rather by the system module. Views has drupal:system as an indirect dependency, however in a KernelTest you have to explicitly specify the dependencies you need. Try adding'system'toUserViewsDataTest::$modulesinstead of altering views, this should get rid of the test failure.Comment #19
mr.baileysAdding tags
Comment #20
cambraca commentedThanks for the guidance! You're absolutely right. In my defense, it is a bit confusing ("action" module vs. entity type).
Here's a new patch, much closer to the one from #14. The test now runs fine on my local.
Comment #21
cambraca commentedWould it make sense for the "views" module to have "system" as a dependency?
Comment #22
mr.baileysTechnically, this already is the case: views has a dependency on drupal:filter, drupal:filter has a dependency on drupal:user, drupal:user has a dependency on drupal:system. So you cannot enable views on a site without also installing the filter+user+system. KernelTestBase ignores a module's dependencies during test though, which is why you have to explictly specify it.
Needs review for the patch in #20.
Comment #23
mr.baileysComments should be complete sentences, so "Unset the pass field, because the access control handler ...". I would also put quotes around "pass". If you alter the comment, make sure you don't exceed the 80 chars per line limit. See https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... for more information on coding standards.
Comment #24
cambraca commentedI learned yet another thing today!
Here's a new patch with the changes to the comment.
Comment #25
mr.baileysThere is the question of the upgrade path in #9. Prior to this patch, adding the pass field to a view does not do anything, no information is shown and no indication is given that the field does not work. After this patch, the field handler is replaced by the "broken/missing handler". I think this is the right approach.
Since we are removing a Views field, I think it's best to have a change record explaining why it was removed.
Comment #26
sokru commentedAdded the change record.
Comment #27
longwaveAgree that no upgrade path is needed nor useful, it is better to show broken/missing handler - it was broken before anyway.
Comment #29
alexpottCommitted 999dbef and pushed to 9.1.x. Thanks!
Going to ask release managers about backporting to 8.9.x and 9.0.x
Comment #32
alexpottI had to hot fix the test for the void return so here's a patch for 9.0.x... #24 is good for 8.9.x.
Comment #33
xjmI'm going to go ahead and set this issue back to fixed against 9.1.x since 9.0.x is nearing the end of its active support; it does change the error behavior and could have side effects for contrib we didn't think of.