Skip to content

Commit

Permalink
test user presence behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
conorpp committed Aug 15, 2019
1 parent 8bcc004 commit af92fba
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/standard/fido2/user_presence/test_user_presence.py
@@ -0,0 +1,42 @@
import sys
import time

import pytest
from fido2.ctap import CtapError
from fido2.utils import hmac_sha256, sha256
from tests.utils import *


@pytest.mark.skipif(
"--sim" in sys.argv, reason="Simulation doesn't care about user presence"
)
class TestUserPresence(object):
@pytest.mark.run(order=1)
def test_user_presence_instructions(self, MCRes, GARes):
print()
print()
print("Starting User Presence (UP) tests.")
time.sleep(1)
print()
print(
"Follow instructions. You will have to give UP or not give UP to pass the tests."
)
time.sleep(2)

def test_user_presence(self, device, GARes):
print("ACTIVATE UP ONCE")
device.sendGA(*FidoRequest(GARes).toGA())

def test_no_user_presence(self, device, MCRes, GARes):
print("DO NOT ACTIVATE UP")
with pytest.raises(CtapError) as e:
device.sendGA(*FidoRequest(GARes, timeout=2).toGA())
assert e.value.code == CtapError.ERR.INVALID_COMMAND

def test_user_presence_permits_only_one_request(self, device, MCRes, GARes):
print("ACTIVATE UP ONCE")
device.sendGA(*FidoRequest(GARes).toGA())

with pytest.raises(CtapError) as e:
device.sendGA(*FidoRequest(GARes, timeout=1).toGA())
assert e.value.code == CtapError.ERR.INVALID_COMMAND
3 changes: 3 additions & 0 deletions tests/utils.py
Expand Up @@ -98,6 +98,7 @@ def __init__(self, request=None, **kwargs):
"exclude_list",
"extensions",
"pin_auth",
"timeout",
):
self.save_attr(i, kwargs.get(i, Empty), request)

Expand Down Expand Up @@ -128,6 +129,7 @@ def toGA(self,):
self.options,
self.pin_auth,
self.pin_protocol,
self.timeout,
]

def toMC(self,):
Expand All @@ -141,6 +143,7 @@ def toMC(self,):
self.options,
self.pin_auth,
self.pin_protocol,
self.timeout,
]

return args + self.get_optional_args()

0 comments on commit af92fba

Please sign in to comment.