7
7
8
8
namespace Magento \GraphQl \GraphQlCache \CacheIdFactorProviders \Customer ;
9
9
10
- use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
11
10
use Magento \TestFramework \TestCase \GraphQlAbstract ;
12
11
13
12
/**
16
15
class IsLoggedInProviderTest extends GraphQlAbstract
17
16
{
18
17
/**
19
- * Tests that cache id header is generated for generateToken mutation and other post requests
18
+ * Tests cache is not generated for generateToken mutation and other post requests
20
19
*
21
20
* @magentoApiDataFixture Magento/Customer/_files/customer.php
22
21
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
@@ -38,10 +37,12 @@ public function testCacheIdHeaderWithIsLoggedIn()
38
37
}
39
38
MUTATION ;
40
39
$ tokenResponse = $ this ->graphQlMutationWithResponseHeaders ($ generateToken );
41
- // Verify that the the cache id is generated for generate token mutation
42
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ tokenResponse ['headers ' ]);
43
- $ cacheIdCustomerToken = $ tokenResponse ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
44
- $ this ->assertTrue ((boolean )preg_match ('/^[0-9a-f]{64}$/i ' , $ cacheIdCustomerToken ));
40
+ // Verify that the cache is not generated for generate token mutation
41
+ $ this ->assertEquals ('no-cache ' , $ tokenResponse ['headers ' ]['Pragma ' ]);
42
+ $ this ->assertEquals (
43
+ 'no-store, no-cache, must-revalidate, max-age=0 ' ,
44
+ $ tokenResponse ['headers ' ]['Cache-Control ' ]
45
+ );
45
46
$ this ->assertArrayHasKey ('generateCustomerToken ' , $ tokenResponse ['body ' ]);
46
47
$ customerToken = $ tokenResponse ['body ' ]['generateCustomerToken ' ]['token ' ];
47
48
$ createEmptyCart = <<<MUTATION
@@ -54,20 +55,21 @@ public function testCacheIdHeaderWithIsLoggedIn()
54
55
'' ,
55
56
['Authorization ' => 'Bearer ' . $ customerToken ]
56
57
);
57
- //Verify that the the cache id is generated for authorized mutation like createEmptyCart
58
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ createCustomerCartResponse ['headers ' ]);
58
+ //Verify that the cache is not generated for authorized mutation like createEmptyCart
59
+ $ this ->assertEquals ('no-cache ' , $ createCustomerCartResponse ['headers ' ]['Pragma ' ]);
60
+ $ this ->assertEquals (
61
+ 'no-store, no-cache, must-revalidate, max-age=0 ' ,
62
+ $ createCustomerCartResponse ['headers ' ]['Cache-Control ' ]
63
+ );
59
64
$ cartId = $ createCustomerCartResponse ['body ' ]['createEmptyCart ' ];
60
- $ cacheIdCreateCustomerCart = $ createCustomerCartResponse ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
61
- $ this ->assertTrue ((boolean )preg_match ('/^[0-9a-f]{64}$/i ' , $ cacheIdCreateCustomerCart ));
62
- $ this ->assertEquals ($ cacheIdCustomerToken , $ cacheIdCreateCustomerCart );
63
65
64
66
$ createGuestCartResponse = $ this ->graphQlMutationWithResponseHeaders ($ createEmptyCart );
65
- //Verify that cache id is generated for unauthorized post requests
66
- $ this ->assertArrayHasKey (CacheIdCalculator:: CACHE_ID_HEADER , $ createGuestCartResponse ['headers ' ]);
67
- $ cacheIdCreateGuestCart = $ createGuestCartResponse [ ' headers ' ][CacheIdCalculator:: CACHE_ID_HEADER ];
68
- $ this -> assertTrue (( boolean ) preg_match ( ' /^[0-9a-f]{64}$/i ' , $ cacheIdCreateGuestCart ));
69
- //Verify that cache id generated for customer and guest are not equal
70
- $ this -> assertNotEquals ( $ cacheIdCreateCustomerCart , $ cacheIdCreateGuestCart );
67
+ //Verify that cache is not generated for unauthorized post requests
68
+ $ this ->assertEquals ( ' no-cache ' , $ createGuestCartResponse ['headers ' ][ ' Pragma ' ]);
69
+ $ this -> assertEquals (
70
+ ' no-store, no-cache, must-revalidate, max-age=0 ' ,
71
+ $ createGuestCartResponse [ ' headers ' ][ ' Cache-Control ' ]
72
+ );
71
73
$ addProductToCustomerCart = <<<MUTATION
72
74
mutation{
73
75
addSimpleProductsToCart
@@ -86,11 +88,11 @@ public function testCacheIdHeaderWithIsLoggedIn()
86
88
'' ,
87
89
['Authorization ' => 'Bearer ' . $ customerToken ]
88
90
);
89
- $ this -> assertArrayHasKey (CacheIdCalculator:: CACHE_ID_HEADER , $ addProductToCustomerCartResponse [ ' headers ' ]);
90
- //Verify that cache id generated for all subsequent operations by the customer remains consistent
91
+ //Verify that cache is not generated for addSimpleProductsToCart mutation
92
+ $ this -> assertEquals ( ' no- cache' , $ addProductToCustomerCartResponse [ ' headers ' ][ ' Pragma ' ]);
91
93
$ this ->assertEquals (
92
- $ cacheIdCreateCustomerCart ,
93
- $ addProductToCustomerCartResponse ['headers ' ][CacheIdCalculator:: CACHE_ID_HEADER ]
94
+ ' no-store, no-cache, must-revalidate, max-age=0 ' ,
95
+ $ addProductToCustomerCartResponse ['headers ' ][' Cache-Control ' ]
94
96
);
95
97
}
96
98
@@ -102,12 +104,15 @@ public function testCacheIdHeaderWithIsLoggedIn()
102
104
*/
103
105
public function testCacheIdHeaderAfterRevokeToken ()
104
106
{
105
- // Get the guest cache id
107
+ // Get the guest headers
106
108
$ guestCartResponse = $ this ->graphQlMutationWithResponseHeaders ('mutation{createEmptyCart} ' );
107
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ guestCartResponse ['headers ' ]);
108
- $ guestCacheId = $ guestCartResponse ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
109
+ $ this ->assertEquals ('no-cache ' , $ guestCartResponse ['headers ' ]['Pragma ' ]);
110
+ $ this ->assertEquals (
111
+ 'no-store, no-cache, must-revalidate, max-age=0 ' ,
112
+ $ guestCartResponse ['headers ' ]['Cache-Control ' ]
113
+ );
109
114
110
- // Get the customer cache id and token to send to the revoke mutation
115
+ // Get the customer token to send to the revoke mutation
111
116
$ generateToken = <<<MUTATION
112
117
mutation{
113
118
generateCustomerToken(email:"customer@example.com", password:"password")
@@ -117,20 +122,24 @@ public function testCacheIdHeaderAfterRevokeToken()
117
122
$ tokenResponse = $ this ->graphQlMutationWithResponseHeaders ($ generateToken );
118
123
$ this ->assertArrayHasKey ('generateCustomerToken ' , $ tokenResponse ['body ' ]);
119
124
$ customerToken = $ tokenResponse ['body ' ]['generateCustomerToken ' ]['token ' ];
120
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ tokenResponse ['headers ' ]);
121
- $ customerCacheId = $ tokenResponse ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
122
- $ this ->assertNotEquals ($ customerCacheId , $ guestCacheId );
125
+ $ this ->assertEquals ('no-cache ' , $ tokenResponse ['headers ' ]['Pragma ' ]);
126
+ $ this ->assertEquals (
127
+ 'no-store, no-cache, must-revalidate, max-age=0 ' ,
128
+ $ tokenResponse ['headers ' ]['Cache-Control ' ]
129
+ );
123
130
124
- // Revoke the token and check that it returns the guest cache id
131
+ // Revoke the token and check that cache is not generated
125
132
$ revokeCustomerToken = "mutation{revokeCustomerToken{result}} " ;
126
133
$ revokeResponse = $ this ->graphQlMutationWithResponseHeaders (
127
134
$ revokeCustomerToken ,
128
135
[],
129
136
'' ,
130
137
['Authorization ' => 'Bearer ' . $ customerToken ]
131
138
);
132
- $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ revokeResponse ['headers ' ]);
133
- $ revokeCacheId = $ revokeResponse ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
134
- $ this ->assertEquals ($ guestCacheId , $ revokeCacheId );
139
+ $ this ->assertEquals ('no-cache ' , $ revokeResponse ['headers ' ]['Pragma ' ]);
140
+ $ this ->assertEquals (
141
+ 'no-store, no-cache, must-revalidate, max-age=0 ' ,
142
+ $ revokeResponse ['headers ' ]['Cache-Control ' ]
143
+ );
135
144
}
136
145
}
0 commit comments