How to generate the COOKIEHASH from JavaScript

Question

The overarching question

How do I get the contents of the PHP-variable: COOKIEHASH inside a Cypress-test.


I’m writing some Cypress-test for WordPress, and in order to set the cookies to log in a user in WordPress using Cypress, then I need the contents of the COOKIEHASH-variable.

For those not familiar with the COOKIEHASH, go to a WordPress-installation and put in this code anywhere:

echo '<pre>';
print_r(COOKIEHASH);
echo '</pre>';
die();

And then you’ll see it. It looks something like this: a8b94154380982c3284a467b8aa224c6.

When I run my Cypress-tests for the first time, then I don’t know what that hash is, so I don’t know which cookies to set.

So currently I log in manually, go to cookies in my browser and get the hash. Which is quite the manual operation for automated tests. 🙂


My attempts / thoughts

  1. It looks like an MD5-hash. But I can’t recreate the cookie-hash with an JS MD5-function. It doesn’t correspond. I haven’t tried that many MD5-JS-functions, it should be said.

  2. I considered making an API-endpoint (in my functions.php), that returns the cookie-hash. But this just feels wrong, making my code to backflips like this.

0
Zeth 2 years 2020-10-23T11:10:27-05:00 0 Answers 14 views 0

Leave an answer

Browse
Browse