-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: backend article preview 'shop' cookie #2737
Open
Dominikrt
wants to merge
1
commit into
shopware5:5.7
Choose a base branch
from
Dominikrt:fix-shop-cookie
base: 5.7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
use Enlight_Controller_Response_ResponseTestCase; | ||
use PHPUnit\Framework\TestCase; | ||
use Shopware\Tests\Functional\Traits\ContainerTrait; | ||
use Symfony\Component\HttpFoundation\Cookie; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class BootstrapTest extends TestCase | ||
|
@@ -52,4 +53,32 @@ public function testOnRouteShutdown(): void | |
static::assertSame(Response::HTTP_MOVED_PERMANENTLY, $response->getStatusCode()); | ||
static::assertSame('shopware.php/www.test.de', $response->getHeader('location')); | ||
} | ||
|
||
public function testOnRouteStartupClearShopCookie(): void | ||
{ | ||
$pluginBootstrap = $this->getContainer()->get('plugins')->Core()->Router(); | ||
|
||
$request = new Enlight_Controller_Request_RequestTestCase(); | ||
$request->setRequestUri('shopware.php/www.test.de'); | ||
$request->setCookie('shop', 2); | ||
$response = new Enlight_Controller_Response_ResponseTestCase(); | ||
$args = new Enlight_Controller_EventArgs([ | ||
'request' => $request, | ||
'response' => $response, | ||
]); | ||
$pluginBootstrap->onRouteStartup($args); | ||
|
||
static::assertSame(Response::HTTP_OK, $response->getStatusCode()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mitelg, here 2 options for testing this, I'm not happy with both solutions |
||
// Option A | ||
static::assertIsString($response->headers->get('Set-Cookie')); | ||
static::assertStringContainsString('shop=deleted', $response->headers->get('Set-Cookie')); | ||
|
||
// Option B | ||
$cookie = $response->headers->getCookies(); | ||
static::assertCount(1, $cookie); | ||
static::assertInstanceOf(Cookie::class, $cookie[0]); | ||
static::assertSame('shop', $cookie[0]->getName()); | ||
static::assertTrue($cookie[0]->isCleared()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearing the cookie here, would also affect the next if condition, if I see that correctly.
Before your change, the if condition could also be met, if this condition was met before.
With your change this is no longer possible.
A test of the
\Shopware_Plugins_Core_Router_Bootstrap::onRouteStartup
method in\Shopware\Tests\Functional\Plugins\Core\Router\BootstrapTest
would be really nice, to ensure, that we do not break stuffThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, the main problem is, I don't understand the reason of this cookie.
I tested this change on my server and I still get redirect after the first attempt, trying to visit the start page. Only on the second attempt is the Cookie gone and I can visit the primary shop again.
But I don't know, if there is a case that the cookie is needed to redirect to the right shop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the cookie at all then? 🤔
unfortunately I cannot reproduce this locally. you wrote this only occurs via HTTPS? 🤔 If I am using only HTTP, the cookie is not set at all 🤔