How do I filter csv email attachments via RouteonAttributes by attachment name? - apache-nifi

I want to filter csv email attachments I extract from gmail via ConsumeIMAP by their file name. I am having trouble with what syntax to use when I am configuring RouteonAttributes processor.
I was able to extract the csv file from gmail by configuring RouteonAttributes to
fetchcsv | ${filename:contains('.csv')}
but when I try to specify the filename
"${filename:contains('Threat_-_SQL_Injection_-_Rule*')}"
it always routes to unmatched. The file name is Threat_-_SQL_Injection_-_Rule-2019-06-29. The date following "Rule-" will be constantly changing as well depending on the date it was sent. I would also need to write a route to property name for the file "Threat_-_Vulnerability_Scanner_-_Rule-2019-06-28". Any help with the configuration would be appreciated.

You can use startsWith instead of contains as -
${filename:startsWith('Threat_-_SQL_Injection_-_Rule')}
This will match for any file that starts with "Threat_-_SQL_Injection_-_Rule" string. This means, date part on your file can vary.You can refer to Apache Nifi Expression Language guide for more details

A simpler solution would be to use
"${filename:contains('Threat_-_SQL_Injection_-_Rule*')}"
like you did earlier but drop the "*"
"${filename:contains('Threat_-_SQL_Injection_-_Rule')}"

Related

Jmeter can get parameters?

My question is - if I run a test via Jmeter, for example , if it's a site which enables you to book a flight, and you choose your source and destination when you record it.
Is it possible to pass different values to the destination field? I mean, maybe a txt file with some destinations and pass it to the Jmeter test and then, you will have some tests which each of them is running with a different destination?
If yes, how can I do it?
It's not necessary that it will be a txt file. Just a way to pass different values to one parameter.
Important: I'm using blazemeter plugin for chrome.
Thanks a lot,
appreciated.
You can use CSV Data Set Config. It is very easy to use for parameterizing variables in the test plan.
Check this article on blazemeter to understand the CSV Data Set Config quickly.
Depending on what you're trying to achieve you can go for:
HTML Link Parser. See Poll Example which shows how you can use it for selecting random values from inputs
You can extract all the possible values from the previous response using a Post-Processor, most probably CSS Selector Extractor and configure each thread to use its own (or random) value from the input
And last, but not the least, you can use an external data source like .txt or .csv file and utilize __StringFromFile() function or CSV Data Set Config so each thread (virtual user) would read the next value from file instead of using recorded hard-coded values.

How to hit parameterized url in Apache Jmeter?

This is my test URL " http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id={Email} "
I want to hit the url 1500 times per second , and want to change the "{Email}" with real value in each iteration.
How it's possible please give me a step by step guide.
Considering that you need to pass the emails from the external file, the most efficient way that we are using in software testing companies is to pass the variable from .csv or .txt files using 'CSV Data Set Config' element of the JMeter.
Please find the steps that you need to follow:
Add a 'CSV Data Set Config' element from 'Config Element' by right-clicking the thread group
Set Filename field with complete path to your .csv or .txt file that contains your emails
Set Variable field as 'Email' [This variable name should be same as you set in your url request]
Ignore first line to False
Set other fields as per your requirement
Now add HTTP Sampler in your Thread Group and set the Protocol, Server Name, Method & Path as instructed in the screenshot:
Create .csv or .txt file and add all emails separated by new line:
Hope this answer is useful.
You can use the CSV Data Set Config. Put all your email credentials in the CSV file and make sure you have put this CSV file in your JMeter /bin directory.
Add a CSV dataset config in your test plan. Your CSV dataset config should be like:
Now in your thread group, define the number of threads you want to execute and then in your sampler put the path as follows:
http://appr.seconddemo.org/hitssurveys/survey?uid=113&offerid=311&subid=subvalues&offr_id=${Email}
Depending on where do your emails live there are following options:
If they are in a text file, each email on a new line you can use __StringFromFile() function like:
If they are in a database you can use JDBC PreProcessor to fetch the data from the database table column and put your request under ForEach Controller
If you need to provide just some random characters you can use __RandomString() function.
More information: JMeter Parameterization - The Complete Guide

