pyocf: security tests for ioclass api
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
parent
fa556247d7
commit
c4a2dc4cad
@ -4,10 +4,12 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import string
|
||||||
|
|
||||||
from pyocf.types.cache import (
|
from pyocf.types.cache import (
|
||||||
Cache,
|
Cache,
|
||||||
CacheMode,
|
CacheMode,
|
||||||
|
CACHE_MODE_NONE,
|
||||||
CleaningPolicy,
|
CleaningPolicy,
|
||||||
AlruParams,
|
AlruParams,
|
||||||
AcpParams,
|
AcpParams,
|
||||||
@ -18,7 +20,7 @@ from pyocf.types.cache import (
|
|||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.volume import Volume
|
from pyocf.types.volume import Volume
|
||||||
from pyocf.utils import Size as S
|
from pyocf.utils import Size as S
|
||||||
from tests.utils.random import RandomGenerator, DefaultRanges
|
from tests.utils.random import Range, RandomGenerator, DefaultRanges, RandomStringGenerator
|
||||||
from pyocf.types.shared import OcfError, CacheLineSize, SeqCutOffPolicy
|
from pyocf.types.shared import OcfError, CacheLineSize, SeqCutOffPolicy
|
||||||
from ctypes import c_uint64, c_uint32, c_uint8
|
from ctypes import c_uint64, c_uint32, c_uint8
|
||||||
|
|
||||||
@ -454,3 +456,137 @@ def test_neg_set_nhit_promotion_policy_param_threshold(pyocf_ctx, cm, cls):
|
|||||||
cache.set_promotion_policy_param(
|
cache.set_promotion_policy_param(
|
||||||
PromotionPolicy.NHIT, NhitParams.INSERTION_THRESHOLD, i
|
PromotionPolicy.NHIT, NhitParams.INSERTION_THRESHOLD, i
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cm", CacheMode)
|
||||||
|
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||||
|
@pytest.mark.security
|
||||||
|
def test_neg_set_ioclass_max_size(pyocf_ctx, cm, cls):
|
||||||
|
"""
|
||||||
|
Test whether it is possible to add ioclass with invaild max size
|
||||||
|
:param pyocf_ctx: basic pyocf context fixture
|
||||||
|
:param cm: cache mode we start with
|
||||||
|
:param cls: cache line size we start with
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# Start cache device
|
||||||
|
cache_device = Volume(S.from_MiB(30))
|
||||||
|
cache = Cache.start_on_device(cache_device, cache_mode=cm, cache_line_size=cls)
|
||||||
|
|
||||||
|
# Set invalid max size and check if failed
|
||||||
|
for i in RandomGenerator(DefaultRanges.UINT32):
|
||||||
|
if i in ConfValidValues.ioclass_max_size_range:
|
||||||
|
continue
|
||||||
|
with pytest.raises(OcfError, match="Error adding partition to cache"):
|
||||||
|
cache.configure_partition(
|
||||||
|
part_id=1,
|
||||||
|
name="unclassified",
|
||||||
|
max_size=i,
|
||||||
|
priority=0,
|
||||||
|
cache_mode=CACHE_MODE_NONE,
|
||||||
|
)
|
||||||
|
print("\n" + i)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cm", CacheMode)
|
||||||
|
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||||
|
@pytest.mark.security
|
||||||
|
def test_neg_set_ioclass_priority(pyocf_ctx, cm, cls):
|
||||||
|
"""
|
||||||
|
Test whether it is possible to add ioclass with invaild priority
|
||||||
|
:param pyocf_ctx: basic pyocf context fixture
|
||||||
|
:param cm: cache mode we start with
|
||||||
|
:param cls: cache line size we start with
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# Start cache device
|
||||||
|
cache_device = Volume(S.from_MiB(30))
|
||||||
|
cache = Cache.start_on_device(cache_device, cache_mode=cm, cache_line_size=cls)
|
||||||
|
|
||||||
|
# Set invalid priority and check if failed
|
||||||
|
for i in RandomGenerator(DefaultRanges.INT16):
|
||||||
|
if i in ConfValidValues.ioclass_priority_range:
|
||||||
|
continue
|
||||||
|
with pytest.raises(OcfError, match="Error adding partition to cache"):
|
||||||
|
cache.configure_partition(
|
||||||
|
part_id=1,
|
||||||
|
name="unclassified",
|
||||||
|
max_size=100,
|
||||||
|
priority=i,
|
||||||
|
cache_mode=CACHE_MODE_NONE,
|
||||||
|
)
|
||||||
|
print("\n" + i)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cm", CacheMode)
|
||||||
|
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||||
|
@pytest.mark.security
|
||||||
|
def test_neg_set_ioclass_cache_mode(pyocf_ctx, cm, cls):
|
||||||
|
"""
|
||||||
|
Test whether it is possible to add ioclass with invaild cache mode
|
||||||
|
:param pyocf_ctx: basic pyocf context fixture
|
||||||
|
:param cm: cache mode we start with
|
||||||
|
:param cls: cache line size we start with
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# Start cache device
|
||||||
|
cache_device = Volume(S.from_MiB(30))
|
||||||
|
cache = Cache.start_on_device(cache_device, cache_mode=cm, cache_line_size=cls)
|
||||||
|
|
||||||
|
# Set invalid cache mode and check if failed
|
||||||
|
for i in RandomGenerator(DefaultRanges.INT):
|
||||||
|
if i in list(CacheMode) + [CACHE_MODE_NONE]:
|
||||||
|
continue
|
||||||
|
with pytest.raises(OcfError, match="Error adding partition to cache"):
|
||||||
|
cache.configure_partition(
|
||||||
|
part_id=1, name="unclassified", max_size=100, priority=1, cache_mode=i
|
||||||
|
)
|
||||||
|
print("\n" + i)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.security
|
||||||
|
def test_neg_set_ioclass_name(pyocf_ctx):
|
||||||
|
"""
|
||||||
|
Test whether it is possible to add ioclass with invaild name
|
||||||
|
:param pyocf_ctx: basic pyocf context fixture
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
invalid_chars = [chr(c) for c in range(256) if chr(c) not in string.printable]
|
||||||
|
invalid_chars += [",", '"']
|
||||||
|
|
||||||
|
# Start cache device
|
||||||
|
cache_device = Volume(S.from_MiB(30))
|
||||||
|
cache = Cache.start_on_device(
|
||||||
|
cache_device, cache_mode=CacheMode.WT, cache_line_size=CacheLineSize.LINE_4KiB
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set invalid name and check if failed
|
||||||
|
for name in RandomStringGenerator(
|
||||||
|
len_range=Range(0, 1024), count=10000, extra_chars=invalid_chars
|
||||||
|
):
|
||||||
|
if not any(c for c in invalid_chars if c in name):
|
||||||
|
continue
|
||||||
|
with pytest.raises(OcfError, match="Error adding partition to cache"):
|
||||||
|
cache.configure_partition(part_id=1, name=name, max_size=100, priority=1)
|
||||||
|
print(f"\n{name}")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.security
|
||||||
|
def test_neg_set_ioclass_name_len(pyocf_ctx):
|
||||||
|
"""
|
||||||
|
Test whether it is possible to add ioclass with too long name
|
||||||
|
:param pyocf_ctx: basic pyocf context fixture
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Start cache device
|
||||||
|
cache_device = Volume(S.from_MiB(30))
|
||||||
|
cache = Cache.start_on_device(
|
||||||
|
cache_device, cache_mode=CacheMode.WT, cache_line_size=CacheLineSize.LINE_4KiB
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set invalid name and check if failed
|
||||||
|
for name in RandomStringGenerator(len_range=Range(1025, 4096), count=10000):
|
||||||
|
with pytest.raises(OcfError, match="Error adding partition to cache"):
|
||||||
|
cache.configure_partition(part_id=1, name=name, max_size=100, priority=1)
|
||||||
|
print(f"\n{name}")
|
||||||
|
Loading…
Reference in New Issue
Block a user