Gatling - No attribute named 'CSRF' is defined - scala

I get this error that my attribute is not defined and I can't figure out why.
I have it it first saved in my first request as CSRF variable.
Later on I try to access it while doing post request to fill out the form.
This is my main simulation class:
package simulations.stage
import io.ecx.steps.{Config, Login}
import io.gatling.core.Predef._
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import scala.concurrent.duration._
class RampUsersLoadSimulations extends Simulation{
val httpConf: HttpProtocolBuilder = http.baseUrl(Config.baseUrl)
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36")
.inferHtmlResources()
.acceptEncodingHeader("gzip, deflate, br")
.proxy(Proxy("localhost", 8866))
before {
println(s"Running for: ${Config.baseUrl}")
}
val login: ScenarioBuilder = scenario("Scenario: Login to the storefront")
.exec(
Login.login(Config.accounts),
Login.navigateToMyAccountPage())
setUp(login.inject(atOnceUsers(1))).protocols(httpConf)
}
This is my steps object where I try to save it and then use it in the post request:
package io.ecx.steps
import io.gatling.core.Predef._
import io.gatling.http.Predef._
object Login {
def login(accountsPath: String) = {
val accounts = csv(accountsPath).random
exec(http("Load Login Page")
.get("/login")
.check(regex("<title>My Title</title>").exists)
.check(css("[name=CSRFToken]", "value").saveAs("CSRF"))
.check(status.is(200)))
.pause(2)
// .exec{session => println(session); session}
feed(accounts)
.exec(http("Log in with credentials to the storefront")
.post("/j_spring_security_check")
.formParam("username", "${username}")
.formParam("password", "${password}")
.formParam("rememberMe", "${rememberMe}")
.formParam("CSRFToken", "${CSRF}")
.check(css("#loginForm").notExists)
.check(status.in(200)))
.pause(5)
}
def navigateToMyAccountPage() = {
exec(http("Open My account Page")
.get("accountSummary")
.check(css(".page-AccountSummaryPage").exists)
.check(status.in(200)))
.pause(2)
}
}
In the HTML that is loaded when login page loads we have:
<input type="hidden" name="CSRFToken" value="6ac89c39-ee25-4cdc-9553-cc8a7824f43b" />
This is the logs:
Simulation simulations.stage.RampUsersLoadSimulations started...
Session(Scenario: Login to the storefront,1,Map(gatling.http.ssl.sslContexts -> io.gatling.http.util.SslContexts#6e62fe0c, gatling.http.cache.dns -> io.gatling.http.resolver.ShufflingNameResolver#56fe67f3, gatling.http.cache.baseUrl -> https://my-site.com),KO,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$434/1485485458#7dcefc4,io.netty.channel.nio.NioEventLoop#70f02c32)
23:29:59.611 [ERROR] i.g.h.a.HttpRequestAction - 'httpRequest-4' failed to execute: No attribute named 'CSRF' is defined
================================================================================
2021-03-03 23:30:00 5s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=0 KO=1 )
> Load Login Page (OK=0 KO=1 )
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 1 (50.00%)
on
> Log in with credentials to the storefront: Failed to build req 1 (50.00%)
uest: No attribute named 'CSRF' is defined
---- Scenario: Login to the storefront -----------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-03-03 23:30:05 10s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=0 KO=1 )
> Load Login Page (OK=0 KO=1 )
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 1 (50.00%)
on
> Log in with credentials to the storefront: Failed to build req 1 (50.00%)
uest: No attribute named 'CSRF' is defined
---- Scenario: Login to the storefront -----------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-03-03 23:30:08 13s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=0 KO=2 )
> Load Login Page (OK=0 KO=1 )
> Open My account Page (OK=0 KO=1 )
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 2 (66.67%)
on
> Log in with credentials to the storefront: Failed to build req 1 (33.33%)
uest: No attribute named 'CSRF' is defined
---- Scenario: Login to the storefront -----------------------------------------
[##########################################################################]100%
waiting: 0 / active: 0 / done: 1
================================================================================
Simulation simulations.stage.RampUsersLoadSimulations completed in 13 seconds
Parsing log file(s)...
Parsing log file(s) done
Generating reports...
================================================================================
---- Global Information --------------------------------------------------------
> request count 2 (OK=0 KO=2 )
> min response time 2015 (OK=- KO=2015 )
> max response time 2019 (OK=- KO=2019 )
> mean response time 2017 (OK=- KO=2017 )
> std deviation 2 (OK=- KO=2 )
> response time 50th percentile 2017 (OK=- KO=2017 )
> response time 75th percentile 2018 (OK=- KO=2018 )
> response time 95th percentile 2019 (OK=- KO=2019 )
> response time 99th percentile 2019 (OK=- KO=2019 )
> mean requests/sec 0.143 (OK=- KO=0.143 )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms 0 ( 0%)
> 800 ms < t < 1200 ms 0 ( 0%)
> t > 1200 ms 0 ( 0%)
> failed 2 (100%)
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 2 (66.67%)
on
> Log in with credentials to the storefront: Failed to build req 1 (33.33%)
uest: No attribute named 'CSRF' is defined
================================================================================
Could it be that I have this behavior because the input field is marked as hidden?
Or there is something I can't see.
Please help.
Thanks!

You have an error in your code: you're missing a dot before feed(accounts). Because of this, it's not attached to the head and only the tail is considered.

Related

IMAP UID FETCH Command - Return two sequence numbers by one UID request

In very rare cases server returns a second sequence number.
Example log:
C: A0020 UID FETCH 304244 (BODY[HEADER.FIELDS (SUBJECT FROM TO CC REPLYTO MESSAGEID DATE SIZE REFERENCES)] UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE RFC822.HEADER)
S: * 9 FETCH (BODY[HEADER.FIELDS (SUBJECT FROM TO CC REPLYTO MESSAGEID DATE SIZE REFERENCES)] {262}
S: Date: Thu, 29 Dec 2022 00:00:00 +0000\r\nFrom: Name <email#domain.com>\r\nSubject: Subject\r\nTo: <email#domain.com>\r\nCC:\r\n\r\n
S: UID 304244 FLAGS (\\Seen) INTERNALDATE \"29-Dec-2022 01:00:00 +0100\" RFC822.SIZE 226713 ENVELOPE (ENVELOPE DATA) RFC822.HEADER {7754}
S: MIME-Version: 1.0\r\nReceived: from ... email data
S: FLAGS (\\Seen))
S: * 11 FETCH (FLAGS (\\Seen \\Deleted))
S: A0020 OK FETCH completed.
Client request UID FETCH by UID "304244". The server responded that the email is "9" sequence number. At the end before "OK FETCH completed." the server returns another sequence number "11" with information about the flags.
I tried to find in https://www.rfc-editor.org/rfc/rfc3501#section-6.4.5 , https://www.rfc-editor.org/rfc/rfc3501#section-6.4.8 and elsewhere some information on such responses from the server, but found nothing. Does anyone know why the server in the "UID FETCH" command response returns another sequence number with information about the flags and what it can mean?
UPDATE:
Today I have got this case:
C: A0051 UID FETCH 305421 (BODY[HEADER.FIELDS (SUBJECT FROM TO CC REPLYTO MESSAGEID DATE SIZE REFERENCES)] UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE RFC822.HEADER)
S: * 40 FETCH (BODY[HEADER.FIELDS (SUBJECT FROM TO CC REPLYTO MESSAGEID DATE SIZE REFERENCES)] {209}
S: To: email#domain.com\r\nSubject: Subject\r\nDate: Tue, 03 Jan 2023 00:07:15 +0200\r\nFrom: <email#domain.com>\r\n\r\n
S: UID 305421 FLAGS (\\Seen) INTERNALDATE \"02-Jan-2023 23:07:20 +0100\" RFC822.SIZE 158940 ENVELOPE (ENVELOPE DATA) RFC822.HEADER {8278}
S: MIME-Version: 1.0\r\nReceived: from ... email data
S: FLAGS (\\Seen))
S: * 3 FETCH (FLAGS (\\Seen \\Deleted))
S: * 4 FETCH (FLAGS (\\Seen \\Deleted))
S: * 5 FETCH (FLAGS (\\Seen \\Deleted))
S: * 6 FETCH (FLAGS (\\Seen \\Deleted))
S: * 7 FETCH (FLAGS (\\Seen \\Deleted))
S: * 8 FETCH (FLAGS (\\Seen \\Deleted))
S: A0051 OK FETCH completed.
So, if I understood the answer below correctly. While the server run "UID FETCH" the email from the server, someone in another session change this and other emails. In begin of "UID FETCH" the sequence number was "40". But during command execution the sequence number changed several times: 40 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8. That is why the server sends me these "* number FETCH (FLAGS ...)" lines. Did I understand correctly?
What you want is described in IMAP-speak as: Your FETCH command directs the server to send an untagged FETCH command before the server concludes processing the FETCH command, and return a tagged response with the result (usually just OK).
Note the verb directs. Other things can also direct the server to send untagged responses, even at the same time as you direct it. For example, when new mail arrives, that directs the server to send an untagged EXISTS response as soon as possible.
Your example is a bit strange, but the server is allowed to do it.
The simplest way to deal with it is to maintain a cache of messages clientside, update the relevant message in the cache whenever you get a FETCH response, and when you receive a tagged OK, you can trust that the information you wanted is now present in the cache.
Make sure to test what happens if a message is deleted just as you request it. The server's untagged responses should cause your cache to contain something like 'this message has been deleted'.

How to add total and percentage column for splunk timechart command

Using a simple example: count the number of events for each host name
... | timechart count BY host
> ... | timechart count BY host
>
> This search produces this results table:
>
> _time host1 host2 host3
>
> 2018-07-05 1038 27 7
> 2018-07-06 4981 111 35
> 2018-07-07 5123 99 45
> 2018-07-08 5016 112 22
What I want is to add a column to show the total events for that day and the percentage of each http status code.
I tried
... | timechart count BY host
| eval total= host1 + host2 + host3
| eval host1_percent = host1 / total
| eval host2_percent = host2 / total
| eval host3_percent = host3 / total
| table _time, host1_percent, host2_percent, host3_percent
This works most of the time, but I found out if for certain day, a host was offline (no record for a particular host), then the search doesn't work (return blank results), I have to remove that particular host from the "total = host1 + host2 + host3" to get it to work.
So my question is: is there a way to get the total number of record for for every day (row) without having to add them together, e.g. replace the "total = host1 + host2 + host3" with a count or sum, I tried couple of thing, none of them work.
It would help to know what you've tried so far so we don't suggest the same things.
Have you tried addtotals?
| timechart count by host
| addtotals row=true fieldname=total host*

Play 2.4 / Slick 3.1: database evolution connection leak

I have a default setup of Play 2.4 and Slick 3.1 and I'm using database evolutions (my db is PostgreSQL). It seems that evolutions create a connection leak.
I'm connecting to two databases (prod and test):
slick.dbs.default.driver = "slick.driver.PostgresDriver$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/et"
slick.dbs.default.db.user = "postgres"
slick.dbs.default.db.password = "postgres"
slick.dbs.test.driver = "slick.driver.PostgresDriver$"
slick.dbs.test.db.driver = "org.postgresql.Driver"
slick.dbs.test.db.url = "jdbc:postgresql://localhost:5432/et_test"
slick.dbs.test.db.user = "postgres"
slick.dbs.test.db.password = "postgres"
This is the connection count before the application is started:
et=# select count(*) from pg_stat_activity;
count
-------
3
(1 row)
This is the connection count after the application is started:
et=# select count(*) from pg_stat_activity;
count
-------
45
(1 row)
It would seem each database allocates 21 connections - 42 in total, fair enough.
This is the connection count after the "apply evolutions" is clicked:
et=# select count(*) from pg_stat_activity;
count
-------
87
(1 row)
It seems evolutions allocate 21 more connections per database, so another 42.
After 10 minutes of application running idle:
et=# select count(*) from pg_stat_activity;
count
-------
87
(1 row)
This looks like an obvious connection leak created by evolutions, doesn't it? Correct me if I'm wrong. Any ideas on how to fix this?

How to split multiple datas from multiple lines in perl

Firstly, I have the data below:
*********************************************************************
TEST CASE
*********************************************************************
test results for the last 1 run(s)
TEST TITLE GROUP PRIO R-STAT R-TIME VERDICT VERDICT-TEXT
------------------------- ---------------------------------------- -------- ---- ------ ------------ -------- --------------------------------------------------
TESTCASE1 TC1 ABC 1 PASS 00:00:09.572 PASS nothing
TESTCASE2 TC2 DEF 2 PASS 00:00:01.650 PASS nothing
----------------------------------------------------------------------------------------------------
NUMBER OF : 2
NUMBER OF TC: 2
*********************************************************************
VERDICT: PASS
*********************************************************************
I would like to perform lines:
TESTCASE1 TC1 ABC 1 PASS 00:00:09.572 PASS nothing
TESTCASE2 TC2 DEF 2 PASS 00:00:01.650 PASS nothing
and split first lines and last lines.
How can I do that?
ADDITIONAL:
Sorry for too late reply, i want to split
*********************************************************************
TEST CASE
*********************************************************************
test results for the last 1 run(s)
TEST TITLE GROUP PRIO R-STAT R-TIME VERDICT VERDICT-TEXT
------------------------- ---------------------------------------- -------- ---- ------ ------------ -------- --------------------------------------------------
just handled two lines
TESTCASE1 TC1 ABC 1 PASS 00:00:09.572 PASS nothing
TESTCASE2 TC2 DEF 2 PASS 00:00:01.650 PASS nothing
i use while loop to check line by line, the problem is it will be looped all of lines whereas i want two lines only.
You can try this to get first and last line from file:
cat filename | grep "^TESTCASE" | sed -n '1p;$p'

Database issue with ZF application

I have a website built on Zend Framework. I want to run the site on my local machine.
I am using wamp server and I created the database for the website.
When loading the site I get the following errors:
( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'devhyper_links'#'localhost' (using password: YES)' in E:\wamp\www\hyper\code\library\Zend\Db\Adapter\Pdo\Abstract.php on line 144
( ! ) PDOException: SQLSTATE[28000] [1045] Access denied for user 'devhyper_links'#'localhost' (using password: YES) in E:\wamp\www\hyper\code\library\Zend\Db\Adapter\Pdo\Abstract.php on line 129
Call Stack
# Time Memory Function Location
1 0.0006 368952 {main}( ) ..\index.php:0
2 0.0422 1681728 Zend_Application->bootstrap( ) ..\index.php:20
3 0.0422 1681760 Zend_Application_Bootstrap_BootstrapAbstract->bootstrap( ) ..\Application.php:355
4 0.0422 1681760 Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap( ) ..\BootstrapAbstract.php:583
5 0.1858 5863392 Zend_Application_Bootstrap_BootstrapAbstract->_executeResource( ) ..\BootstrapAbstract.php:619
6 0.1858 5863520 MKLib_Application_Bootstrap_Bootstrap->_initUtf8( ) ..\BootstrapAbstract.php:666
7 0.1970 6299480 Zend_Db_Adapter_Pdo_Abstract->exec( ) ..\Bootstrap.php:60
8 0.1970 6299480 Zend_Db_Adapter_Abstract->getConnection( ) ..\Abstract.php:263
9 0.1970 6299480 Zend_Db_Adapter_Pdo_Mysql->_connect( ) ..\Abstract.php:315
10 0.1970 6299480 Zend_Db_Adapter_Pdo_Abstract->_connect( ) ..\Mysql.php:96
11 0.1970 6299968 PDO->__construct( ) ..\Abstract.php:129
( ! ) Zend_Db_Adapter_Exception: SQLSTATE[28000] [1045] Access denied for user 'devhyper_links'#'localhost' (using password: YES) in E:\wamp\www\hyper\code\library\Zend\Db\Adapter\Pdo\Abstract.php on line 144
Call Stack
# Time Memory Function Location
1 0.0006 368952 {main}( ) ..\index.php:0
2 0.0422 1681728 Zend_Application->bootstrap( ) ..\index.php:20
3 0.0422 1681760 Zend_Application_Bootstrap_BootstrapAbstract->bootstrap( ) ..\Application.php:355
4 0.0422 1681760 Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap( ) ..\BootstrapAbstract.php:583
5 0.1858 5863392 Zend_Application_Bootstrap_BootstrapAbstract->_executeResource( ) ..\BootstrapAbstract.php:619
6 0.1858 5863520 MKLib_Application_Bootstrap_Bootstrap->_initUtf8( ) ..\BootstrapAbstract.php:666
7 0.1970 6299480 Zend_Db_Adapter_Pdo_Abstract->exec( ) ..\Bootstrap.php:60
8 0.1970 6299480 Zend_Db_Adapter_Abstract->getConnection( ) ..\Abstract.php:263
9 0.1970 6299480 Zend_Db_Adapter_Pdo_Mysql->_connect( ) ..\Abstract.php:315
10 0.1970 6299480 Zend_Db_Adapter_Pdo_Abstract->_connect( ) ..\Mysql.php:96
You have to
Create a database user devhyper_links on your local MySQL database
Grant appropriate privileges for devhyper_links to your local MySQL database
Something like
GRANT ALL ON db_name.* TO "devhyper_links"#"localhost" IDENTIFIED BY "password";
FLUSH PRIVILEGES;
Please note that ALL privileges may be too open. Customise at your discretion.
See http://dev.mysql.com/doc/refman/5.5/en/grant.html#grant-privileges