Skip to content

Commit

Permalink
fix(schema): Curly bracket support in URL validation (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Oct 16, 2021
1 parent 8214f67 commit 7255a0c
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5)

- **schema**: Fix validation for curly bracket variables in autoupdate
- Internal modules/libs are loaded only when not loaded already
- **scoop-install**: Fix independent installations
- Initial support for manipulation with `arm64` based manifests
Expand Down
2 changes: 2 additions & 0 deletions bin/format.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ foreach ($gci in Get-ChildItem $Dir "$App.*" -File) {
}
#endregion Architecture properties sort

if ($manifest.'$schema') { $manifest.PSObject.Properties.Remove('$schema') }

$newManifest = [PSCustomObject] @{ }
# Add informational properties in special order ranked by usability into new object and remove from old object
# Comment for maintainers has to be at first
Expand Down
53 changes: 32 additions & 21 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,7 @@
},
"url": {
"description": "Specifies the URL of webpage/file which contains information about file integrity.",
"anyOf": [
{
"type": "string",
"format": "uri"
},
{
"type": "string",
"pattern": "^(\\$url|\\$baseurl).[\\w\\d]+$"
},
{
"type": "string",
"pattern": "^.*(\\$url|\\$baseurl).*$"
}
]
"$ref": "#/definitions/autoupdateHashUrl"
}
}
},
Expand Down Expand Up @@ -376,14 +363,39 @@
}
]
},
"autoupdateUrl": {
"description": "Specifies URL to be updated.",
"anyOf": [
{
"type": "string",
"format": "uri"
},
{
"type": "string",
"pattern": "^https?://[\\w/?=&%._${}#-]+"
}
]
},
"autoupdateHashUrl": {
"description": "Specifies URL to be updated.",
"anyOf": [
{
"type": "string",
"$ref": "#/definitions/autoupdateUrl"
},
{
"type": "string",
"pattern": "^(\\$\\{?(base)?url\\}?).*$"
}
]
},
"autoupdateArchitecture": {
"type": "object",
"additionalProperties": false,
"properties": {
"url": {
"description": "Specifies URLs to be updated.",
"type": "string",
"format": "uri"
"description": "Specifies URL to be updated.",
"$ref": "#/definitions/autoupdateUrl"
},
"hash": {
"description": "Specifies how hashes are extracted.",
Expand All @@ -396,7 +408,7 @@
}
},
"autoupdate": {
"description": "Specifies how the manifest is updated with different version.",
"description": "Specifies what properies (and how) should be updated when performing autoupdate.",
"type": "object",
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -433,8 +445,7 @@
},
"url": {
"description": "Specifies the URL to be updated",
"type": "string",
"format": "uri"
"$ref": "#/definitions/autoupdateUrl"
},
"hash": {
"description": "Specifies how the hashes are extracted",
Expand All @@ -453,7 +464,7 @@
},
"properties": {
"$schema": {
"description": "Specifies which schema file should be used for intellisense/code-completion in text editor.",
"description": "Specify the path to the json schema, used for validation of the json file and extended editors support (intellisense/code-completion)",
"type": "string"
},
"##": {
Expand Down
8 changes: 4 additions & 4 deletions test/Scoop-Format-Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Describe 'Pretty json formating' -Tag 'Scoop' {

Context 'Beautify manifest' {
$manifests | ForEach-Object {
if ($PSVersionTable.PSVersion.Major -gt 5) { $_ = $_.Name } # Fix for pwsh
$name = if ($PSVersionTable.PSVersion.Major -gt 5) { $_.Name } else { $_ } # Fix for pwsh

It "$_" {
$pretty_json = (parse_json "$format\unformated\$_") | ConvertToPrettyJson
$correct = (Get-Content "$format\formated\$_") -join "`r`n"
It "$name" {
$pretty_json = (parse_json "$format\unformated\$name") | ConvertToPrettyJson
$correct = (Get-Content "$format\formated\$name") -join "`r`n"
$correct.CompareTo($pretty_json) | Should Be 0
}
}
Expand Down
17 changes: 16 additions & 1 deletion test/Scoop-Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ Describe -Tag 'Manifests' 'manifest-validation' {
$validator.Errors | Select-Object -First 1 | Should -Match "Property 'randomproperty' has not been defined and the schema does not allow additional properties\."
$validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version, description\.'
}
It 'fail with nonsense in autoupdate' {
$validator = New-Object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/autoupdate_fail.json") | Should -BeFalse
$validator.Errors.Count | Should -Not -Be 0
# URL should contain URI or uri with {}, but not $(base)?url
@($validator.Errors)[0] | Should -Match 'from ''anyOf'''
@($validator.Errors)[1] | Should -Match '\$baseurl/'
# Hash has to contain $url/$baseurl or uri
@($validator.Errors)[-1] | Should -Match 'nonhttps/'
}
It 'pass with curly brackets in autoupdate' {
$validator = New-Object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/autoupdate.json") | Should -BeTrue
$validator.Errors.Count | Should -Be 0
}
}

Context 'manifest validates against the schema' {
Expand All @@ -69,7 +84,7 @@ Describe -Tag 'Manifests' 'manifest-validation' {

# Filter out valid manifests
foreach ($ext in $ALLOWED_MANIFEST_EXTENSION) {
$manifest_files += $allFiles | Where-Object { $_ -like "*.$ext" }
$manifest_files += $allFiles | Where-Object -Property 'Name' -Like -Value "*.$ext"
}

$validator = New-Object Scoop.Validator($schema, $true)
Expand Down
35 changes: 35 additions & 0 deletions test/fixtures/manifest/autoupdate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "16.3.20211004",
"description": "Visual Paradigm Community Edition. UML CASE Tool supporting UML 2, SysML and Business Process Modeling Notation from the Object Management Group.",
"homepage": "https://www.visual-paradigm.com",
"license": {
"identifier": "Trialware",
"url": "https://www.visual-paradigm.com/product/licenseagreement.jsp?product=vp&edition=ce"
},
"architecture": {
"64bit": {
"url": "https://uk3.dl.visual-paradigm.com/visual-paradigm/vpce16.3/20211004/Visual_Paradigm_CE_16_3_20211004_Win64_InstallFree.zip",
"hash": "adadf9ddb33f55e261f4a97805a405e956caf3d861fca98c2bf1f5480b633197"
}
},
"checkver": {
"url": "https://www.visual-paradigm.com/download/community.jsp",
"regex": "Version:\\s*(?<ver>[\\d.]+).*Build number:\\s*(?<build>(\\d{8}))",
"replace": "${ver}.${build}"
},
"autoupdate": {
"architecture": {
"64bit": {
"url": "https://uk3.dl.visual-paradigm.com/visual-paradigm/vpce$majorVersion.$minorVersion/$patchVersion/Visual_Paradigm_CE_${underscoreVersion}_Win64_InstallFree.zip#/alfa.something"
},
"32bit": {
"url": "https://uk3.dl.visual-paradigm.com/visual-paradigm/vpce$majorVersion.$minorVersion/$patchVersion/Visual_Paradigm_CE_$underscoreVersion_Win64_InstallFree.zip"
}
},
"hash": {
"url": "$url/checksum.html",
"regex": "$basename\\s*</td>\\s*<td>\\s*sha256: $sha256"
},
"extract_dir": "Visual Paradigm CE ${majorVersion}.${minorVersion}"
}
}
31 changes: 31 additions & 0 deletions test/fixtures/manifest/autoupdate_fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "../../../schema.json",
"version": "16.3.20211004",
"description": "Visual Paradigm Community Edition. UML CASE Tool supporting UML 2, SysML and Business Process Modeling Notation from the Object Management Group.",
"homepage": "https://www.visual-paradigm.com",
"license": {
"identifier": "Trialware",
"url": "https://www.visual-paradigm.com/product/licenseagreement.jsp?product=vp&edition=ce"
},
"architecture": {
"64bit": {
"url": "https://uk3.dl.visual-paradigm.com/visual-paradigm/vpce16.3/20211004/Visual_Paradigm_CE_16_3_20211004_Win64_InstallFree.zip",
"hash": "adadf9ddb33f55e261f4a97805a405e956caf3d861fca98c2bf1f5480b633197"
}
},
"autoupdate": {
"architecture": {
"64bit": {
"url": "$baseurl/visual-paradigm/vpce$majorVersion.$minorVersion/$patchVersion/Visual_Paradigm_CE_${underscoreVersion}_Win64_InstallFree.zip#/alfa.something"
},
"32bit": {
"url": "https://uk3.dl.visual-paradigm.com/visual-paradigm/vpce$majorVersion.$minorVersion/$patchVersion/Visual_Paradigm_CE_${underscoreVersion}_Win64_InstallFree.zip"
}
},
"hash": {
"url": "nonhttps/checksum.html",
"regex": "$basename\\s*</td>\\s*<td>\\s*sha256: $sha256"
},
"extract_dir": "Visual Paradigm CE ${majorVersion}.${minorVersion}"
}
}

0 comments on commit 7255a0c

Please sign in to comment.