Geen omschrijving

tests_rest_customers.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # IRIS Source Code
  2. # Copyright (C) 2023 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from unittest import TestCase
  19. from iris import Iris
  20. _PERMISSION_CUSTOMERS_WRITE = 0x80
  21. _IRIS_INITIAL_CLIENT_IDENTIFIER = 1
  22. class TestsRestCustomers(TestCase):
  23. def setUp(self) -> None:
  24. self._subject = Iris()
  25. def tearDown(self):
  26. self._subject.clear_database()
  27. users = self._subject.get('/manage/users/list').json()
  28. for user in users['data']:
  29. identifier = user['user_id']
  30. body = {'customers_membership': [_IRIS_INITIAL_CLIENT_IDENTIFIER]}
  31. self._subject.create(f'/manage/users/{identifier}/customers/update', body)
  32. customers = self._subject.get('/manage/customers/list').json()
  33. for customer in customers['data']:
  34. identifier = customer['customer_id']
  35. self._subject.create(f'/manage/customers/delete/{identifier}', {})
  36. def test_create_customer_should_return_200_when_user_has_customer_write_right(self):
  37. body = {
  38. 'group_name': 'Customer create',
  39. 'group_description': 'Group with customers_write right',
  40. 'group_permissions': [_PERMISSION_CUSTOMERS_WRITE]
  41. }
  42. response = self._subject.create('/manage/groups/add', body).json()
  43. group_identifier = response['data']['group_id']
  44. user = self._subject.create_dummy_user()
  45. body = {'groups_membership': [group_identifier]}
  46. self._subject.create(f'/manage/users/{user.get_identifier()}/groups/update', body)
  47. body = {'custom_attributes': {}, 'customer_description': '', 'customer_name': 'Customer', 'customer_sla': ''}
  48. response = user.create('/manage/customers/add', body)
  49. self.assertEqual(200, response.status_code)