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

[Feature Request] Dynamic Replacement Text #10

Open
rbwest opened this issue Nov 11, 2021 · 8 comments
Open

[Feature Request] Dynamic Replacement Text #10

rbwest opened this issue Nov 11, 2021 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@rbwest
Copy link

rbwest commented Nov 11, 2021

My org has been using Demo Monkey for a bit now and we've come across a feature we would love to see added to Demo Monkey. We would like the ability to assign dynamic replacement text through some sort of user definable function rather than being limited to static replacement text.

To elaborate, we are trying to replace email addresses with randomized strings that look like hashes. So for example, we could use the following:

!/(.+)@(.+).(.+)/i=XXXXXXXXXXXXX

This would of course turn "ryan.west@pendo.io" or "severin.neumann@altmuehlnet.de" or any other email to "XXXXXXXXXXXXX", but we would like the replacement to be dynamic hash based on the contents of the email. So "ryan.west@pendo.io" could be replaced with something like "32c84e61df0567e09164fbe11511b08b" instead. The way I envision this working is Demo Monkey users would be able to define a function in their script and then use that function as the return value throughout their script:

!function hash(match) { ... }
!/(.+)@(.+).(.+)/i=!hash(match)

@svrnm svrnm added the enhancement New feature or request label Jan 3, 2022
@svrnm
Copy link
Owner

svrnm commented Jan 3, 2022

hi @rbwest, I saw your issue and forgot to comment on it, sorry.

I like that idea, but I have to verify if all of it can be implemented as expected. Especially allowing users to define a function always comes with the question if this is possible without using eval. I'll look into it.

@svrnm
Copy link
Owner

svrnm commented Jan 3, 2022

I added some functionality inspired by that:

  • Variables provide a randomness feature, i.e. ${random.hash()} creates a random(!) hash, there are also more like name, integer, etc, full list at https://chancejs.com/
  • !replace now accepts an additional parameter which is one of many pre-defined functions, i.e. 'replace' and 'hash', based on that there is a short-hand function !hash(word) = hashAlg you can use, e.g. !hash(ryan.west@pendo.io, SHA256)

svrnm added a commit that referenced this issue Jan 3, 2022
@rbwest
Copy link
Author

rbwest commented Jan 5, 2022

Hi @svrnm , thanks for adding this! This sounds like exactly what we were looking for.

@svrnm
Copy link
Owner

svrnm commented Jan 7, 2022

Awesome, I added it into the dev release already: https://bit.ly/demomonkey-dev you can play around with it and give me feedback, I plan to put it into the stable release asap.

@rbwest
Copy link
Author

rbwest commented Jan 21, 2022

@svrnm Got the chance to play around with the dev branch and I'm a bit confused at one piece. I can specify the hash function in a !replace as follows:

!replaceFunction(Benjamin122021@InGen.com, hash) = SHA256 ; Benjamin122021@InGen.com -> 2475ea4c4365941346bac0cc2347e246ed953616a7541f09512826c140fd50af
!hash(Cody092721@Oceanic.com) = SHA256 ; Cody092721@Oceanic.com -> e5d1c5273d48a474647770b1c0992fdc6070ba2115cc6c10333711c21c4a5be6

Or I can use a random variable as follows:

$myHash=${random.hash()}
!/(.+)@(.+)\.(.+)/i = ${myHash} ; ryan.west@pendo.io -> 867d0ff58c48099859191bb6ba219b267c80b178, severin.neumann@altmuehlnet.de -> 867d0ff58c48099859191bb6ba219b267c80b178

But I can't seem to combine the two approaches. What I was expecting was something like the following:

!hash(/(.+)@(.+)\.(.+)/i) = SHA256 ; ryan.west@pendo.io -> 2475ea4c4365941346bac0cc2347e246ed953616a7541f09512826c140fd50af, severin.neumann@altmuehlnet.de -> e5d1c5273d48a474647770b1c0992fdc6070ba2115cc6c10333711c21c4a5be6

I would like to be able to provide a regex pattern and replace any match with a unique hash based on the contents of the match. Am I making a syntax error here using the regex + replace function or is this not possible?

@svrnm
Copy link
Owner

svrnm commented Jan 24, 2022

Ok, so your goal is to have a way to match any email address on a website and replace it with its hash?

As of now you can not access groups matched by a regular expression or use regular expressions freely as replacement pattern. That would definitely be a great improvement, but I have to see how difficult it is to get this working (the solutions I created where low-hanging fruits)

@rbwest
Copy link
Author

rbwest commented Jan 24, 2022

Got it. Yes, ideally I would like to be able to use regex match patterns to replace any match on a page with one of the functions you've added. Sorry if that wasn't initially clear. Still really appreciate the additions. Thanks!

@svrnm
Copy link
Owner

svrnm commented Jan 28, 2022

Ok, let's leave this open for now then.

@svrnm svrnm added the help wanted Extra attention is needed label Sep 28, 2022
@svrnm svrnm changed the title Feature Request: Dynamic Replacement Text [Feature Request] Dynamic Replacement Text Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants