getCookieValue returns an object - gatling

I`ve used method getCookieValue() for get cookie value from session, it returns an object io.gatling.http.action.cookie.GetCookieValueBuilder#2012cf26
.exec{session => {
val cookie = getCookieValue(CookieKey("CookieKey"))
println("Session cookie is :::::::::::::::::::::::::" + cookie.toString)
session
}}
should get cookie value instead of io.gatling.http.action.cookie.GetCookieValueBuilder#2012cf26

looking at the documentation, getCookieValue is a DSL action that (as you discovered) returns a builder, so you would need to execute it in an 'exec' block - it's designed to get a named cookie and put it into the session.
so if you did
.exec(getCookieValue(CookieKey("CookieKey")))
the value of the cookie named "CookieKey" would be put in the session under the key "CookieKey".
You can't call DSL methods inside a session function - the returned builder won't ever be called

Related

Can't get data from Marvel API - The passed referrer not allowed for the passed API key

I'm trying to get data from the Marvel API, using this request URL:
https://gateway.marvel.com:443/v1/public/characters?apikey=4dab7cb0585a4ea6c5d6a183f6769968
But, when using the fetch API method and logging the data to console. I'm get this:
{code: "InvalidCredentials", message: "The passed referrer is not allowed for the passed API key."}
Following the link you shared I get this error:
{"code":"MissingParameter","message":"You must provide a hash."}
Accoring to the documentation, you need to provide a timestamp, ts and a hash value in the request parameter.
Also check your Your authorized referrers section.If you add * and update it will allow from any host.
See docs:
https://developer.marvel.com/documentation/authorization

Gatling not storing value in session

I am using sessions in gatling to store values, as shown below
exec(session => {
val id = Instant.now.toEpochMilli.toString + scala.util.Random.nextInt(1000).toString
session.set("STARTED_PROCESS_ID",id)
//Store the id somewhere for processing later
session
})
.exec(
http("scenario")
.post(url)
.header("Content-Type", "application/json")
.header("id", session => session("STARTED_PROCESS_ID").as[String])
.body(StringBody(body)
.check(status.is(200))
According to the documentation, the value should be stored in session & the header "id" should be populated as expected. But when running the simuation I get the following error
java.util.NoSuchElementException: No attribute named 'STARTED_PROCESS_ID' is defined
at io.gatling.core.session.SessionAttribute.as(Session.scala:46)
at common.HttpUtil$.$anonfun$sendPostRequestForWasStartDefLoad$1(HttpUtil.scala:557)
at io.gatling.core.action.SessionHook.execute(SessionHook.scala:32)
at io.gatling.core.action.Action.$bang(Action.scala:38)
at io.gatling.core.action.Action.$bang$(Action.scala:38)
Can someone please help explain why is this happening ?
You're not using the Session API correctly. Please properly read the documentation.
Session is immutable and set returns a new instance.
exec { session =>
val id = Instant.now.toEpochMilli.toString + scala.util.Random.nextInt(1000).toString
session.set("STARTED_PROCESS_ID",id)
}
gatling sessions are immutable, so where you return session as the final line of your session function, you're actually returning the initial, unedited session.
session.set returns a new, updated session, so you can just leave that as the last line of the session function and it should work.

Identity Server 4 GetSchemeSupportsSignOutAsync returns incorrect response

I've setup an open id connect provider, Google in this case, using the AddOpenIdConnect extension method in dotnet core. From the discovery document:
https://accounts.google.com/.well-known/openid-configuration
it does not seem that google supports federated sign-out because there is no end_session endpoint. However, in Identity Server 4, the call:
var providerSupportsSignout = await HttpContext.GetSchemeSupportsSignOutAsync(idp);
returns true. So during Logout it tries to sign out of google using:
return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
which throws an exception:
InvalidOperationException: Cannot redirect to the end session endpoint, the configuration may be missing or invalid.
Is this a bug in Identity Server 4 or is there a configuration property that needs to be set when setting up the Oidc provider so that this extension method will pickup that the provider does not support signout?
Doesn't appear to be a bug in Identity Server 4. The code behind this extension calls out to get the underlying authentication scheme handler.
public static async Task<bool> GetSchemeSupportsSignOutAsync(this HttpContext context, string scheme)
{
var provider = context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>();
var handler = await provider.GetHandlerAsync(context, scheme);
return (handler != null && handler is IAuthenticationSignOutHandler);
}
In this case, your handler will be OpenIdConnectHandler which appears to implement IAuthenticationSignOutHandler so that's why regardless of what is in the discovery document (end session endpoint supported or not), if you use the AddOpenIdConnect(...), it will always register a handler which seemingly supports sign out, but as you have pointed out, does not actually enforce the actual idp validation for that kind of functionality support (link to handler source).
And lastly, worthwhile to mention, that Identity Server 4 check is rightful here as according to Microsoft docs, the IAuthenticationSignOutHandler is indeed basically a marker interface used to determine if a handler supports SignOut.
So I guess you just simply can't use the generic AddOpenIdConnect(...), instead perhaps you should use AddGoogle(...) which does not implement IAuthenticationSignOutHandler so will work as expected with Identity Server 4 (link to source).
As Vidmantas Blazevicius mentioned, using .AddOpenIdConnect will make the extension method default to true because of the interface. I have changed my code to explicity check for the support of an end_session_endpoint by doing:
var discoveryClient = new IdentityModel.Client.DiscoveryClient("https://accounts.google.com/.well-known/openid-configuration")
{
Policy = new IdentityModel.Client.DiscoveryPolicy
{
ValidateEndpoints = false, //this is needed for google, if set to true then will result in error response
ValidateIssuerName = false //this is needed for Microsoft, if set to true then will result in error response
}
};
var discoveryResult = await discoveryClient.GetAsync();
if (!discoveryResult.IsError)
{
if (!String.IsNullOrWhiteSpace(discoveryResult.EndSessionEndpoint))
supportsFederatedSignOut = true;
}
I then save an additional property on the model "SupportsFederatedSignOut" and then use this to determine whether external identity provider signout (SignOut) should be called.

Get UserId from the Session Id and Server URL

I have a requirement, where I will be getting the Session Id and Server URL(parameters of a webservice method).
Say like this:
Session ID : 00D900000xxxxxx!ARUAQOb4VVoQR1UXlY_Hvuy1DdKdN6nSfnNJKYwPTF9R3tYuA2jzBsWXHIGDQUFL13iebnYSDKKC45H98TzVxxxxxxxxxx
Server URL :
https://ap1.salesforce.com/services/Soap/u/12.0/00D900000xxxxxx
Now i need to get the User Id(or any other user details) from these two.
Thanks in Advance!!
Nitin
You could use the SOAP API, which has a GetUserInfo method. Calling this method will return a GetUserInfoResult object, which will contain the user ID associated to the session.
Adam, GetUserInfo method requires existing connection object which we can create by calling method, so I applied the following code and now everything works fine!
ConnectorConfig config = new ConnectorConfig();
config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/24.0/");
config.setServiceEndpoint("https://na14.salesforce.com/services/Soap/c/24.0/00DXXXXXXXXXXXX");
config.setSessionId("00DXXXXXXXXXXXX!1AQ4AQO980Fmu25SOFQxxOlQN8zAaHOlnfdk._rZU2Vkf_CV0HJREqKavMLaPg9jtA9N517MNHLdLeF.aVkoZtnk2eu7u.XNn");
connection = new EnterpriseConnection(config); GetUserInfoResult
userInfo = connection.getUserInfo();
I used the same server URL and sessionId that I have received from query parameter string.

Cakephp cookie always get deleted automatically

Anybody have an idea, why cookie in Cakephp always get deleted automatically after function ends?
I try to write a cookie in let say function abc, with following :
$this->Cookie->write('referal', $ref);
Before that, in app controller before filter, i have initialized the cookie as following :
$this->Cookie->name = 'renttycoons';
$this->Cookie->time = 604800; // or '1 week'
$this->Cookie->path = '/';
$this->Cookie->domain = 'rent.local';
$this->Cookie->key = 'qSI232qs*&sXOw!';
But once the execution of function ends, the cookie was empty. when i try to read the cookie before function abc ends, it was there. There was no delete cookie method anyway.
yes, because the way Cookie in Cake works: when you use Cookie->write(), it doesn't directly write to the cookie, because the cookie is in the user's browser. Only until the view is rendered that the cookie you wrote is sent. So when you redirect, (I would guess the cookie doesn't get sent and flushed out because the view isn't rendered) the new request has the old cookie data.
If you want to persist some shared data within cake app, and unique to each visitor, use SessionComponent. It looks pretty much the same as Cookie: $this->Session->write('referal', $ref); and $this->Session->read('referal');

Resources