Beispiel #1
0
    async def validate(self, connection: SQLConnectionInterface, model: Model,
                       _type: ValidationTypes):
        if _type == ValidationTypes.CREATE:

            if model["art"].value == MeldungsArt.MANUELL:
                await model.validate_not_empty(['personal.uuid'])
            else:
                await model.validate_not_empty(['beobachter.id'])

            await model.validate_not_empty(['raum.id', 'beschreibung'])

        if not model["raum"]["id"].empty:
            if await self.raum_controller.get(connection,
                                              model["raum"]) is None:
                raise ValidationError(["raum.id"], "Raum existiert nicht.")

        if not model["sensor"]["dev_eui"].empty:
            # Prüft das der Sensor im ausgewählten Raum liegt.
            sensor = await self.sensor_controller.get(connection,
                                                      model["sensor"])
            if sensor is None:
                raise ValidationError(["sensor.dev_eui"],
                                      "Sensor existiert nicht.")
            elif sensor["raum"]["id"].value != model["raum"]["id"].value:
                raise ValidationError(['sensor.dev_eui', 'raum.id'],
                                      "Sensor liegt nicht im Raum.")

        sanitize_fields(model, ['beschreibung'])
Beispiel #2
0
    async def validate(self, connection: SQLConnectionInterface, model: Model,
                       _type: ValidationTypes):
        """Validiert den Namen-"""
        if _type == ValidationTypes.CREATE:
            await model.validate_not_empty(['name'])

        sanitize_fields(model, ['name'])
Beispiel #3
0
    async def validate(self, connection: SQLConnectionInterface, model: Model, _type: ValidationTypes):
        """Validiert ob die UUID bereits gesetzt wurde vor dem Erstellen.
        Dies ist nicht erlaubt. Zudem wird der Inhalt auf HTML Tags geprüft.

        Args:
            connection: Verbindung zur Datenbank.
            model: Personal Modell.
            _type: Art der Validierung.
        """

        if _type == ValidationTypes.CREATE:

            if model["uuid"].value is not None:
                raise ValidationError(['uuid'], "UUID can not be set in advance.")

            await model.validate_not_empty(['name', 'benutzername', 'passwort', 'rolle'])

            stmt = "SELECT uuid FROM logins WHERE username=$1 LIMIT 1"
            if await connection.fetch_row(stmt, model["benutzername"].value) is not None:
                raise ValidationError(['benutzername'], "Benutzername existiert bereits.")
        elif _type == ValidationTypes.UPDATE:
            stmt = "SELECT uuid FROM logins WHERE uuid!=$1 AND username=$2 LIMIT 1"
            if await connection.fetch_row(stmt, model["uuid"].value, model[
                "benutzername"].value) is not None:
                raise ValidationError(['benutzername'],
                                      "Benutzername existiert bereits.")

        sanitize_fields(model, ['name', 'benutzername'])
Beispiel #4
0
    async def validate(self, connection: SQLConnectionInterface, model: Model,
                       _type: ValidationTypes):
        """Prüft, dass der Name nicht leer ist."""

        if _type == ValidationTypes.CREATE:
            await model.validate_not_empty(['name'])

        sanitize_fields(model, ['name'])
Beispiel #5
0
def test_sanitize_fields():
    mock = Mock()
    mock['name'].value = '<script>alert("Böse");</script>'
    mock['nested']['name'].value = '<script>alert("Böse");</script>'
    sanitize_fields(mock, ['name', 'nested.name'])

    assert mock['name'].value == '&lt;script&gt;alert("Böse");&lt;/script&gt;'
    assert mock['nested'][
               'name'].value == '&lt;script&gt;alert("Böse");&lt;/script&gt;'
Beispiel #6
0
    async def validate(self, connection: SQLConnectionInterface, model: Model,
                       _type: ValidationTypes):

        if _type == ValidationTypes.CREATE:
            await model.validate_not_empty(['dev_eui', 'name', 'art', 'raum.id'])

            if await self.get(connection, model) is not None:
                raise ValidationError(['dev_eui'], "Sensor existiert bereits.")

        if not model["raum"]["id"].empty:
            if await self.raum_controller.get(connection, model["raum"]) is None:
                raise ValidationError(['raum.id'], "Raum existiert nicht.")

        sanitize_fields(model, ['name'])
Beispiel #7
0
    async def validate(self, connection: SQLConnectionInterface, model: Model,
                       _type: ValidationTypes):
        """Validiert und prüft dass der Name und die Stockwerk ID nicht leer sind.
        Die Stockwerk ID wird auch geprüft, ob diese auch wirklich korrekt ist."""

        if _type == ValidationTypes.CREATE:
            await model.validate_not_empty(['name', 'stockwerk.id'])

        if not model["stockwerk"]["id"].empty:
            stockwerk = await self.stockwerk_controller.get(
                connection, model["stockwerk"])
            if stockwerk is None:
                raise ValidationError(['stockwerk.id'],
                                      "Stockwerk existiert nicht.")

        sanitize_fields(model, ['name'])
Beispiel #8
0
    async def validate(self, connection: SQLConnectionInterface, model: Model,
                       _type: ValidationTypes):

        if _type == ValidationTypes.CREATE:
            await model.validate_not_empty(['sensor.dev_eui', 'name', 'art'])

            if model["art"].value == BeobachterArt.RICHTWERT_DARUEBER or model[
                    "art"].value == BeobachterArt.RICHTWERT_DARUNTER:
                await model.validate_not_empty(['wertName', 'ausloeserWert'])

        if not model["sensor"]["dev_eui"].empty:
            if await self.sensor_controller.get(connection,
                                                model["sensor"]) is None:
                raise ValidationError(['sensor.dev_eui'],
                                      "Sensor existiert nicht.")

        sanitize_fields(model, ['name', 'wertName'])