Complete ErasePhysical and EraseBasic.standards; remove EraseBasic.zeros

This commit is contained in:
Xavier Bustamante Talavera 2018-11-17 18:24:34 +01:00
parent 955fb4a33d
commit 9c3de1c258
19 changed files with 76 additions and 47 deletions

View file

@ -80,6 +80,10 @@ class Dummy:
sample_pc = s['device']['id'] sample_pc = s['device']['id']
else: else:
pcs.add(s['device']['id']) pcs.add(s['device']['id'])
if s.get('uuid', None) == 'de4f495e-c58b-40e1-a33e-46ab5e84767e': # oreo
# Make one hdd ErasePhysical
hdd = next(hdd for hdd in s['components'] if hdd['type'] == 'HardDrive')
user.post({'type': 'ErasePhysical', 'method': 'Shred', 'device': hdd['id']}, res=m.Event)
assert sample_pc assert sample_pc
print('PC sample is', sample_pc) print('PC sample is', sample_pc)
# Link tags and eTags # Link tags and eTags

View file

@ -97,7 +97,7 @@
"endTime": "2018-07-11T11:42:12.971177" "endTime": "2018-07-11T11:42:12.971177"
} }
], ],
"zeros": false,
"severity": "Info", "severity": "Info",
"type": "EraseBasic", "type": "EraseBasic",
"endTime": "2018-07-11T11:42:12.975358", "endTime": "2018-07-11T11:42:12.975358",

View file

@ -72,7 +72,7 @@
"events": [ "events": [
{ {
"type": "EraseBasic", "type": "EraseBasic",
"zeros": false,
"endTime": "2018-07-11T11:56:52.390306", "endTime": "2018-07-11T11:56:52.390306",
"severity": "Info", "severity": "Info",
"startTime": "2018-07-11T10:49:31.998217", "startTime": "2018-07-11T10:49:31.998217",

View file

@ -81,7 +81,7 @@
}, },
{ {
"startTime": "2018-07-11T10:32:14.445306", "startTime": "2018-07-11T10:32:14.445306",
"zeros": false,
"type": "EraseBasic", "type": "EraseBasic",
"severity": "Info", "severity": "Info",
"endTime": "2018-07-11T10:53:46.442123", "endTime": "2018-07-11T10:53:46.442123",
@ -113,7 +113,7 @@
}, },
{ {
"startTime": "2018-07-11T10:53:46.442187", "startTime": "2018-07-11T10:53:46.442187",
"zeros": false,
"type": "EraseBasic", "type": "EraseBasic",
"severity": "Info", "severity": "Info",
"endTime": "2018-07-11T11:16:28.469899", "endTime": "2018-07-11T11:16:28.469899",

View file

@ -110,8 +110,7 @@
"endTime": "2018-07-11T14:04:04.861590", "endTime": "2018-07-11T14:04:04.861590",
"severity": "Info" "severity": "Info"
} }
], ]
"zeros": false
} }
], ],
"size": 238475, "size": 238475,

View file

@ -104,7 +104,6 @@
"severity": "Info", "severity": "Info",
"endTime": "2018-07-11T11:33:41.531918", "endTime": "2018-07-11T11:33:41.531918",
"startTime": "2018-07-11T10:30:35.643855", "startTime": "2018-07-11T10:30:35.643855",
"zeros": false,
"type": "EraseBasic", "type": "EraseBasic",
"steps": [ "steps": [
{ {

View file

@ -105,7 +105,7 @@
], ],
"startTime": "2018-07-03T09:15:22.256074", "startTime": "2018-07-03T09:15:22.256074",
"severity": "Info", "severity": "Info",
"zeros": false,
"endTime": "2018-07-03T10:32:11.848455" "endTime": "2018-07-03T10:32:11.848455"
} }
] ]

View file

@ -1,6 +1,7 @@
from contextlib import suppress
from distutils.version import StrictVersion from distutils.version import StrictVersion
from enum import Enum, IntEnum, unique from enum import Enum, IntEnum, unique
from typing import Union from typing import Set, Union
import inflection import inflection
@ -350,5 +351,14 @@ class ErasureStandards(Enum):
return self.value return self.value
@classmethod @classmethod
def from_data_storage(cls, erasure): def from_data_storage(cls, erasure) -> Set['ErasureStandards']:
raise NotImplementedError() """Returns a set of erasure standards."""
from ereuse_devicehub.resources.event import models as events
standards = set()
if isinstance(erasure, events.EraseSectors):
with suppress(ValueError):
first_step, *other_steps = erasure.steps
if isinstance(first_step, events.StepZero) \
and all(isinstance(step, events.StepRandom) for step in other_steps):
standards.add(cls.HMG_IS5)
return standards

