I am trying to do load testing for a RESTlet endpo...
# suitescript
m
I am trying to do load testing for a RESTlet endpoint. I am using the Token-Based authentication method. The request works fine in Insomnia (similar to Postman), but I can't get it to work in code. I don't even know how. Anyone tried that before?
s
not sure what 'code' you mean, but you just need a client that follows the TBA authentication (OAuth) protocol
m
Tools like K6 for example let you write code to do loadtesting. It works from the client just fine. But you can only send one request from it.
c
Load testing in a shared tenant environment is going to be spotty at BEST. Especially NetSuite. You get X number of connections per suitecloud plus license you have so you're going to be able to use those X and then performance is going to be totally random since its shared tenant. If you have your own instance, it may be more reliable for sure. Code wise, you'd just need to write something that calls the restlet w/ the desired credentials which there should be tons of examples on.
💯 1
b
if you are trying to write code to send a request to netsuite, then use something that does oauth1 for you
k6 suggests javascript, in which case i recommend oauth-1.0a
m
I tried that but didn't work 😢
b
what did you try
m
Copy code
class Oauth1Helper {
	static getAuthHeaderForRequest(request) {
		const oauth = oauth1a({
			consumer: { key: CONSUMERKEY, secret: CONSUMERSECRET },
			signature_method: 'HMAC-SHA1',
			hash_function(base_string, key) {
				return crypto
					.createHmac('sha1', key)
					.update(base_string)
					.digest('base64')
			},
		})

		const authorization = oauth.authorize(request, {
			key: TOKENKEY,
			secret: TOKENSECRET,
		});

		return oauth.toHeader(authorization);
	}
}

module.exports = Oauth1Helper;
the example mentioned in the docs.
I took that header and passed it to axios, but didn't work. I get Invalid login attempt.
b
missing realm
usually the login audit trail will tell you that particular error
m
omg, I added 'realm' and it worked. I can't thank you enough ❤️