Repository: Netflix/lemur

Issue:
Getting error while creating authority with lemur_cryptography plugin
I added a comment to the offending commit code here: https://github.com/Netflix/lemur/commit/d53f64890cb656765bc1c18f4b8442ee3a592f47

Upon creating an authority certificate with the lemur_cryptography plugin here, I get an error because unit is None and cannot be compared to 90. Is it reasonable to make an validation assumption that unit should be 0 if undefined?

I haven't quite been able to trace how this validation function is called, so I'm not entirely clear on what it is doing or why it's involved in the creation of an authority certificate, but not in the creation of a certificate signed by an authority.


Here's the error I get upon submitting an authority for creation.
```
2017-03-07 01:44:41,352 ERROR: Exception on /api/1/authorities [POST] [in /home/lemur/venv/lib/python3.4/site-packages/flask/app.py:1560]
Traceback (most recent call last):
  File "/home/lemur/venv/lib/python3.4/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/lemur/venv/lib/python3.4/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/lemur/venv/lib/python3.4/site-packages/flask_restful/__init__.py", line 477, in wrapper
    resp = resource(*args, **kwargs)
  File "/home/lemur/venv/lib/python3.4/site-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/home/lemur/venv/lib/python3.4/site-packages/flask_restful/__init__.py", line 587, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/home/lemur/app/lemur/auth/service.py", line 110, in decorated_function
    return f(*args, **kwargs)
  File "/home/lemur/app/lemur/common/schema.py", line 150, in decorated_function
    data, errors = input_schema.load(request_data)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/schema.py", line 578, in load
    result, errors = self._do_load(data, many, partial=partial, postprocess=True)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/schema.py", line 658, in _do_load
    index_errors=self.opts.index_errors,
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/marshalling.py", line 295, in deserialize
    index=(index if index_errors else None)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/marshalling.py", line 68, in call_and_store
    value = getter_func(data)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/marshalling.py", line 288, in <lambda>
    data
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/fields.py", line 265, in deserialize
    output = self._deserialize(value, attr, data)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/fields.py", line 465, in _deserialize
    data, errors = self.schema.load(value)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/schema.py", line 578, in load
    result, errors = self._do_load(data, many, partial=partial, postprocess=True)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/schema.py", line 658, in _do_load
    index_errors=self.opts.index_errors,
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/marshalling.py", line 295, in deserialize
    index=(index if index_errors else None)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/marshalling.py", line 68, in call_and_store
    value = getter_func(data)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/marshalling.py", line 288, in <lambda>
    data
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/fields.py", line 266, in deserialize
    self._validate(output)
  File "/home/lemur/venv/lib/python3.4/site-packages/marshmallow/fields.py", line 196, in _validate
    r = validator(value)
  File "/home/lemur/app/lemur/schemas.py", line 44, in validate_options
    if unit > 90:
TypeError: unorderable types: NoneType() > int()
```


Discussion:
You're right, I hadn't considered the fact that plugin validation happens in quite a bit more places than just notifications. Not sure why none of the other tests caught this, I will create a PR and add a few more tests to cover it. 

Resolving patch:
diff --git a/lemur/schemas.py b/lemur/schemas.py
--- a/lemur/schemas.py
+++ b/lemur/schemas.py
@@ -35,6 +35,9 @@ def validate_options(options):
     interval = get_plugin_option('interval', options)
     unit = get_plugin_option('unit', options)
 
+    if not interval and not unit:
+        return
+
     if interval == 'month':
         unit *= 30
 


Test patch:
diff --git a/lemur/tests/test_authorities.py b/lemur/tests/test_authorities.py
--- a/lemur/tests/test_authorities.py
+++ b/lemur/tests/test_authorities.py
@@ -13,7 +13,7 @@ def test_authority_input_schema(client, role):
         'owner': 'jim@example.com',
         'description': 'An example authority.',
         'commonName': 'AnExampleAuthority',
-        'pluginName': {'slug': 'verisign-issuer'},
+        'plugin': {'slug': 'verisign-issuer', 'plugin_options': [{'name': 'test', 'value': 'blah'}]},
         'type': 'root',
         'signingAlgorithm': 'sha256WithRSA',
         'keyType': 'RSA2048',