Test that README urls are secure

This commit is contained in:
Sam Carlton 2021-11-29 00:01:28 -06:00
parent 4ba4a92e68
commit b28303305e

View file

@ -2,6 +2,7 @@ import fs from 'fs-extra'
import test from 'ava' import test from 'ava'
// import MarkdownIt from 'markdown-it' // import MarkdownIt from 'markdown-it'
import { isValidHttpUrl } from '../helpers/check-types.js'
import { buildReadmeAppList } from '../helpers/build-app-list.js' import { buildReadmeAppList } from '../helpers/build-app-list.js'
@ -12,11 +13,6 @@ require('dotenv').config()
const allowedTitleCharacters = new Set( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 -_.®/\()音乐体验版'.split('') ) const allowedTitleCharacters = new Set( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 -_.®/\()音乐体验版'.split('') )
function isString( maybeString ) {
return (typeof maybeString === 'string' || maybeString instanceof String)
}
test.before(async t => { test.before(async t => {
const readmeFileContent = await fs.readFile('./README.md', 'utf-8') const readmeFileContent = await fs.readFile('./README.md', 'utf-8')
@ -30,7 +26,7 @@ test.before(async t => {
}) })
}) })
test('README App Titles are alphanumeric only', (t) => { test('README Apps are formated correctly', (t) => {
// console.log('t.context.sitemapUrls', t.context.sitemapUrls) // console.log('t.context.sitemapUrls', t.context.sitemapUrls)
const { const {
@ -44,6 +40,15 @@ test('README App Titles are alphanumeric only', (t) => {
for (const readmeApp of readmeAppList) { for (const readmeApp of readmeAppList) {
const cleanedAppName = readmeApp.name//.toLowerCase() const cleanedAppName = readmeApp.name//.toLowerCase()
// Check that all related links urls are valid
for (const relatedLink of readmeApp.relatedLinks) {
if ( !isValidHttpUrl( relatedLink.href ) ) {
t.log('relatedLink.href', readmeApp.name, relatedLink.href)
t.fail(`README App ${readmeApp.name} does not have valid url`, readmeApp.url)
}
}
for ( const character of cleanedAppName ) { for ( const character of cleanedAppName ) {
if ( !allowedTitleCharacters.has( character ) ) { if ( !allowedTitleCharacters.has( character ) ) {