View file

@ -34,6 +34,11 @@ class EraseSectorsDef(EraseBasicDef):
SCHEMA = schemas.EraseSectors SCHEMA = schemas.EraseSectors
class ErasePhysicalDef(EraseBasicDef):
VIEW = None
SCHEMA = schemas.ErasePhysical
class StepDef(Resource): class StepDef(Resource):
VIEW = None VIEW = None
SCHEMA = schemas.Step SCHEMA = schemas.Step

View file

@ -311,11 +311,6 @@ class EraseBasic(JoinedWithOneDeviceMixin, EventWithOneDevice):
Devicehub automatically shows the standards that each erasure Devicehub automatically shows the standards that each erasure
follows. follows.
""" """
zeros = Column(Boolean, nullable=False)
zeros.comment = """
Whether this erasure had a first erasure step consisting of
only writing zeros.
"""
@property @property
def standards(self): def standards(self):
@ -330,7 +325,6 @@ class EraseSectors(EraseBasic):
"""A secured-way of erasing data storages, checking sector-by-sector """A secured-way of erasing data storages, checking sector-by-sector
the erasure, using `badblocks <https://en.wikipedia.org/wiki/Badblocks>`_. the erasure, using `badblocks <https://en.wikipedia.org/wiki/Badblocks>`_.
""" """
# todo make a property that says if the data wiping process is british...
class ErasePhysical(EraseBasic): class ErasePhysical(EraseBasic):

View file

@ -17,8 +17,8 @@ from teal.enums import Country
from ereuse_devicehub.resources.agent.models import Agent from ereuse_devicehub.resources.agent.models import Agent
from ereuse_devicehub.resources.device.models import Component, Computer, Device from ereuse_devicehub.resources.device.models import Component, Computer, Device
from ereuse_devicehub.resources.enums import AppearanceRange, Bios, ErasureStandards, \ from ereuse_devicehub.resources.enums import AppearanceRange, Bios, ErasureStandards, \
FunctionalityRange, PriceSoftware, RatingSoftware, ReceiverRole, Severity, \ FunctionalityRange, PhysicalErasureMethod, PriceSoftware, RatingSoftware, ReceiverRole, \
SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength Severity, SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength
from ereuse_devicehub.resources.models import Thing from ereuse_devicehub.resources.models import Thing
from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.models import User
@ -364,6 +364,14 @@ class EraseSectors(EraseBasic):
super().__init__(**kwargs) super().__init__(**kwargs)
class ErasePhysical(EraseBasic):
method = ... # type: Column
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.method = ... # type: PhysicalErasureMethod
class Benchmark(EventWithOneDevice): class Benchmark(EventWithOneDevice):
pass pass

View file

@ -1,5 +1,5 @@
from flask import current_app as app from flask import current_app as app
from marshmallow import Schema as MarshmallowSchema, ValidationError, validates_schema from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema
from marshmallow.fields import Boolean, DateTime, Decimal, Float, Integer, List, Nested, String, \ from marshmallow.fields import Boolean, DateTime, Decimal, Float, Integer, List, Nested, String, \
TimeDelta, UUID TimeDelta, UUID
from marshmallow.validate import Length, Range from marshmallow.validate import Length, Range
@ -9,11 +9,12 @@ from teal.marshmallow import EnumField, IP, SanitizedStr, URL, Version
from teal.resource import Schema from teal.resource import Schema
from ereuse_devicehub.marshmallow import NestedOn from ereuse_devicehub.marshmallow import NestedOn
from ereuse_devicehub.resources import enums
from ereuse_devicehub.resources.agent.schemas import Agent from ereuse_devicehub.resources.agent.schemas import Agent
from ereuse_devicehub.resources.device.schemas import Component, Computer, Device from ereuse_devicehub.resources.device.schemas import Component, Computer, Device
from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \ from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \
PriceSoftware, RATE_POSITIVE, RatingRange, RatingSoftware, ReceiverRole, Severity, \ PhysicalErasureMethod, PriceSoftware, RATE_POSITIVE, RatingRange, RatingSoftware, ReceiverRole, \
SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength Severity, SnapshotExpectedEvents, SnapshotSoftware, TestDataStorageLength
from ereuse_devicehub.resources.event import models as m from ereuse_devicehub.resources.event import models as m
from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
from ereuse_devicehub.resources.schemas import Thing from ereuse_devicehub.resources.schemas import Thing
@ -72,14 +73,18 @@ class Deallocate(EventWithMultipleDevices):
class EraseBasic(EventWithOneDevice): class EraseBasic(EventWithOneDevice):
zeros = Boolean(required=True, description=m.EraseBasic.zeros.comment) steps = NestedOn('Step', many=True)
steps = NestedOn('Step', many=True, required=True) standards = f.List(EnumField(enums.ErasureStandards), dump_only=True)
class EraseSectors(EraseBasic): class EraseSectors(EraseBasic):
pass pass
class ErasePhysical(EraseBasic):
method = EnumField(PhysicalErasureMethod, description=PhysicalErasureMethod.__doc__)
class Step(Schema): class Step(Schema):
type = String(description='Only required when it is nested.') type = String(description='Only required when it is nested.')
start_time = DateTime(required=True, data_key='startTime') start_time = DateTime(required=True, data_key='startTime')

