You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. # -*- coding: utf-8 -*-
  2. # This file is under GNU Affero General Public License 3.0
  3. # see LICENSE.txt
  4. """Identity unit tests."""
  5. import pytest
  6. from . import constants
  7. from . import model
  8. # TODO: test_get_identity_by_{name,addr,etc..}
  9. # def test_create_ident_myself(pEp, alice_myself):
  10. # def test_create_ident_import(pEp, alice_myself):
  11. # def test_create_ident_nokey(pEp, alice_myself):
  12. def test_identity_constructor(pEp, model):
  13. alice = pEp.Identity(
  14. model.alice.addr,
  15. model.alice.name,
  16. model.alice.user_id
  17. )
  18. assert alice.address == model.alice.addr
  19. assert alice.username == model.alice.name
  20. assert alice.user_id == model.alice.user_id
  21. assert str(alice) == str(model.alice)
  22. # TODO:
  23. # These here are actually plenty of individual tests
  24. # Identity.update
  25. # key_import
  26. # set_own_key
  27. @pytest.mark.skip(reason="needs to be decomposed and migrated to new data model")
  28. def test_two_identities_succeed(pEp, model):
  29. alice = pEp.Identity(
  30. constants.ALICE_ADDRESS, constants.ALICE_USERNAME, '',
  31. constants.ALICE_FPR, 0, ''
  32. )
  33. assert alice.address == constants.ALICE_ADDRESS
  34. assert alice.username == constants.ALICE_USERNAME
  35. assert alice.fpr == constants.ALICE_FPR
  36. assert alice.user_id == ""
  37. assert alice.comm_type == 0
  38. assert alice.flags == 0
  39. pEp.import_key(model.bob.key_pub)
  40. bob = pEp.Identity()
  41. bob.address = constants.BOB_ADDRESS
  42. bob.username = constants.BOB_USERNAME
  43. bob.fpr = constants.BOB_FPR
  44. expected_bob = pEp.Identity(
  45. constants.BOB_ADDRESS, constants.BOB_USERNAME, '',
  46. constants.BOB_FPR, 56, ''
  47. )
  48. assert str(bob) == constants.BOB_NAME_ADDR
  49. assert bob.address == expected_bob.address
  50. assert bob.username == expected_bob.username
  51. assert bob.fpr == expected_bob.fpr
  52. assert bob.user_id == ""
  53. assert bob.comm_type == 0
  54. assert bob.flags == 0
  55. # Test that data after updating.
  56. bob.update()
  57. assert str(bob) == constants.BOB_NAME_ADDR
  58. assert bob.address == expected_bob.address
  59. assert bob.username == expected_bob.username
  60. assert bob.fpr == expected_bob.fpr
  61. assert bob.user_id == "TOFU_bob@openpgp.example"
  62. assert bob.comm_type == 56
  63. assert bob.flags == 0
  64. @pytest.mark.skip(reason="needs to be decomposed and migrated to new data model")
  65. def test_set_own_key(pEp, alice_key_sec):
  66. pEp.import_key(alice_key_sec)
  67. alice = pEp.Identity()
  68. alice.address = constants.ALICE_ADDRESS
  69. alice.username = constants.ALICE_USERNAME
  70. alice.fpr = constants.ALICE_FPR
  71. alice.user_id = constants.ALICE_NAME_ADDR
  72. expected_alice = pEp.Identity(
  73. constants.ALICE_ADDRESS, constants.ALICE_USERNAME, '',
  74. constants.ALICE_FPR, 0, ''
  75. )
  76. pEp.set_own_key(alice, alice.fpr)
  77. # assert str(alice) == constants.ALICE_NAME_ADDR
  78. assert str(alice) == str(expected_alice)
  79. assert alice.address == expected_alice.address
  80. assert alice.username == expected_alice.username
  81. # assert alice.user_id == constants.ALICE_NAME_ADDR
  82. assert alice.user_id == str(expected_alice)
  83. assert alice.fpr == expected_alice.fpr
  84. assert alice.comm_type == 255
  85. assert alice.flags == 0
  86. # After setting own key this would give ValueError: illegal value
  87. # alice.update()