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

Coverage for graphite.whitelist #1572

Merged
merged 2 commits into from
Jul 5, 2016

Conversation

cbowman0
Copy link
Member

@cbowman0 cbowman0 commented Jul 5, 2016

I had this mostly together, so in light of issue #1569 and pull request #1570, I submit this for test cases before the wording changes.

  • Fix graphite.whitelist.load_whitelist()
  • Add test cases for show, add and remove

Of note, the load_whitelist() function was not working before this change. If the preferred method is to read the blob in and use unpickle.loads(), then that can be done.

@codecov-io
Copy link

codecov-io commented Jul 5, 2016

Current coverage is 56.73%

Merging #1572 into master will increase coverage by 0.47%

@@             master      #1572   diff @@
==========================================
  Files            52         52          
  Lines          5781       5780     -1   
  Methods           0          0          
  Messages          0          0          
  Branches       1111       1111          
==========================================
+ Hits           3252       3279    +27   
+ Misses         2328       2300    -28   
  Partials        201        201          

Powered by Codecov. Last updated by d0295a2...cddfe40

@gwaldo
Copy link
Member

gwaldo commented Jul 5, 2016

Thank you for this, @cbowman0

* Fix graphite.whitelist.load_whitelist()
* Add test cases for show, add and remove
* Test save_whitelist failure scenarios
@cbowman0 cbowman0 force-pushed the coverage_whitelist branch from 3a00d67 to cddfe40 Compare July 5, 2016 14:20
@cbowman0
Copy link
Member Author

cbowman0 commented Jul 5, 2016

I adjusted the testing to be deterministic. I would like someone else from @graphite-project/committers to confirm the changes to load_whitelist() is ok.

Once that is merged, I will help @gwaldo with adjusting the test cases to work with his wording changes, if required.

@obfuscurity
Copy link
Member

@cbowman0 why the change from unpickle to pickle? The latter is intended as a safe alternative to the insecure pickle.

# This whole song & dance is due to pickle being insecure
# The SafeUnpickler classes were largely derived from
# http://nadiana.com/python-pickle-insecure
# This code also lives in carbon.util
if USING_CPICKLE:
class SafeUnpickler(object):
PICKLE_SAFE = {
'copy_reg': set(['_reconstructor']),
'__builtin__': set(['object', 'list']),
'collections': set(['deque']),
'graphite.render.datalib': set(['TimeSeries']),
'graphite.intervals': set(['Interval', 'IntervalSet']),
}
@classmethod
def find_class(cls, module, name):
if not module in cls.PICKLE_SAFE:
raise pickle.UnpicklingError('Attempting to unpickle unsafe module %s' % module)
__import__(module)
mod = sys.modules[module]
if not name in cls.PICKLE_SAFE[module]:
raise pickle.UnpicklingError('Attempting to unpickle unsafe class %s' % name)
return getattr(mod, name)
@classmethod
def loads(cls, pickle_string):
pickle_obj = pickle.Unpickler(StringIO(pickle_string))
pickle_obj.find_global = cls.find_class
return pickle_obj.load()
else:
class SafeUnpickler(pickle.Unpickler):
PICKLE_SAFE = {
'copy_reg': set(['_reconstructor']),
'__builtin__': set(['object', 'list']),
'collections': set(['deque']),
'graphite.render.datalib': set(['TimeSeries']),
'graphite.intervals': set(['Interval', 'IntervalSet']),
}
def find_class(self, module, name):
if not module in self.PICKLE_SAFE:
raise pickle.UnpicklingError('Attempting to unpickle unsafe module %s' % module)
__import__(module)
mod = sys.modules[module]
if not name in self.PICKLE_SAFE[module]:
raise pickle.UnpicklingError('Attempting to unpickle unsafe class %s' % name)
return getattr(mod, name)
@classmethod
def loads(cls, pickle_string):
return cls(StringIO(pickle_string)).load()
unpickle = SafeUnpickler

@cbowman0
Copy link
Member Author

cbowman0 commented Jul 5, 2016

@obfuscurity Because it currently doesn't work. Calls to load_whitelist() error with:
AttributeError: type object 'SafeUnpickler' has no attribute 'load'

@obfuscurity
Copy link
Member

Ah right, we're loading from a file, not a string. Looks like a typo from c198e58. Yeah, this change looks good.

👍

@cbowman0
Copy link
Member Author

cbowman0 commented Jul 5, 2016

Alternatively, we can do:

   buffer = open(settings.WHITELIST_FILE, 'rb').read()
   whitelist = unpickle.loads(buffer)

and add set to the PICKLE_SAFE set. I can do that quickly, if that's preferred.

@obfuscurity
Copy link
Member

@cbowman0 Yeah, good idea.

@cbowman0
Copy link
Member Author

cbowman0 commented Jul 5, 2016

Done. Once automated checks go green again, I'll merge it.

@cbowman0 cbowman0 merged commit 5f5ac58 into graphite-project:master Jul 5, 2016
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.

4 participants