S311: fix random usage

This commit is contained in:
Jörg Thalheim
2025-08-20 16:19:14 +02:00
parent 7747e3cc0d
commit e208c02be7
3 changed files with 6 additions and 6 deletions

View File

@@ -235,7 +235,7 @@ def test_multiple_user_keys(
# let's do some setting and getting of secrets
def random_str() -> str:
return "".join(random.choices(string.ascii_letters, k=10))
return "".join(random.choices(string.ascii_letters, k=10)) # noqa: S311 - Test data generation, not cryptographic
for user_key in user_keys:
# set a secret using each of the user's private keys

View File

@@ -1,5 +1,5 @@
import platform
import random
import secrets
from collections.abc import Generator
from contextlib import contextmanager
from dataclasses import dataclass
@@ -27,7 +27,7 @@ def graphics_options(vm: VmConfig) -> GraphicOptions:
if vm.waypipe.enable:
# FIXME: check for collisions
cid = random.randint(1, 2**32)
cid = secrets.randbelow(2**32 - 1) + 1 # Generate random CID between 1 and 2^32
# fmt: off
return GraphicOptions([
*common,

View File

@@ -1,8 +1,8 @@
import json
import logging
import os
import random
import re
import secrets
from pathlib import Path
from tempfile import TemporaryDirectory
@@ -34,8 +34,8 @@ def is_local_input(node: dict[str, dict[str, str]]) -> bool:
def random_hostname() -> str:
adjectives = ["wacky", "happy", "fluffy", "silly", "quirky", "zany", "bouncy"]
nouns = ["unicorn", "penguin", "goose", "ninja", "octopus", "hamster", "robot"]
adjective = random.choice(adjectives)
noun = random.choice(nouns)
adjective = secrets.choice(adjectives)
noun = secrets.choice(nouns)
return f"{adjective}-{noun}"