summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-04-11 12:27:23 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-04-17 15:47:16 +0200
commit367059ddef14a495e277f68ceaf3455c092f839d (patch)
treeae625ff0265fecd122946c71d3a2d6afefae4817 /archaeological_operations
parentff5aee7158bd46e4ae22bc431adadd7060a6e277 (diff)
downloadIshtar-367059ddef14a495e277f68ceaf3455c092f839d.tar.bz2
Ishtar-367059ddef14a495e277f68ceaf3455c092f839d.zip
bandit checker: mark false security issues - fix security issues (low severity)
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/models.py2
-rw-r--r--archaeological_operations/tests.py25
-rw-r--r--archaeological_operations/utils.py7
3 files changed, 20 insertions, 14 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index ee2023f5c..57fc4676f 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -3005,7 +3005,7 @@ class AdministrativeAct(DocumentItem, BaseHistorizedItem, OwnPerms, ValueGetter)
else:
try:
self._get_index()
- except:
+ except ValidationError:
pass
super(AdministrativeAct, self).save(*args, **kwargs)
if hasattr(self, "associated_file") and self.associated_file:
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 8d134e519..605f4e46f 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -19,7 +19,8 @@
from bs4 import BeautifulSoup
import json
import datetime
-from subprocess import Popen, PIPE
+# nosec: call an explicit bin for testing purpose
+from subprocess import Popen, PIPE # nosec
from io import BytesIO
import tempfile
import locale
@@ -113,7 +114,8 @@ from ishtar_common.serializers import restore_serialized
class FileInit(object):
def login_as_superuser(self):
- self.client.login(username="username", password="tralala")
+ # nosec: hard coded password for test purposes
+ self.client.login(username="username", password="tralala") # nosec
def create_file(self):
self.extra_models, self.model_list = {}, []
@@ -1659,7 +1661,8 @@ class ParcelTest(ImportTest, TestCase):
)
def init_operation_parcels_tests(self):
- username, password, user = create_user(
+ # nosec: hard coded password for test purposes
+ username, password, user = create_user( # nosec
username="Gandalf", password="ushallpass"
)
user.user_permissions.add(
@@ -1980,10 +1983,11 @@ class OperationInitTest(object):
def tearDown(self):
# cleanup for further test
+ # nosec: quick and dirty cleanup do not care to catch exceptions
if hasattr(self, "user"):
try:
self.user.delete()
- except:
+ except: # nosec
pass
self.user = None
# all try/except is necessary for bad migrations on main...
@@ -1992,14 +1996,14 @@ class OperationInitTest(object):
for ope in self.operations:
try:
ope.delete()
- except:
+ except: # nosec
pass
self.operations = []
if hasattr(self, "parcels"):
for p in self.parcels:
try:
p.delete()
- except:
+ except: # nosec
pass
self.parcels = []
@@ -2347,8 +2351,9 @@ class OperationTest(TestCase, OperationInitTest):
)
self.assertEqual(response.status_code, 200)
f = BytesIO(response.content)
+ # nosec: call an explicit bin for testing purpose
filetype = (
- Popen("/usr/bin/file -b --mime -", shell=True, stdout=PIPE, stdin=PIPE)
+ Popen("/usr/bin/file -b --mime -", shell=True, stdout=PIPE, stdin=PIPE) # nosec
.communicate(f.read(1024))[0]
.strip()
)
@@ -2840,7 +2845,8 @@ class OperationSearchTest(TestCase, OperationInitTest, SearchText):
self.alt_user.user_permissions.add(
Permission.objects.get(codename="change_own_operation")
)
- self.alt_username2, self.alt_password2, self.alt_user2 = create_user(
+ # nosec: hard coded password for test purposes
+ self.alt_username2, self.alt_password2, self.alt_user2 = create_user( # nosec
username="luke", password="iamyourfather"
)
profile = UserProfile.objects.create(
@@ -3314,7 +3320,8 @@ class OperationPermissionTest(TestCase, OperationInitTest):
self.alt_user.user_permissions.add(
Permission.objects.get(codename="change_own_operation")
)
- self.alt_username2, self.alt_password2, self.alt_user2 = create_user(
+ # nosec: hard coded password for test purposes
+ self.alt_username2, self.alt_password2, self.alt_user2 = create_user( # nosec
username="luke", password="iamyourfather"
)
profile_type = ProfileType.objects.get(txt_idx="collaborator")
diff --git a/archaeological_operations/utils.py b/archaeological_operations/utils.py
index ba4f17358..a571228b8 100644
--- a/archaeological_operations/utils.py
+++ b/archaeological_operations/utils.py
@@ -460,11 +460,11 @@ def parse_insee(value):
for value in values:
try:
town = Town.objects.get(numero_insee=value)
- towns.append(town)
- except:
+ except Town.DoesNotExist:
# sys.stderr.write('Numero INSEE : %s non existant en base'
# % value)
continue
+ towns.append(town)
return towns
@@ -482,8 +482,7 @@ def parse_parcels(parcel_str, insee_code=None, owner=None):
if insee_code:
town = parse_insee(insee_code)
# manage only one town at a time
- assert len(town) < 2
- if not town:
+ if len(town) >= 2 or not town:
return parcels
town = town[0]
m = PARCEL_YEAR_REGEXP.match(parcel_str)