I have the following Cypress + CryptoJS code which works perfectly, except for the sha256 hash. It finds the URL link, downloads the ~30k PDF file, and saves it locally. The end goal is to have the test verify the response bytes against a known hash, not save it to a file.
- The length of the response.body is identical to the server file and the saved file.
- The
sha256sumof the server file and the saved file is identical. - The SHA256 of the response.bytes, however, is different.
Am I using Cypress and CryptoJS properly to send the exact bytes of the PDF to the CryptoJS.SHA256 function?
cy.xpath("//div[contains(@class, 'pdf')]/a").invoke('attr', 'href').then(href => {
cy.request({
url: href,
encoding: 'binary',
})
.then((response) => {
cy.writeFile('/Users/jc/document.pdf', response.body, 'binary');
console.log('length: ', response.body.length);
console.log('SHA256: ', CryptoJS.SHA256(response.body).toString(CryptoJS.enc.Hex));
})
});