Skip to content

Coverage for graphite.whitelist#1572

Merged
cbowman0 merged 2 commits into
graphite-project:masterfrom
cbowman0:coverage_whitelist
Jul 5, 2016
Merged

Coverage for graphite.whitelist#1572
cbowman0 merged 2 commits into
graphite-project:masterfrom
cbowman0:coverage_whitelist

Conversation

@cbowman0

@cbowman0 cbowman0 commented Jul 5, 2016

Copy link
Copy Markdown
Member

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

codecov-io commented Jul 5, 2016

Copy link
Copy Markdown

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

gwaldo commented Jul 5, 2016

Copy link
Copy Markdown
Member

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

cbowman0 commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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

cbowman0 commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

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

@obfuscurity

Copy link
Copy Markdown
Member

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

👍

@cbowman0

cbowman0 commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member

@cbowman0 Yeah, good idea.

@cbowman0

cbowman0 commented Jul 5, 2016

Copy link
Copy Markdown
Member Author

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