diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 496966f01..b171f3458 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,6 +163,16 @@ jobs: docker load --input ${{ runner.temp }}/iriswebapp_app.tar - name: Check out iris uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + cache-dependency-path: ui/package-lock.json + - name: Build ui to be mounted in development docker + working-directory: ui + run: | + npm ci + npm run build - name: Start development server run: | # Even though, we use --env-file option when running docker compose, this is still necessary, because the compose has a env_file attribute :( diff --git a/source/app/schema/marshables.py b/source/app/schema/marshables.py index 5644f6bd5..f74e8c840 100644 --- a/source/app/schema/marshables.py +++ b/source/app/schema/marshables.py @@ -159,9 +159,7 @@ def store_icon(file): try: store_fullpath = os.path.join(app.config['ASSET_STORE_PATH'], filename) - show_fullpath = os.path.join(app.config['APP_PATH'], 'app', - app.config['ASSET_SHOW_PATH'].strip(os.path.sep), - filename) + show_fullpath = os.path.join(app.config['APP_PATH'], app.config['ASSET_SHOW_PATH'].strip(os.path.sep), filename) file.save(store_fullpath) os.symlink(store_fullpath, show_fullpath) diff --git a/tests/data/img/desktop.png b/tests/data/img/desktop.png new file mode 100644 index 000000000..1d3d03a77 Binary files /dev/null and b/tests/data/img/desktop.png differ diff --git a/tests/iris.py b/tests/iris.py index ec435d54c..fbca2ec37 100644 --- a/tests/iris.py +++ b/tests/iris.py @@ -54,6 +54,9 @@ def delete(self, path): def post_multipart_encoded_file(self, path, data, file_path): return self._api.post_multipart_encoded_file(path, data, file_path) + def post_multipart_encoded_files(self, path, data, files): + return self._api.post_multipart_encoded_files(path, data, files) + def _create_user(self, user_name): body = { 'user_name': user_name, diff --git a/tests/rest_api.py b/tests/rest_api.py index d523d6ccd..68d8a5f6f 100644 --- a/tests/rest_api.py +++ b/tests/rest_api.py @@ -82,3 +82,11 @@ def post_multipart_encoded_file(self, path, data, file_path): response_as_string = self._convert_response_to_string(response) print(f'POST {url} {data} {file_path} => {response_as_string}') return response + + def post_multipart_encoded_files(self, path, data, files): + headers = {'Authorization': f'Bearer {self._api_key}'} + url = self._build_url(path) + response = requests.post(url, headers=headers, data=data, files=files) + response_as_string = self._convert_response_to_string(response) + print(f'POST {url} {data} {list(files)} => {response_as_string}') + return response diff --git a/tests/tests_rest_asset_types.py b/tests/tests_rest_asset_types.py new file mode 100644 index 000000000..57060d9fb --- /dev/null +++ b/tests/tests_rest_asset_types.py @@ -0,0 +1,39 @@ +# IRIS Source Code +# Copyright (C) 2023 - DFIR-IRIS +# contact@dfir-iris.org +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +from unittest import TestCase +from iris import Iris + +_FIRST_ASSET_TYPE_IDENTIFIER = 1 + + +class TestsRestAssetTypes(TestCase): + + def setUp(self) -> None: + self._subject = Iris() + + def tearDown(self): + self._subject.clear_database() + + def test_update_asset_type_should_return_200(self): + url = f'/manage/asset-type/update/{_FIRST_ASSET_TYPE_IDENTIFIER}' + data = {'asset_name': 'Account', 'asset_description': 'Generic Account'} + with open('data/img/desktop.png', 'rb') as file_not_compromised: + files = {'asset_icon_not_compromised': file_not_compromised, 'asset_icon_compromised': ('', '')} + response = self._subject.post_multipart_encoded_files(url, data, files) + self.assertEqual(200, response.status_code)