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

Only obfuscate if the instance has the field in question. #28

Merged
merged 1 commit into from
Dec 16, 2015

Conversation

craigmcnamara
Copy link
Contributor

No description provided.

@nettofarah
Copy link
Contributor

Hello, @craigmcnamara.
Thank you for submitting your PR.

Have you run into a bug because of this?
Also, can you add a test for this?

@craigmcnamara
Copy link
Contributor Author

The code there is playing fast and loose with Object#send. It should check that an attribute exists on an instance before applying the obfuscated value to the instance. My guess is that the || '' was someones attempt to make a test pass with some kind of default value.

I had a fairly involved explore chain, and with the exception of this bug Polo works great.

@craigmcnamara
Copy link
Contributor Author

It seems that the bug is only on the proc form of obfuscate.

@@ -88,6 +88,20 @@

expect(inserts).to eq [ %q{INSERT INTO "chefs" ("id", "name", "email") VALUES (1, 'Netto', 'changeme')} ]
end

it 'only scrables instances with the obfuscate field defined' do
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you mean scramble here?

@nettofarah
Copy link
Contributor

I think I'm starting to understand this problem a little better now.
Let me try and explain what I think is going on:

We always check that the fields actually exist before we try to obfuscate it.
You can see the part that performs the check here:
https://github.com/IFTTT/polo/blob/master/lib/polo/translator.rb#L38

As you can see, we never actually try to apply a transformation on fields that don't exist. We would apply the transformation if the field is nil though.

With this mind we have two options:

a) Check if the field we're trying to obfuscate is nil and then transform it.
b) Just blindly try to run the block and assume that the lambda function would perform the validation itself.

I tend to like b a little better to be honest. Mostly because checking for nil is just one kind of validation.
The whole idea with passing in a lambda as a custom obfuscation strategy is that Polo doesn't have to be aware of how your data looks like.

I don't want to prolong the discussion for too long though, so I'm ok with adding the if check.
But I would love to know if just adding a nil check to your lambda would fix your problem.

Thank you!

@craigmcnamara
Copy link
Contributor Author

A little more detail, here https://github.com/IFTTT/polo/blob/master/lib/polo/translator.rb#L38 the intersection of fields to scrub is only checked if there are any fields to scrub. The inner loop operates on the full original set of fields passed in. I tried rewriting it to get the fields from the intersection method, but more things in unrelated specs failed.

If you change the field check back to the original and run the new spec it fails with

  1) Polo Advanced Options obfuscate: [fields] only scrambles instances with the obfuscate field defined
     Failure/Error: instance.send("#{field}=", new_field_value(field, strategy, value))

     NoMethodError:
       undefined method `title=' for #<AR::Chef:0x007fd733702f58>

@nettofarah
Copy link
Contributor

oh, yeah. That makes total sense.
You're correct @craigmcnamara.

I'll go ahead and merge this in.
We can deal with the optimization (using only intersected fields) when we work on: #29.

Thanks for catching this.

@nettofarah
Copy link
Contributor

@craigmcnamara: Would you mind taking some time and responding to this?
#19

nettofarah added a commit that referenced this pull request Dec 16, 2015
Only obfuscate if the instance has the field in question.
@nettofarah nettofarah merged commit 2e09dd0 into IFTTT:master Dec 16, 2015
@craigmcnamara
Copy link
Contributor Author

I'd be happy to, thanks for merging the pull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants