Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Commit

Permalink
style(worker): clean up rdnn sanitizing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner committed Jul 11, 2018
1 parent 65e1dd2 commit c648552
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 37 deletions.
12 changes: 11 additions & 1 deletion src/worker/task/appstream/content-rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamContentRating extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamDescription extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/worker/task/appstream/exist.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

AppCenter was unable to find your appstream file. Please ensure you have an
appstream file that is placed in `/usr/share/metainfo`. It should be named
`<%- storage.nameDomain %>.appdata.xml`.
`<%- name %>.appdata.xml`.

### For more information, see:
- [The AppStream Quickstart Guide](https://www.freedesktop.org/software/appstream/docs/chap-Quickstart.html)
Expand Down
31 changes: 23 additions & 8 deletions src/worker/task/appstream/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,31 @@ import { Task } from '../task'

export class AppstreamId extends Task {

/**
* Returns what the appstream ID should be
*
* @return {string}
*/
public get id () {
return sanitize(this.worker.context.nameDomain, '_')
}

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
const name = sanitize(this.worker.context.nameDomain, '-')

return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${name}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand All @@ -35,18 +51,17 @@ export class AppstreamId extends Task {
const $ = cheerio.load(raw, { xmlMode: true })

const id = $('component > id')
const appstreamId = sanitize(this.worker.context.nameDomain, '_')

if (id.length === 0) {
$('component').prepend(`<id>${appstreamId}</id>`)
$('component').prepend(`<id>${this.id}</id>`)
await fs.writeFile(this.path, $.xml())

throw new Log(Log.Level.WARN, 'Missing "id" field')
} else if (id.text() !== appstreamId) {
id.text(appstreamId)
} else if (id.text() !== this.id) {
id.text(this.id)
await fs.writeFile(this.path, $.xml())

throw new Log(Log.Level.WARN, `"id" field should be "${appstreamId}"`)
throw new Log(Log.Level.WARN, `"id" field should be "${this.id}"`)
}
}
}
13 changes: 12 additions & 1 deletion src/worker/task/appstream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { WrapperTask } from '../wrapperTask'

Expand Down Expand Up @@ -59,13 +60,22 @@ export class Appstream extends WrapperTask {
}
}

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down Expand Up @@ -102,6 +112,7 @@ export class Appstream extends WrapperTask {
const template = path.resolve(__dirname, 'exist.md')

throw Log.template(Log.Level.ERROR, template, {
name: this.name,
storage: this.worker.context
})
}
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamLicense extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamName extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/worker/task/appstream/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'
import * as sanitize from 'sanitize-html'
import * as sanitizeHtml from 'sanitize-html'
import * as semver from 'semver'

import markdown from '../../../lib/utility/markdown'
import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

Expand All @@ -33,13 +34,22 @@ export class AppstreamRelease extends Task {
xmlMode: true
}

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down Expand Up @@ -141,7 +151,7 @@ export class AppstreamRelease extends Task {
protected sanitize (change) {
const $el = cheerio.load(change, AppstreamRelease.CHEERIO_OPTS)

const sanitized = sanitize($el.xml(), {
const sanitized = sanitizeHtml($el.xml(), {
allowedTags: AppstreamRelease.WHITELISTED_TAGS,
parser: AppstreamRelease.CHEERIO_OPTS
})
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamScreenshot extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamStripe extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ import * as cheerio from 'cheerio'
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Log } from '../../log'
import { Task } from '../task'

export class AppstreamSummary extends Task {

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path the appstream file should exist at
*
* @return {string}
*/
public get path () {
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.worker.context.nameDomain}.appdata.xml`)
return path.resolve(this.worker.workspace, 'package/usr/share/metainfo', `${this.name}.appdata.xml`)
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/worker/task/appstream/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as fs from 'fs-extra'
import * as path from 'path'

import { sanitize } from '../../../lib/utility/rdnn'
import { Docker } from '../../docker'
import { Log } from '../../log'
import { Task } from '../task'
Expand All @@ -20,6 +21,15 @@ export class AppstreamValidate extends Task {
return path.resolve(this.worker.workspace, 'appstream.log')
}

/**
* Returns the main appstream file name
*
* @return {string}
*/
public get name () {
return sanitize(this.worker.context.nameDomain, '-')
}

/**
* Path to folder containing the appstream file
*
Expand All @@ -38,7 +48,7 @@ export class AppstreamValidate extends Task {
public async run () {
const docker = await this.docker()

const file = `${this.worker.context.nameDomain}.appdata.xml`
const file = `${this.name}.appdata.xml`
const cmd = `validate ${file} --no-color`
const exit = await docker.run(cmd)

Expand Down
Loading

0 comments on commit c648552

Please sign in to comment.