How to get SubtleCrypto work with testcafe? - javascript

I am generating SHA256 using SubtleCrypt Web API on client-side as following:
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
Everything works fine except for when I execute tests via testcafe. The captured console error says TypeError: Cannot read properties of undefined (reading 'digest') meaning crypto.subtle is undefined.
I know that SubtleCrypto is available only in secure contexts which also includes localhost and I am using localhost to run my end-to-end testcafe tests.
What am I doing wrong?

You need to run TestCafe over HTTPS protocol. See more information in the following help topic: test-https-websites.

Related

TypeError when testing with Jest and Formidable

I have wrote a cusom express middleware to pars an incoming multipart form.
The middleware works fine when launched in local or deployed but the test with jest fails with the error
TypeError: Cannot set property domain of [object process] which has only a getter
The issues seems to come from the package asap used by formidable.
I think that Jest is putting some limitations on the process object since the line where everything breaks is
domain.active = process.domain = null;
in the file raw.js
Does anyone has any workaround or solution for this issue? I cannot migrate to formidable V3 at the moment so that's not an option

Using axios-cookiejar-support with Vue.js on the backend

Has anyone used axios-cookiejar-support with Vue.js on the backend?
I'm getting the following error in the Chrome debugger:
Uncaught (in promise) TypeError: axiosCookieJarSupport is not a function
And when I console.log(axiosCookieJarSupport) I see "undefined" when I run the the init code shown on the axios-cookiejar-support site that modifies Axios to support cookies:
const axiosCookieJarSupport = require('axios-cookiejar-support').default;
axiosCookieJarSupport(axios); // <--- error occurs here
Obviously, I tried it with a Node.js console application and it works, and I can console.log axiosCookieJarSupport and I see that it is a function in the console application.
I'm guessing I need to somehow tell Webpack (which I believe Vue.js uses) to preload axios-cookiejar-support, as opposed to just include it in the package.json (which I did), but I'm not sure how to do it.

Truffle Drizzle error "TypeError: Cannot read property 'address' of undefined"

Expected:
After running the app, the user should see a "Loading Drizzle..." msg in the browser then soon followed by "Drizzle is ready".
Results:
The app stays stuck on "Loading Drizzle..." and there is an error in the chrome console:
Error
uncaught at root at root
at contractsSaga
at takeEvery
at addContract
at instantiateContract
TypeError: Cannot read property 'address' of undefined
I'm following this tutorial here: https://truffleframework.com/tutorials/getting-started-with-drizzle-and-react
And I'm at the current section:
Replace the render method
render() {
if (this.state.loading) return "Loading Drizzle...";
return <div className="App">Drizzle is ready</div>;
}
I've done that in my app, and expected to see the "Drizzle is ready" message, but instead got the error above.
Here is my repo: https://github.com/leongaban/truffle_drizzle_test
No contracts are deployed to your ganache network, which is why that error is occurring.
In the root of your folder, make sure you run truffle migrate after truffle compile.
I had the same problem, even after deploying the contracts correctly to my ganache network. The reason it didn't work for me was that I had MetaMask active on my Chrome Browser. I was not even logged in, but still it appears that the dapp was looking for the contract on the wrong network. When I open the site with Incognito Mode / completely disabled MetaMask, it works!
This is something the tutorial points out, but I guess it's easy to not take seriously:
Note: Make sure to use an incognito window if you already have
MetaMask installed (or disable MetaMask for now). Otherwise, the app
will try to use the network specified in MetaMask rather than the
development network under localhost:8545.
truffle migrate will deploy your contract onto your blockchain network, and then output a file build/contracts/YourContract.json which contains info about your contract. For example, it contains the ABI for your contract and the address that your contract was deployed at.
Your JavaScript probably imports that JSON file in order to have the needed information to connect to your contract. Therefore, be sure that the JS is importing the most up-to-date version of the JSON, otherwise it won't know which address to find your contract at, etc.

Invalid JSON RPC response: undefined

I'm trying to create an Ethereum account through Node.js. This is my code:
export async function createNewAccount() {
var web3Instance = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
return web3Instance.eth.accounts.create();
}
But I'm getting the following error (from 'create' function):
Invalid JSON RPC response: undefined
I have installed web3.js in my project.
What other step have I missed?
BTW opening the browser on address http://localhost:8545 returns 404. Is there anything I need to install in order to make it work? Is that the testrpc?
Notice that I want to work against the real blockchain, not a test one.
Web3.js is only a javascript interface that can deal with a real node, in order to conduct RPC requests you must have an ethereum node running this can be either
TestRPC , Parity , Geth. additionally, since you are pointing to localhost you will need to run it on your own
The easiest for you to test with will be testRPC install and run it will. By default give you 10 accounts. in order to create a new account with testRPC you will need to run it with --unlock option

What is causing my "illegal character in input string" exception with Facebook PHP SDK when deploying to Heroku?

"facebook/php-sdk-v4" : "4.0.*" - resolves to 4.0.15
Javascript SDK v2.2
I'm having an issue when deploying my laravel app to Heroku using the latest JS SDK and PHP SDK.
It works perfectly locally (nginx) but when deployed to Heroku (Apache) it fails here:
$helper = new FacebookJavaScriptLoginHelper();
with exception -
iconv_strlen(): Detected an illegal character in input string
Logs with both local and remote cookies look the same (structurally), so it's not that:
[fbsr_75710##########] => dJPP8B2GrKYHLmM8826lLXsjclHexnHv4V-dooUISI0.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI...........
I ran into the same issue. If you look at the full stack trace you will see that mb_strlen is used before iconv and returns a bad result; turns out that on Heroku, the mbstring extension is not enabled by default. You need to manually request it in your composer.json, in the "require": bit:
"ext-mbstring": "*"
Update, push and it should work for you. Bit of a late answer but hopefully this will be helpful for anyone running into the same issue.

Categories