View file

@ -75,7 +75,7 @@
], ],
"type": "EraseBasic", "type": "EraseBasic",
"severity": "Info", "severity": "Info",
"zeros": false,
"startTime": "2018-07-13T10:52:45.092612" "startTime": "2018-07-13T10:52:45.092612"
}, },
{ {
@ -113,7 +113,6 @@
], ],
"type": "EraseBasic", "type": "EraseBasic",
"severity": "Info", "severity": "Info",
"zeros": false,
"startTime": "2018-07-13T11:54:55.100667" "startTime": "2018-07-13T11:54:55.100667"
}, },
{ {

View file

@ -16,7 +16,6 @@ components:
manufacturer: c1mr manufacturer: c1mr
events: events:
- type: EraseSectors - type: EraseSectors
zeros: True
startTime: 2018-06-01T08:12:06 startTime: 2018-06-01T08:12:06
endTime: 2018-06-01T09:12:06 endTime: 2018-06-01T09:12:06
steps: steps:
@ -24,7 +23,7 @@ components:
severity: Info severity: Info
startTime: 2018-06-01T08:15:00 startTime: 2018-06-01T08:15:00
endTime: 2018-06-01T09:16:00 endTime: 2018-06-01T09:16:00
- type: StepZero - type: StepRandom
severity: Info severity: Info
startTime: 2018-06-01T08:16:00 startTime: 2018-06-01T08:16:00
endTime: 2018-06-01T09:17:00 endTime: 2018-06-01T09:17:00

View file

@ -10,7 +10,6 @@ type: 'EraseSectors'
severity: Info severity: Info
# snapshot: None fulfill! # snapshot: None fulfill!
# device: None fulfill! # device: None fulfill!
zeros: False
startTime: 2018-01-01T10:10:10 startTime: 2018-01-01T10:10:10
endTime: 2018-01-01T12:10:10 endTime: 2018-01-01T12:10:10
steps: steps:

View file

@ -40,4 +40,4 @@ def test_api_docs(client: Client):
'scheme': 'basic', 'scheme': 'basic',
'name': 'Authorization' 'name': 'Authorization'
} }
assert 94 == len(docs['definitions']) assert 95 == len(docs['definitions'])

View file

