alexa / alexa-skills-kit-sdk-for-python

The Alexa Skills Kit SDK for Python helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-python/overview.html
Apache License 2.0
812 stars 206 forks source link

Fix TimestampVerifier delta check #118

Closed timothyaaron closed 5 years ago

timothyaaron commented 5 years ago

Description

Requests should be handled if they fall +/- within a preset tolerance. Requests with (what should have been) a negative delta within the preset tolerance were raising an exception.

timedelta.seconds is always a positive integer. For x - y, if x is smaller (earlier) than y, you get "the number of seconds in a day minus the delta" instead of "a negative delta".

from datetime import datetime, timedelta
first = datetime.now()
second = datetime.now()
print((first - second).seconds)  # ~ 86397
print((first - second.total_seconds())  # ~ -2.497155

What was intended was most likely timedelta.total_seconds(), which returns a true (negative-possible float) delta.

Motivation and Context

If the server's datetime is fractionally faster than the requests datetime, it'll raise a ValidationException. Unlikely, but possible (happened to me during testing for the first time last week).

Testing

See above code, and new test.

Screenshots (if appropriate)

Types of changes

Checklist

License

timothyaaron commented 5 years ago

I'm not sure how these errors could be related to my changes. Is there anything else you guys need from me to get this merged, or are we just waiting for another reviewer?