From 482df53e4ce9e06123eefc0543f29a6a2df72e00 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sat, 10 Jan 2015 12:19:45 +0100 Subject: [PATCH 1/2] Extend CardGenerator unittests There are now tests for most currently implemented card types. Tests for new card types can easily be added by inheriting from the basic test class. The ePass card type is currently missing from the tests because the CardGenerator for this class currently only works with user interaction. --- .../tests/CardGenerator_test.py | 58 ++++++++++++++----- .../tests/Example_Dataset_Mueller_Gertrud.txt | 1 + 2 files changed, 46 insertions(+), 13 deletions(-) create mode 120000 virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py index ecb8be2..851ebfe 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py @@ -21,28 +21,31 @@ import anydbm import os import tempfile import unittest + from virtualsmartcard.CardGenerator import CardGenerator -class TestNPACardGenerator(unittest.TestCase): +class ISO7816GeneratorTest(unittest.TestCase): + + card_type = 'iso7816' def setUp(self): self.filename = tempfile.mktemp() - self.nPA_generator = CardGenerator('nPA') - self.nPA_generator.password = "TestPassword" + self.card_generator = CardGenerator(self.card_type) + self.card_generator.password = "TestPassword" - def test_nPA_creation(self): - self.nPA_generator.generateCard() - self.nPA_generator.saveCard(self.filename) - mf, sam = self.nPA_generator.getCard() + def test_card_creation(self): + self.card_generator.generateCard() + self.card_generator.saveCard(self.filename) + mf, sam = self.card_generator.getCard() self.assertIsNotNone(mf) self.assertIsNotNone(sam) os.unlink(self.filename) - def test_load_nPA_from_file_nPA_from_file(self): - self.nPA_generator.generateCard() - self.nPA_generator.saveCard(self.filename) - local_generator= CardGenerator('nPA') - local_generator.password = self.nPA_generator.password + def test_load_card_from_file(self): + self.card_generator.generateCard() + self.card_generator.saveCard(self.filename) + local_generator= CardGenerator(self.card_type) + local_generator.password = self.card_generator.password local_generator.loadCard(self.filename) mf, sam = local_generator.getCard() self.assertIsNotNone(mf) @@ -51,7 +54,36 @@ class TestNPACardGenerator(unittest.TestCase): def test_load_nonexistent_file(self): with self.assertRaises(anydbm.error): - self.nPA_generator.loadCard(self.filename) + self.card_generator.loadCard(self.filename) + + def test_get_and_set_card(self): + self.card_generator.generateCard() + mf, sam = self.card_generator.getCard() + local_generator= CardGenerator(self.card_type) + local_generator.setCard(mf, sam) + +class TestNPACardGenerator(ISO7816GeneratorTest): + + card_type = 'nPA' + + def test_readDatagroups(self): + path = os.path.dirname(__file__) + datagroupsFile = path + "/Example_Dataset_Mueller_Gertrud.txt" + self.card_generator.readDatagroups(datagroupsFile) + mf, sam = self.card_generator.getCard() + self.assertIsNotNone(mf) + self.assertIsNotNone(sam) + +class CryptoflexGeneratorTest(ISO7816GeneratorTest): + + card_type = 'cryptoflex' + +# Not tested because an ePass card currently cannot be generated without user +# interaction. +# +#class ePassGeneratorTest(ISO7816GeneratorTest): +# +# card_type = 'ePass' if __name__ == '__main__': unittest.main() diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt new file mode 120000 index 0000000..5608518 --- /dev/null +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt @@ -0,0 +1 @@ +../../../../npa-example-data/Example_Dataset_Mueller_Gertrud.txt \ No newline at end of file From 0b52e4a1842b8b03652dafd13324cb6c5264e676 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sun, 18 Jan 2015 18:48:56 +0100 Subject: [PATCH 2/2] Use a relative path instead of a symlink so that the unit test works on windows --- .../src/vpicc/virtualsmartcard/tests/CardGenerator_test.py | 2 +- .../virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 120000 virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py index 851ebfe..1fbc8fd 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/CardGenerator_test.py @@ -68,7 +68,7 @@ class TestNPACardGenerator(ISO7816GeneratorTest): def test_readDatagroups(self): path = os.path.dirname(__file__) - datagroupsFile = path + "/Example_Dataset_Mueller_Gertrud.txt" + datagroupsFile = path + "/../../../../npa-example-data/Example_Dataset_Mueller_Gertrud.txt" self.card_generator.readDatagroups(datagroupsFile) mf, sam = self.card_generator.getCard() self.assertIsNotNone(mf) diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt b/virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt deleted file mode 120000 index 5608518..0000000 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/tests/Example_Dataset_Mueller_Gertrud.txt +++ /dev/null @@ -1 +0,0 @@ -../../../../npa-example-data/Example_Dataset_Mueller_Gertrud.txt \ No newline at end of file