@ -10,6 +10,7 @@ from teal.enums import Currency, Subdivision
from ereuse_devicehub.client import UserClient from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources import enums
from ereuse_devicehub.resources.device import states from ereuse_devicehub.resources.device import states
from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCard, HardDrive, \ from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCard, HardDrive, \
RamModule, SolidStateDrive RamModule, SolidStateDrive
@ -40,7 +41,10 @@ def test_author():
def test_erase_basic(): def test_erase_basic():
erasure = models.EraseBasic( erasure = models.EraseBasic(
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'), device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
zeros=True, steps=[
models.StepZero(**conftest.T),
models.StepRandom(**conftest.T)
],
**conftest.T **conftest.T
) )
db.session.add(erasure) db.session.add(erasure)
@ -48,6 +52,7 @@ def test_erase_basic():
db_erasure = models.EraseBasic.query.one() db_erasure = models.EraseBasic.query.one()
assert erasure == db_erasure assert erasure == db_erasure
assert next(iter(db_erasure.device.events)) == erasure assert next(iter(db_erasure.device.events)) == erasure
assert not erasure.standards, 'EraseBasic themselves do not have standards'
@pytest.mark.usefixtures(conftest.auth_app_context.__name__) @pytest.mark.usefixtures(conftest.auth_app_context.__name__)
@ -65,14 +70,13 @@ def test_validate_device_data_storage():
@pytest.mark.usefixtures(conftest.auth_app_context.__name__) @pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_erase_sectors_steps(): def test_erase_sectors_steps_erasure_standards_hmg_is5():
erasure = models.EraseSectors( erasure = models.EraseSectors(
device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'), device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
zeros=True,
steps=[ steps=[
models.StepZero(**conftest.T), models.StepZero(**conftest.T),
models.StepRandom(**conftest.T), models.StepRandom(**conftest.T),
models.StepZero(**conftest.T) models.StepRandom(**conftest.T)
], ],
**conftest.T **conftest.T
) )
@ -83,6 +87,7 @@ def test_erase_sectors_steps():
assert db_erasure.steps[0].num == 0 assert db_erasure.steps[0].num == 0
assert db_erasure.steps[1].num == 1 assert db_erasure.steps[1].num == 1
assert db_erasure.steps[2].num == 2 assert db_erasure.steps[2].num == 2
assert {enums.ErasureStandards.HMG_IS5} == erasure.standards
@pytest.mark.usefixtures(conftest.auth_app_context.__name__) @pytest.mark.usefixtures(conftest.auth_app_context.__name__)
@ -324,14 +329,14 @@ def test_ereuse_price():
# Range.verylow not returning nothing # Range.verylow not returning nothing
@pytest.mark.xfail(reson='Develop functionality') @pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_erase_standards():
pass
@pytest.mark.xfail(reson='Develop test')
def test_erase_physical(): def test_erase_physical():
pass erasure = models.ErasePhysical(
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
method=enums.PhysicalErasureMethod.Disintegration
)
db.session.add(erasure)
db.session.commit()
@pytest.mark.xfail(reson='validate use-case') @pytest.mark.xfail(reson='validate use-case')

View file

@ -289,7 +289,7 @@ def test_snapshot_component_containing_components(user: UserClient):
user.post(s, res=Snapshot, status=ValidationError) user.post(s, res=Snapshot, status=ValidationError)
def test_erase_privacy(user: UserClient): def test_erase_privacy_standards(user: UserClient):
"""Tests a Snapshot with EraseSectors and the resulting """Tests a Snapshot with EraseSectors and the resulting
privacy properties. privacy properties.
""" """
@ -310,10 +310,14 @@ def test_erase_privacy(user: UserClient):
assert erasure['steps'][1]['startTime'] == '2018-06-01T08:16:00+00:00' assert erasure['steps'][1]['startTime'] == '2018-06-01T08:16:00+00:00'
assert erasure['steps'][1]['endTime'] == '2018-06-01T09:17:00+00:00' assert erasure['steps'][1]['endTime'] == '2018-06-01T09:17:00+00:00'
assert erasure['device']['id'] == storage['id'] assert erasure['device']['id'] == storage['id']
for step in erasure['steps']: step1, step2 = erasure['steps']
assert step['type'] == 'StepZero' assert step1['type'] == 'StepZero'
assert step['severity'] == 'Info' assert step1['severity'] == 'Info'
assert 'num' not in step assert 'num' not in step1
assert step2['type'] == 'StepRandom'
assert step2['severity'] == 'Info'
assert 'num' not in step2
assert ['HMG_IS5'] == erasure['standards']
assert storage['privacy']['type'] == 'EraseSectors' assert storage['privacy']['type'] == 'EraseSectors'
pc, _ = user.get(res=m.Device, item=snapshot['device']['id']) pc, _ = user.get(res=m.Device, item=snapshot['device']['id'])
assert pc['privacy'] == [storage['privacy']] assert pc['privacy'] == [storage['privacy']]

View file

@ -263,7 +263,6 @@ def test_snapshot_real_eee_1001pxd(user: UserClient):
erase = next(e for e in hdd['events'] if e['type'] == em.EraseBasic.t) erase = next(e for e in hdd['events'] if e['type'] == em.EraseBasic.t)
assert erase['endTime'] assert erase['endTime']
assert erase['startTime'] assert erase['startTime']
assert erase['zeros'] is False
assert erase['severity'] == 'Info' assert erase['severity'] == 'Info'
assert hdd['privacy'] == 'EraseBasic' assert hdd['privacy'] == 'EraseBasic'
mother = components[8] mother = components[8]