svrnm / DemoMonkey

Custom Demo Every Demo
http://bit.ly/demomonkey
Apache License 2.0
22 stars 8 forks source link

Feature Request: Dynamic Replacement Text #10

Open rbwest opened 2 years ago

rbwest commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I added some functionality inspired by that:

rbwest commented 2 years ago

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

svrnm commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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