Ejemplo n.º 1
0
    def test_send_apdu_return_errors(self, tag):
        with pytest.raises(nfc.tag.tt4.Type4TagCommandError) as excinfo:
            tag.clf.exchange.side_effect = [HEX('02 90')]
            tag.send_apdu(1, 2, 3, 4, b'56', 1)
        assert excinfo.value.errno == -2

        with pytest.raises(nfc.tag.tt4.Type4TagCommandError) as excinfo:
            tag.clf.exchange.side_effect = [HEX('03 9192')]
            tag.send_apdu(1, 2, 3, 4, b'56', 1)
        assert excinfo.value.errno == 0x9192
Ejemplo n.º 2
0
    def test_send_apdu_extended_length(self, tag):
        tag._extended_length_support = True

        with pytest.raises(ValueError) as excinfo:
            tag.send_apdu(0, 0, 0, 0, 65536 * b'\0')
        assert str(excinfo.value) == "invalid command data length"

        with pytest.raises(ValueError) as excinfo:
            tag.send_apdu(0, 0, 0, 0, mrl=65537)
        assert str(excinfo.value) == "invalid max response length"

        tag.clf.exchange.side_effect = [HEX('02 A9 9000')]
        assert tag.send_apdu(1, 2, 3, 4, b'56') == b'\xA9'
        tag.clf.exchange.assert_called_once_with(
            HEX('02 01020304 000002 3536'), 0.08095339233038348)

        tag.clf.exchange.reset_mock()
        tag.clf.exchange.side_effect = [HEX('03 9A 9000')]
        assert tag.send_apdu(1, 2, 3, 4, mrl=1) == b'\x9A'
        tag.clf.exchange.assert_called_once_with(HEX('03 01020304 000001'),
                                                 0.08095339233038348)

        tag.clf.exchange.reset_mock()
        tag.clf.exchange.side_effect = [HEX('02 A99A 9000')]
        assert tag.send_apdu(1, 2, 3, 4, b'56', 1) == b'\xA9\x9A'
        tag.clf.exchange.assert_called_once_with(
            HEX('02 01020304 000002 3536 0001'), 0.08095339233038348)