Skip to content

Run <if> value by ts_search:subst/2#311

Merged
tisba merged 3 commits into
developfrom
make-if-value-dynamic
Jul 17, 2018
Merged

Run <if> value by ts_search:subst/2#311
tisba merged 3 commits into
developfrom
make-if-value-dynamic

Conversation

@tisba

@tisba tisba commented Jun 27, 2018

Copy link
Copy Markdown
Collaborator

This PR will run the value of <if> by ts_search:subst/2 to make it work with variables as well.

For example, if you need to compare a variable against another variable that you've extracted from a previous request, you can now do that.

Example:

<request>
  <dyn_variable name="extracted_token" re="X-CSRF-Token: (https?://.*)&#13;"/>
  <http url="http://example.com/login" method="GET" version="1.1">
  </http>
</request>

<!-- make some more request -->

<request>
  <dyn_variable name="current_token" re="X-CSRF-Token: (https?://.*)&#13;"/>
  <http url="http://example.com/basket" method="GET" version="1.1">
  </http>
</request>


<!-- abort current client in case tokens do not match and you cannot proceed -->

<if var="current_token" neq="%%_extracted_token%%">
  <abort type="session"/>
</if>

Fixes #168

@tisba tisba changed the title Run if value by ts_search:subst/2 Run <if> value by ts_search:subst/2 Jun 27, 2018
@tisba tisba requested a review from nniclausse June 27, 2018 06:46
@tisba

tisba commented Jun 27, 2018

Copy link
Copy Markdown
Collaborator Author

I first thought about adding a flag to enable the substitution (like with <request>). But then I thought that this is quite counter intuitive.

Another option would be to a new/alternative attribute beside the literal "value".

The current solution feels the most natural too me though.

What do you think, @nniclausse?

@tisba

tisba commented Jul 6, 2018

Copy link
Copy Markdown
Collaborator Author

ping @nniclausse

@nniclausse

Copy link
Copy Markdown
Contributor

maybe we can add a subst flag during the xml parsing, if we detect the %%xxx%% pattern ?

if we don't do that, every use of an 'if' will call ts_search:subst even if we don't need substitutions.

@tisba

tisba commented Jul 6, 2018

Copy link
Copy Markdown
Collaborator Author

I like that idea! I was first thinking about subst="true" but since we should be able to detect that automatically that's probably way better.

I'll try to give this a shot.

@tisba

tisba commented Jul 6, 2018

Copy link
Copy Markdown
Collaborator Author

Can you take another look, @nniclausse? I'm not sure if this approach is sufficient. I'm simply peeking into the value and if I see %% I enable substitution.

@tisba

tisba commented Jul 16, 2018

Copy link
Copy Markdown
Collaborator Author

Could you take another look, @nniclausse?

Comment thread src/tsung_controller/ts_config.erl Outdated
NewId = NewConf#config.curid,
?LOGF("endif in session ~p as id ~p",[CurS#session.id,NewId+1],?INFO),
InitialAction = {ctrl_struct, {if_start, Rel, VarName, list_to_binary(Value) , NewId+1}},
SubstitutionFlag = case string:str(Value, "%%") of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use re:run(Value, "%%.+%%") instead if think

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I thought string:str because that's recommended for performance reasons, but since we are only parsing the configuration, that should not be a issue to begin with.

I'll change this.

Do you have anything else on the new approach?

@tisba tisba merged commit a64c4a6 into develop Jul 17, 2018
@tisba tisba deleted the make-if-value-dynamic branch July 17, 2018 13:52
@nniclausse nniclausse added this to the 1.8.0 milestone Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How can i use dynamic vars with the attribute value of eq?

2 participants