remove url as required attribute of manifest.json for safe-apps (#1962)
* remove url as required attribute of manifest.json for safe-apps * getAppInfoFromUrl: get requiredData from manifest
This commit is contained in:
parent
6444c37380
commit
5361aec9ee
|
@ -0,0 +1,48 @@
|
||||||
|
import { isAppManifestValid } from '../utils'
|
||||||
|
import { SafeApp, SAFE_APP_FETCH_STATUS } from '../types.d'
|
||||||
|
|
||||||
|
describe('SafeApp manifest', () => {
|
||||||
|
it('It should return true given a manifest with mandatory values supplied', async () => {
|
||||||
|
const manifest = {
|
||||||
|
name: 'test',
|
||||||
|
description: 'a test',
|
||||||
|
error: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = isAppManifestValid(manifest as SafeApp)
|
||||||
|
expect(result).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('It should return false given a manifest without name', async () => {
|
||||||
|
const manifest = {
|
||||||
|
name: '',
|
||||||
|
description: 'a test',
|
||||||
|
error: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = isAppManifestValid(manifest as SafeApp)
|
||||||
|
expect(result).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('It should return false given a manifest without description', async () => {
|
||||||
|
const manifest = {
|
||||||
|
name: 'test',
|
||||||
|
description: '',
|
||||||
|
error: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = isAppManifestValid(manifest as SafeApp)
|
||||||
|
expect(result).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('It should return false given a manifest with error', async () => {
|
||||||
|
const manifest = {
|
||||||
|
name: 'test',
|
||||||
|
description: 'a test',
|
||||||
|
error: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = isAppManifestValid(manifest as SafeApp)
|
||||||
|
expect(result).toBe(false)
|
||||||
|
})
|
||||||
|
})
|
|
@ -165,8 +165,6 @@ export const isAppManifestValid = (appInfo: SafeApp): boolean =>
|
||||||
appInfo.name !== 'unknown' &&
|
appInfo.name !== 'unknown' &&
|
||||||
// `description` exists
|
// `description` exists
|
||||||
!!appInfo.description &&
|
!!appInfo.description &&
|
||||||
// `url` exists
|
|
||||||
!!appInfo.url &&
|
|
||||||
// no `error` (or `error` undefined)
|
// no `error` (or `error` undefined)
|
||||||
!appInfo.error
|
!appInfo.error
|
||||||
|
|
||||||
|
@ -201,7 +199,7 @@ export const getAppInfoFromUrl = memoize(
|
||||||
const appInfo = await axios.get(`${noTrailingSlashUrl}/manifest.json`, { timeout: 5_000 })
|
const appInfo = await axios.get(`${noTrailingSlashUrl}/manifest.json`, { timeout: 5_000 })
|
||||||
|
|
||||||
// verify imported app fulfil safe requirements
|
// verify imported app fulfil safe requirements
|
||||||
if (!appInfo?.data || isAppManifestValid(appInfo.data)) {
|
if (!appInfo?.data || !isAppManifestValid(appInfo.data)) {
|
||||||
throw Error('The app does not fulfil the structure required.')
|
throw Error('The app does not fulfil the structure required.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,9 +208,16 @@ export const getAppInfoFromUrl = memoize(
|
||||||
const jsonDataLength = 20
|
const jsonDataLength = 20
|
||||||
const remainingSpace = originFieldSize - res.url.length - jsonDataLength
|
const remainingSpace = originFieldSize - res.url.length - jsonDataLength
|
||||||
|
|
||||||
|
const appInfoData = {
|
||||||
|
name: appInfo.data.name,
|
||||||
|
iconPath: appInfo.data.iconPath,
|
||||||
|
description: appInfo.data.description,
|
||||||
|
providedBy: appInfo.data.providedBy,
|
||||||
|
}
|
||||||
|
|
||||||
res = {
|
res = {
|
||||||
...res,
|
...res,
|
||||||
...appInfo.data,
|
...appInfoData,
|
||||||
id: JSON.stringify({ url: res.url, name: appInfo.data.name.substring(0, remainingSpace) }),
|
id: JSON.stringify({ url: res.url, name: appInfo.data.name.substring(0, remainingSpace) }),
|
||||||
error: false,
|
error: false,
|
||||||
loadingStatus: SAFE_APP_FETCH_STATUS.SUCCESS,
|
loadingStatus: SAFE_APP_FETCH_STATUS.SUCCESS,
|
||||||
|
|
Loading…
Reference in New Issue