Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 17, 2018
Merged

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

merged 3 commits into from
Jul 17, 2018

Conversation

tisba
Copy link
Collaborator

@tisba tisba commented Jun 27, 2018

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
Copy link
Collaborator Author

tisba commented Jun 27, 2018

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
Copy link
Collaborator Author

tisba commented Jul 6, 2018

ping @nniclausse

@nniclausse
Copy link
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
Copy link
Collaborator Author

tisba commented Jul 6, 2018

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
Copy link
Collaborator Author

tisba commented Jul 6, 2018

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
Copy link
Collaborator Author

tisba commented Jul 16, 2018

Could you take another look, @nniclausse?

@@ -503,7 +503,13 @@ parse(_Element = #xmlElement{name='if', attributes=Attrs,content=Content},
NewConf = lists:foldl(fun parse/2, Conf#config{curid=Id+1}, Content),
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
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
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