Could you pls let me know how do i pass variable if the URL is dynamic based on your search value in jmeter?

When is search for an item by giving its id the url i get is http://aa.bb.com/bikes/2 or http://aa.bb.com/bikes/3,
the value after bikes is dynamic based on my search results and corresponding page is displayed. How do i parameterize this in Jmeter?
I am using HTTP request sampler.
I added a csv config file, gave different ids and added these values in the parameter part and used the parameter variable in the URL path. But it is not working.
EX: the url path i gave as /aa.bb.com/bikes/${id} but its not working.
You can add 'debug sampler' to narrow down the root cause.
i figured out the way to do this.
I just mentioned the possible id values in a csv file.
Used the variable name in the url.
Ex: I created a idValues.csv file and used this file in CSV data set config.
Gave the variable name as value.
now in the HttpSampler in the path i mentioned as http://aa.bb.com/bikes/${value} and it worked.
Thank you.

JMeter using a variable as input for a response assertion pattern

I have a test plan in JMeter that has a Response Assertion where I'd like to use a variable that comes from a CSV Data Set Config. So my Pattern looks like:
${assert1}
Which corresponds (at least in my thoughts) to what comes from the file used in CSV Data Set Config, but it doesn't work. I have seen multiple suggestions to use a Regular Expression Extractor, but the examples I saw refer to something they're trying to capture from a page. In my case I am using an external csv file.
My question: how can I use a variable as input for a Response Assertion pattern ?
I have successfully used a CSV Data Set Config as a source of string that I use in a url parameter, and then use a Response Assertion to seek out that parameter in the response.
Variable name: P.
URL: /product/${P}.
The response assertion Parterns to Test: ${P}.
I wonder if it is not necessary to use the CSV data variable in the request in order for it to be available in the response assertion?
If my understanding is right,
here your problem:
You want to use the value from your CSV as part of URL and that too via variable.
Solution:
Configure your CSV Data Set Config like this:
Filename: url csv path
variable name : assert1
Delimiter : , (if your CSV comma separated)
leave remaining unchanged
That's it you can use the variable assert1 anywhere: ${assert1}.

Spring MVC Upload File - How is Content Type determine?

I'm using Spring 3 ability to upload a file. I would like to know the best way to validate that a file is of a certain type, specifically a csv file. I'm rather sure that checking the extension is useless and currently I am checking the content type of the file that is uploaded. I just ensure that it is of type "text/csv". And just to clarify this is a file uploaded by the client meaning I have no control of its origins.
I'm curious how Spring/the browser determines what the content type is? Is this the best/safest way to determine what kind of file has been uploaded? Can I ever be 100% certain?
UPDATE: Again I'm not wondering how to determine what the content type is of a file but how the content type gets determined. How does spring/the browser know that the content type is a "text/csv" based on the file uploaded?
You can use
org.springframework.web.multipart.commons.CommonsMultipartFile object.
it hasgetContentType(); method.
Look at the following example http://www.ioncannon.net/programming/975/spring-3-file-upload-example/
you can just add the simple test on CommonsMultipartFile object and redirect to error page if it the content type is incorrect.
So you can also count the number of commas in the file per line.There should normally be the same amount of commas on each line of the file for it to be a valid CSV file.
Why you don't just take the file name in you validator and split it, the file type is fileName.split("\.")[filename.length()-1] string
Ok, in this case i suggest you to use the Csvreader java library. You just have to check your csvreader object and that's all.
As far as I'm aware the getContentType(String) method gets its value from whatever the user agent tells it - so you're right to be wary as this can easily be spoofed.
For binary files you could check the magic number or use a library, such as mime-util or jMimeMagic. There's also Files.probeContentType(String) since Java 7 but it only works with files on disk and bugs have been reported on some OSes.

Resources