Add checking the package name and activity name length

This commit is contained in:
Jonas Lochmann
2020-10-05 02:00:00 +02:00
parent ba3bb50113
commit a767a94430
4 changed files with 35 additions and 3 deletions
+2
View File
@@ -34,6 +34,8 @@ export type AppModelStatic = typeof Sequelize.Model & {
new (values?: object, options?: Sequelize.BuildOptions): AppModel;
}
export const maxPackageNameLength = 255
export const attributes: SequelizeAttributes<AppAttributes> = {
familyId: {
...familyIdColumn,
+3
View File
@@ -32,6 +32,9 @@ export type AppActivityModelStatic = typeof Sequelize.Model & {
new (values?: object, options?: Sequelize.BuildOptions): AppActivityModel;
}
export const maxPackageNameLength = 255
export const maxActivityNameLength = 255
export const attributes: SequelizeAttributes<AppActivityAttributes> = {
familyId: {
...familyIdColumn,
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -17,14 +17,24 @@
import * as Sequelize from 'sequelize'
import { AddInstalledAppsAction } from '../../../../action'
import { AppAttributes } from '../../../../database/app'
import { AppAttributes, maxPackageNameLength } from '../../../../database/app'
import { Cache } from '../cache'
import { ApplyActionException } from '../exception'
export async function dispatchAddInstalledApps ({ deviceId, action, cache }: {
deviceId: string
action: AddInstalledAppsAction
cache: Cache
}) {
action.apps.forEach((app) => {
if (app.packageName.length > maxPackageNameLength) {
throw new ApplyActionException({
staticMessage: 'package name too long',
dynamicMessage: 'package name too long: ' + app.packageName
})
}
})
await cache.database.app.destroy({
where: {
familyId: cache.familyId,
@@ -18,14 +18,31 @@
import { chunk } from 'lodash'
import * as Sequelize from 'sequelize'
import { UpdateAppActivitiesAction } from '../../../../action'
import { AppActivityAttributes } from '../../../../database/appactivity'
import { AppActivityAttributes, maxActivityNameLength, maxPackageNameLength } from '../../../../database/appactivity'
import { Cache } from '../cache'
import { ApplyActionException } from '../exception'
export async function dispatchUpdateAppActivities ({ deviceId, action, cache }: {
deviceId: string
action: UpdateAppActivitiesAction
cache: Cache
}) {
action.updatedOrAdded.forEach((app) => {
if (app.packageName.length > maxPackageNameLength) {
throw new ApplyActionException({
staticMessage: 'package name too long',
dynamicMessage: 'package name too long: ' + app.packageName
})
}
if (app.activityName.length > maxActivityNameLength) {
throw new ApplyActionException({
staticMessage: 'activity name too long',
dynamicMessage: 'activity name too long: ' + app.activityName
})
}
})
if (action.updatedOrAdded.length > 0) {
const chuncks = chunk(action.updatedOrAdded, 500)