p≡p for Python
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.

113 lines
3.7 KiB

2 years ago
2 years ago
2 years ago
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. """Identity unit tests."""
  3. import os
  4. from . import constants
  5. def test_create_one_identity_succeed(pEp):
  6. # It has to be imported here to get the management db initialized,
  7. alice = pEp.Identity()
  8. alice.address = constants.ALICE_ADDRESS
  9. alice.username = constants.ALICE_NAME
  10. alice.fpr = constants.ALICE_FPR
  11. expected_alice = pEp.Identity(
  12. constants.ALICE_ADDRESS, constants.ALICE_NAME, '',
  13. constants.ALICE_FPR, 0, ''
  14. )
  15. # XXX: Can't compare objects
  16. # assert alice == expected_alice
  17. assert str(alice) == constants.ALICE_NAME_ADDR
  18. assert alice.address == expected_alice.address
  19. assert alice.username == expected_alice.username
  20. # Cause the key is created by pEp
  21. assert alice.fpr == expected_alice.fpr
  22. assert alice.user_id == expected_alice.user_id
  23. assert alice.comm_type == expected_alice.comm_type
  24. assert alice.flags == expected_alice.flags
  25. # Test that data after updating.
  26. # If the db has not been initialized this would return PEP_GET_KEY_FAILED
  27. alice.update()
  28. assert str(alice) == constants.ALICE_NAME_ADDR
  29. assert alice.address == expected_alice.address
  30. assert alice.username == expected_alice.username
  31. # XXX: shouldn't this be he fpr of the key generated by pEp?
  32. assert alice.fpr == ''
  33. # After updating this changed
  34. assert alice.user_id == "TOFU_alice@openpgp.example"
  35. # After updating this changed
  36. assert alice.comm_type == 3
  37. assert alice.flags == expected_alice.flags
  38. def test_two_identities_succeed(pEp, bob_key_pub):
  39. alice = pEp.Identity(
  40. constants.ALICE_ADDRESS, constants.ALICE_NAME, '',
  41. constants.ALICE_FPR, 0, ''
  42. )
  43. assert alice.address == constants.ALICE_ADDRESS
  44. assert alice.username == constants.ALICE_NAME
  45. assert alice.fpr == constants.ALICE_FPR
  46. assert alice.user_id == ""
  47. assert alice.comm_type == 0
  48. assert alice.flags == 0
  49. pEp.import_key(bob_key_pub)
  50. bob = pEp.Identity()
  51. bob.address = constants.BOB_ADDRESS
  52. bob.username = constants.BOB_NAME
  53. bob.fpr = constants.BOB_FPR
  54. expected_bob = pEp.Identity(
  55. constants.BOB_ADDRESS, constants.BOB_NAME, '',
  56. constants.BOB_FPR, 56, ''
  57. )
  58. assert str(bob) == constants.BOB_NAME_ADDR
  59. assert bob.address == expected_bob.address
  60. assert bob.username == expected_bob.username
  61. assert bob.fpr == expected_bob.fpr
  62. assert bob.user_id == ""
  63. assert bob.comm_type == 0
  64. assert bob.flags == 0
  65. # Test that data after updating.
  66. bob.update()
  67. assert str(bob) == constants.BOB_NAME_ADDR
  68. assert bob.address == expected_bob.address
  69. assert bob.username == expected_bob.username
  70. assert bob.fpr == expected_bob.fpr
  71. assert bob.user_id == "TOFU_bob@openpgp.example"
  72. assert bob.comm_type == 56
  73. assert bob.flags == 0
  74. def test_set_own_key(pEp, alice_key_sec):
  75. pEp.import_key(alice_key_sec)
  76. alice = pEp.Identity()
  77. alice.address = constants.ALICE_ADDRESS
  78. alice.username = constants.ALICE_NAME
  79. alice.fpr = constants.ALICE_FPR
  80. alice.user_id = constants.ALICE_NAME_ADDR
  81. expected_alice = pEp.Identity(
  82. constants.ALICE_ADDRESS, constants.ALICE_NAME, '',
  83. constants.ALICE_FPR, 0, ''
  84. )
  85. pEp.set_own_key(alice, alice.fpr)
  86. # assert str(alice) == constants.ALICE_NAME_ADDR
  87. assert str(alice) == str(expected_alice)
  88. assert alice.address == expected_alice.address
  89. assert alice.username == expected_alice.username
  90. # assert alice.user_id == constants.ALICE_NAME_ADDR
  91. assert alice.user_id == str(expected_alice)
  92. assert alice.fpr == expected_alice.fpr
  93. assert alice.comm_type == 255
  94. assert alice.flags == 0
  95. # After setting own key this would give ValueError: illegal value
  96. # alice.update()