In #2432911: Provide test coverage to prove that a third party authentication provider does not automatically start a session tests were added to check if no cookies are set if a user authenticates using basic authentication. It was discovered that the cookies from a previous test were still present at the start of a new test.
In WebTestBase::curlHeaderCallback()
the $this->cookies
property is filled whenever a cookie is set on the request but these are never cleared to simulate the browser persisting the cookies inbetween requests. We should make sure to clear this before starting a new test.
Beta phase evaluation
Issue category | Bug |
---|---|
Unfrozen changes | Unfrozen because it only changes tests. |
Disruption | Not disruptive |
Comment | File | Size | Author |
---|---|---|---|
#44 | 2491353-44.patch | 3.6 KB | stefan.r |
#44 | interdiff.txt | 493 bytes | stefan.r |
#41 | 2491353-cookie-clearing-d7-41.patch | 3.58 KB | pietmarcus |
#41 | interdiff-2491353-35-41.txt | 1.13 KB | pietmarcus |
#35 | 2491353-cookie-clearing-d7-35.patch | 3.56 KB | pietmarcus |
Comments
Comment #1
pfrenssenHere's a fix + test. Since the
$this->cookies
property seems to be wholly untested I also added a test to see if the name and value of the cookie are correct.Comment #3
znerol CreditAttribution: znerol commentedUse
$this->drupalGetHeader()
unless there is a strong reason against that.The
$cookies
property is not initialized on declaration. In order to maintain consistency (each test should work with the same initial value), I think either the$cookies
property needs to be set toNULL
here or it should to be initialized to an empty array on declaration.Comment #4
pfrenssenarray()
syntax instead of[]
to be consistent with the rest of the file.Comment #5
pfrenssenThis patch contains only the test, this should fail.
Comment #7
pfrenssenComment #8
znerol CreditAttribution: znerol commentedThanks!
Comment #9
alexpottLet's set a static in testCookies() and assert it's value in testCookieDoesNotBleed() so we can be sure we're testing something - or if someone has the bright idea of parallelising all the individual test methods during a run this breaks.
Comment #10
pfrenssenAl right I added a static to track whether
testCookies()
actually runs beforetestCookieDoesNotBleed()
. This will fail to alert someone running the tests in parallel that this behaviour is now untested. Probably we will have long moved to BrowserTestBase before running test methods in parallel becomes a real necessity.I added two failing tests now: one to prove that the test detects the issue, and the other to prove that a failure will occur if
testCookies()
does not run beforetestCookieDoesNotBleed()
.Comment #12
almaudoh CreditAttribution: almaudoh commentedCore maintainers comments addressed and reversed test sequence fails as desired. I would have set this to RTBC, but:
'A cookie has been set in a previous test.' does not exactly tell why the assertion failed. A more explicit message like 'testCookieDoesNotBleed() runs after testCookie()' or so would be more helpful, especially in the case of parallel testing.
Comment #13
znerol CreditAttribution: znerol commentedI'm not quite sure and I cannot find any reliable source, but I feel that
static
is preferable overself
nowadays. search query.Comment #14
znerol CreditAttribution: znerol commentedRe #12 perhaps something like Test methods are run in the expected order?
Comment #15
pfrenssenComment #16
pfrenssenAddressed the remarks.
Comment #18
znerol CreditAttribution: znerol commentedThanks!
Comment #19
alexpottCommitted ca5fced and pushed to 8.0.x. Thanks!
Comment #21
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedI am guessing this needs to be backported, right?
Comment #23
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedI have backported this issue to Drupal 7. Here is a testonly patch, that will fail.
Comment #24
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedHere is the patch itself. Please review.
Comment #25
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedLet me upload the testonly patch again, so it is picked up by the test-server.
Comment #27
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedAs expected, the test-only patch failed. #24 passed, so I'm changing the status to Needs review again.
Comment #29
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer and commentedThis patch applied in my localhost. I qued the test again.
Comment #31
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedThe test only patch failed again. #24, the patch with the fix is the patch up for review.
Comment #32
znerol CreditAttribution: znerol commentedNice, thanks.
Comment #33
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThis won't work on PHP 5.2, which we technically still support. Is there any reason
self::
can't just be used instead?Also, minor, but the @see should actually be a sentence using "See" since it's an inline code comment. I would probably include the class name too, in other words: "See SimpleTestBrowserTestCase::testCookieDoesNotBleed()."
Comment #34
znerol CreditAttribution: znerol commentedOh, do we even have 5.2 test runners on CI?
Comment #35
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedI have changed the patch as suggested in #33. Here are a new patch and the interdiff.
Please review!
Comment #37
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedThe test that failed has nothing to do with the patch, so marking Needs review again.
Comment #38
Anonymous (not verified) CreditAttribution: Anonymous as a volunteer and commentedI qued for test again.
Comment #39
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedLooking better, but:
The @see should not be there. Just the "See". And a period at the end of the sentence.
Since this one is part of the function documentation it should use @see but according to https://www.drupal.org/coding-standards/docs#see. So it should just be "@see SimpleTestBrowserTestCase::testCookies()"
This one will need to use "self::" also.
Comment #40
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedNot currently, but I've heard rumors they could exist in the future :) Bottom line, it's worth keeping the tests compatible with PHP 5.2 (like the rest of Drupal) if we can.
Comment #41
pietmarcus CreditAttribution: pietmarcus as a volunteer commentedFixed the comments made in #39. Please review.
Comment #42
znerol CreditAttribution: znerol commentedLooks good, thanks.
Comment #43
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThis should still say SimpleTestBrowserTestCase::testCookies.
Could be fixed on commit, though.
Comment #44
stefan.r CreditAttribution: stefan.r commented+1, looks great
Comment #45
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedStill RTBC and marked for commit.
Comment #46
stefan.r CreditAttribution: stefan.r commentedComment #48
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedCommitted and pushed to 7.x! Thanks!
Added to CHANGELOG.txt so that module authors know that their tests could have a side effect fixed.