Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
user system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Oct 2010 at 08:36 UTC
Updated:
3 Jan 2014 at 02:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
bfroehle commentedOoops. Forgot --no-prefix last time. Updated patch.
Comment #2
bfroehle commentedAttached is a unit test routine. Won't pass until the patch in #1 is applied.
----
For the curious, the bug comes from commit c407765a4dae4ab103f5a7b13ceaf9237efbe4a2
Author: dries
Date: Thu Apr 30 16:10:10 2009 +0000
- Patch #394594: DBTNG: User module by Berdir: additional conversion to the new database abstraction layer plus clean-up.
----
Beware: this is my first stab at writing a unit test, so it's probably not the prettiest. For example the assertEqual( ... , 0) should probably be assertFalse(...). Etc.
Comment #4
damien tournoud commentedD'oh. This means that this feature is nearly completely broken. Raising to major.
Comment #5
bfroehle commentedThe unit test in #2 passes after application of the patch in #1 on my system. Changing status to needs review.
Comment #6
moshe weitzman commentedPlease combine into one patch so the bot shows a green result. http://drupal.org/patch/create
Core does not use this function, and basically neither should anyone else in D7. How did you find the bug? ... The Distributed Auth system was ripped out. Thanks still for writing tests.
Comment #7
bfroehle commentedCombined patch is attached. Description in the patch follows:
955414: (user_get_authmaps) Fix key value pair ordering.
The comments for user_get_authmaps describe the function as
returning a key-value pair '%module' => '%authname'. This agrees
with functionality in past releases.
In #394594: DBTNG: User module, the key value pair ordering was (inadvertently)
reversed to be '%authname' => '%module'.
Included also is a unit test for user_get_authmaps and
user_set_authmaps which verifies that authmaps can be set and
removed, and their output has the proper key-value pair ordering.
Comment #8
bfroehle commentedmoshe: I discovered the bug while working to update the CAS module to D7. I assume using authmaps is still the preferred way to interface with external authentication systems.
(Changing priority to major since this completely breaks external authentication schemes.)
Comment #9
moshe weitzman commentedThanks. I'd actually recommend maintaining your own map table. These last vestiges of dist auth will be removed in D8. I don't really see much benefit in using this core table.
Comment #10
bfroehle commentedThanks moshe. The OpenID module in core does make use of the core authmap table, but uses it's own SQL code to query it (and hence is unaffected by this bug).
Comment #11
bfroehle commentedA follow up to patch in #7, this time replacing the static strings in the test routine with ones generated by $this->randomName().
Comment #12
metzlerd commentedHi moshe, Dave... cas module maintainer here, In light of #10. Is it still the case that the authmap table will dissapear? We've been modeling a lot of what we do here based on how drupal does openID support. Just trying to plan for the future. A few hundred university sites still use this authentication mechanism, and I'll need to start planning for a data migration path before drupal 8 gets released if that's the case.
Comment #13
moshe weitzman commentedYes, I think that OpenId should gets its own map table as well in D8. There is no longer any benefit to centralization of mappings since login never consults this table. Contrib modules and OpenID need to inject custom validators into the login form and do login check there. Actually, some contrib modules may choose to forego the map table if they know that drupal username will always match external username.
Comment #14
bfroehle commentedI'm posting a summary of the problem in hopes of getting some action on this. The bug and patch are straightforward.
Summary of the bug:
The function user_get_authmaps claims to return "an associative array with module as key and username as value." However the current code returns an associative array with the username as key and module as the value, effectively reversing the the key/value pair.
This key/value reversal problem stems from a mistake in #394594: DBTNG: User module. You can clearly see the bug introduced in the diff
Recommended solution:
The fix is to replace
fetchAllKeyed()withfetchAllKeyed(1,0).The proposed patch in #11 fixes the key/value ordering and provides a unit test to ensure that
user_get_authmapsanduser_set_authmapswork as advertised. I'm uploading a rebased version of this patch since user.module has seen some changes in the last week.Comment #15
bfroehle commentedCarlos8f and I reworked the unit test at this morning's coding session at BAD Camp.
Comment #16
carlos8f commentedWe can remove the setUp() method, I think other than that it is RTBC.
I worked with @bfroehle on this, mainly as an exercise in test writing. It's just a unit test; core doesn't use this so no functional test is possible.
I'm surprised these API functions still exist. user_save() no longer does any authmap stuff. Even in D6, user_get_authmaps() is not used in core. At this point, the authmaps table might as well belong to the OpenID schema (a module I think should not even be in core). But that's neither here nor there :)
Comment #17
carlos8f commentedprotected $admin_userisn't used, either.Comment #18
bfroehle commentedcarlos8f: You're right about removing the
setUp()and$admin_userparts as they are not used.Updated patch attached, which is #15 plus the changes carlos8f suggested in #16 and #17.
Comment #19
bfroehle commentedEdit: Okay that was weird... ended up with a double post some how.
Comment #21
carlos8f commentedSomething messed up. The patch link doesn't even link to anywhere! Try re-uploading the patch.
Comment #22
bfroehle commented#18, re-uploaded. I'm scratching my head about how the file just disappeared, but whatever.
Comment #23
bfroehle commentedAnd changing the status to needs review, to trigger the bot. The file seems to actually exist this time... ;)
Comment #24
bfroehle commentedSince there seems to be minimal interest in fixing this regression, here's a patch which rips out all of the external authentication functions ala moshe in #9... Why ship them in a broken state when you can just remove them instead?
(obviously, I'd prefer to just have #22 committed, but I'm a bit frustrated).
Comment #25
carlos8f commentedFrustration does not merit scope creep. Let's not go from a simple bugfix to a major API change, if possible. #22 is on my list of stuff to review, but there are criticals now that take precedence. Please be patient :)
Comment #27
carlos8f commented#18 looks great, let's RTBC that. Re-uploaded.
Comment #28
webchickI might very well be missing something, but...
Couldn't we just flip the order of "authname, module" in the SELECT clause so we don't need to use that weird 1,0 pattern?
If not, then I'd prefer to see a comment here explaining why we do this, because it looks odd, and there's information in the commit message explaining it that's not captured here.
Comment #29
chx commentedWe could.
Comment #30
webchickOk, cool. Thanks.
Technically, at this point, we should be fixing documentation rather than changing the API. However, I think it's clear that this was an accidental oversight during DBTNG conversion, and there are only a handful of possible modules affected by this. It looks like not even OpenID is affected by this, which seems a bit odd? Hm.
Anyway, Committed to HEAD.
Note to Randy: This changes the format of the array coming back from user_get_authmaps() so that it's "An associative array with module as key and username as value." like the documentation says. Previous, it was an array with username as key and module as value, due to a bug introduced during DBTNG conversion. Affects only modules implementing external authentication systems. Not sure it's worth an announcement, I'd defer to bfroehle on this point.
Comment #31
rfayThanks for the note about the API change.
I'm getting a bit overwhelmed by these, but I'll try to get a compendium of them together. Wow, are they coming "willy nilly" :-)
Comment #32
webchickWell. It's the last chance to fix bugs that require them, so they'll probably continue coming in for another week. They are not "willy-nilly," though. I've moved most of these to D8 except in cases where they cause regressions or can't be solved another way.
Comment #33
bfroehle commented@rfay: I don't think this needs to be announced, as it is rarely used and a regression from D6 in the DBTNG conversion. Also, any module developer is likely to just mimic openid's implementation which never even calls the function.