Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cyclonedx/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from abc import ABC, abstractmethod
from collections.abc import Iterable, Mapping
from itertools import chain
from random import random
from typing import TYPE_CHECKING, Any, Literal, Optional, Union, overload
from uuid import uuid4

from ..schema import OutputFormat, SchemaVersion

Expand Down Expand Up @@ -166,7 +166,7 @@ def reset(self) -> None:
bomref.value = original_value

def _make_unique(self) -> str:
return f'{self._prefix}{str(random())[1:]}{str(random())[1:]}' # nosec B311
return f'{self._prefix}.{uuid4().int}.{uuid4().int}'

@classmethod
def from_bom(cls, bom: 'Bom', prefix: str = 'BomRef') -> 'BomRefDiscriminator':
Expand Down
5 changes: 5 additions & 0 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ def test_discriminate_and_reset_manually(self) -> None:
discr.reset()
self.assertEqual('djdlkfjdslkf', bomref1.value)
self.assertEqual('djdlkfjdslkf', bomref2.value)

def test_make_unique_generates_integers(self) -> None:
discr = BomRefDiscriminator([])
for _ in range(1000):
self.assertRegex(discr._make_unique(), r'^BomRef\.\d+\.\d+$')