Exemplo n.º 1
0
def test_signing_time_equals_current_time():
    # Given an timezone-aware signing time
    signing_time = datetime(2014, 10, 27, 20, 51, 43, tzinfo=utc)

    # and a current time that exactly matches the signing time,
    current_time = signing_time

    # and a time-delta of zero,
    threshold = timedelta(0)

    # when we attempt to validate the signing time against the threshold,
    valid = applepay_utils.valid_signing_time(signing_time, current_time,
                                              threshold)

    # then the token should be considered valid.
    assert valid is True
Exemplo n.º 2
0
def test_expired_signing_time():
    # Given an timezone-aware signing time
    signing_time = datetime(2014, 10, 27, 20, 51, 43, tzinfo=utc)

    # and a current time well past the signing time,
    current_time = signing_time + timedelta(days=100)

    # and a time-delta threshold of only one day,
    threshold = timedelta(days=1)

    # when we attempt to validate the signing time against the threshold,
    valid = applepay_utils.valid_signing_time(signing_time, current_time,
                                              threshold)

    # then the token should be considered invalid.
    assert valid is False
Exemplo n.º 3
0
def test_future_signing_time():
    # Given an timezone-aware signing time
    signing_time = datetime(2014, 10, 27, 20, 51, 43, tzinfo=utc)

    # and a current time which is well before the signing time,
    current_time = signing_time - timedelta(weeks=10)

    # and a time-delta threshold of five weeks,
    threshold = timedelta(weeks=5)

    # when we attempt to validate the signing time against the threshold,
    valid = applepay_utils.valid_signing_time(signing_time, current_time,
                                              threshold)

    # then the token should be considered invalid.
    assert valid is False
Exemplo n.º 4
0
def test_valid_signing_time():
    # Given an timezone-aware signing time
    signing_time = datetime(2014, 10, 27, 20, 51, 43, tzinfo=utc)

    # and a current time exactly one hour past the signing time,
    current_time = signing_time + timedelta(hours=1)

    # and a time-delta threshold of one hour,
    threshold = timedelta(hours=1)

    # when we attempt to validate the signing time against the threshold,
    valid = applepay_utils.valid_signing_time(signing_time, current_time,
                                              threshold)

    # then the token shosuld be considered valid.
    assert valid is True
Exemplo n.º 5
0
def test_invalid_signing_time_data_is_logged(caplog):
    # Given: an invalid signing time
    signing_time = datetime(2014, 10, 27, 20, 51, 43, tzinfo=utc)
    current_time = signing_time + timedelta(hours=5)
    threshold = timedelta(hours=1)

    # When we attempt to validate the signing time against the threshold,
    with caplog.atLevel(logging.DEBUG):
        valid = applepay_utils.valid_signing_time(signing_time, current_time,
                                                  threshold)

    # Then the signing time is not valid
    assert valid is False

    # Then a new debug log is captured
    # filter on DEBUG log records only
    records = filter(lambda log_record: log_record.levelno == logging.DEBUG,
                     caplog.records())
    assert len(records) == 1
    assert records[0].name == 'applepay.utils'
    assert records[
        0].message == 'Signing time is invalid. Signing time: 2014-10-27 20:51:43 UTC, Current time: 2014-10-28 01:51:43 UTC, Threshold: 1:00:00.'