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.

129 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # This file is under GNU Affero General Public License 3.0
  3. # see LICENSE.txt
  4. # from . import utils
  5. import pytest
  6. @pytest.fixture()
  7. def model():
  8. "Returns the whole data model"
  9. return Model()
  10. identities = \
  11. {
  12. "alice": {
  13. "name": "alice",
  14. "user_id": "23",
  15. "accounts":
  16. {
  17. "work": {
  18. "addr": "alice_work@peptest.org",
  19. "fpr": "3E45175EE953EBBEB948F11A6A03DB2A17FB9D15"
  20. },
  21. "home": {
  22. "addr": "alice@peptest.org",
  23. "fpr": "2D35731B9C754564CBAD15D2D18F7444594F2283"
  24. }
  25. }
  26. },
  27. "bob": {
  28. "name": "bob",
  29. "user_id": "uuid:1-2-3-4",
  30. "accounts": \
  31. {
  32. "work": {
  33. "addr": "bob_work@peptest.org",
  34. "fpr": "1A97F263D8319D6885F638C5AA81E1B5457A2B40"
  35. },
  36. "home": {
  37. "addr": "bob@peptest.org",
  38. "fpr": "6A9835699EF1215F1558A496D9C1D4B0984094E5"
  39. }
  40. }
  41. }
  42. }
  43. # An Identity class that is read-only (const)
  44. class Identity:
  45. __name = ""
  46. __user_id = ""
  47. __addr = ""
  48. __fpr = ""
  49. __key_sec = ""
  50. __key_pub = ""
  51. def __init__(self, name="", user_id="", addr="", fpr="", key_sec="", key_pub=""):
  52. self.__name = name
  53. self.__user_id = user_id
  54. self.__addr = addr
  55. self.__fpr = fpr
  56. self.__key_sec = key_sec
  57. self.__key_pub = key_pub
  58. def get_name(self):
  59. return self.__name
  60. def get_user_id(self):
  61. return self.__user_id
  62. def get_addr(self):
  63. return self.__addr
  64. def get_fpr(self):
  65. return self.__fpr
  66. def get_key_sec(self):
  67. return self.__key_sec
  68. def get_key_pub(self):
  69. return self.__key_pub
  70. name = property(get_name)
  71. user_id = property(get_user_id)
  72. addr = property(get_addr)
  73. fpr = property(get_fpr)
  74. key_sec = property(get_key_sec)
  75. key_pub = property(get_key_pub)
  76. def debug(self) -> str:
  77. ret = "name:" + self.__name
  78. ret +="user_id:" + self.__user_id
  79. ret +="addr:" + self.__addr
  80. ret +="fpr:" + self.__fpr
  81. ret +="key_sec:" + self.__key_sec[0:255]
  82. ret +="key_pub:" + self.__key_pub[0:255]
  83. return ret
  84. def __str__(self):
  85. return "{} {}".format(self.name, "<{}>".format(self.addr))
  86. # The Data Model
  87. class Model:
  88. alice = None
  89. alice_work = None
  90. bob = None
  91. bob_work = None
  92. def getIdentity(self, name, account) -> Identity:
  93. # fetch keys for ident from data folder
  94. key_sec = utils.data_file_contents(identities[name]['accounts'][account]['fpr'] + ".sec.asc")
  95. key_pub = utils.data_file_contents(identities[name]['accounts'][account]['fpr'] + ".pub.asc")
  96. ident = Identity(name=identities[name]['name'],
  97. user_id=identities[name]['user_id'],
  98. addr=identities[name]['accounts'][account]['addr'],
  99. fpr=identities[name]['accounts'][account]['fpr'],
  100. key_pub=key_pub,
  101. key_sec=key_sec
  102. )
  103. return ident
  104. def __init__(self):
  105. self.alice = self.getIdentity("alice", "home")
  106. self.alice_work = self.getIdentity("alice", "work")
  107. self.bob = self.getIdentity("bob", "home")
  108. self.bob_work = self.getIdentity("bob", "work")