Skip to content

Commit 1e13874

Browse files
Merge pull request #2870 from SwiftPackageIndex/issue-2868
Issue 2868
2 parents 5d379c7 + 385e76a commit 1e13874

File tree

7 files changed

+75
-9
lines changed

7 files changed

+75
-9
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let package = Package(
3131
.package(url: "https://github.com/MrLotU/SwiftPrometheus.git", from: "1.0.0-alpha"),
3232
.package(url: "https://github.com/SwiftPackageIndex/CanonicalPackageURL.git", from: "0.0.8"),
3333
.package(url: "https://github.com/SwiftPackageIndex/DependencyResolution.git", from: "1.1.2"),
34-
.package(url: "https://github.com/SwiftPackageIndex/SPIManifest.git", from: "1.1.0"),
34+
.package(url: "https://github.com/SwiftPackageIndex/SPIManifest.git", from: "1.1.2"),
3535
.package(url: "https://github.com/SwiftPackageIndex/SemanticVersion.git", from: "0.3.0"),
3636
.package(url: "https://github.com/SwiftPackageIndex/ShellOut.git", from: "3.1.4"),
3737
.package(url: "https://github.com/apple/swift-package-manager.git", revision: "swift-5.9-RELEASE"),

Sources/App/Controllers/ValidateSPIManifestController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ enum ValidateSPIManifestController {
3737

3838
static func validationResult(manifest: String) -> ValidateSPIManifest.ValidationResult {
3939
do {
40-
return .valid(try SPIManifest.Manifest(yml: manifest))
41-
} catch let error as DecodingError {
42-
return .invalid("\(error)")
40+
return .valid(try SPIManifest.Manifest.load(data: Data(manifest.utf8)))
41+
} catch let ManifestError.decodingError(error) {
42+
return .invalid("Decoding failed: \(error)")
43+
} catch let ManifestError.fileTooLarge(size: size) {
44+
return .invalid("File must not exceed \(SPIManifest.Manifest.maxByteSize) bytes. File size: \(size) bytes.")
4345
} catch {
4446
return .invalid(error.localizedDescription)
4547
}

Sources/App/Views/ValidateSPIManifest/ValidateSPIManifest+Model.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum ValidateSPIManifest {
2929
"""
3030
}
3131

32-
enum ValidationResult {
32+
enum ValidationResult: Equatable {
3333
case valid(SPIManifest.Manifest)
3434
case invalid(String)
3535

Sources/App/Views/ValidateSPIManifest/ValidateSPIManifest+View.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ extension ValidateSPIManifest {
6767
.autofocus(true),
6868
.rows(15),
6969
.text(model.manifest),
70-
.attribute(named: "maxlength", value: "\(SPIManifest.Manifest.maxByteSize)")
70+
// allow more than maxByteSize so we can correctly report on files that are too large
71+
.attribute(named: "maxlength", value: "\(SPIManifest.Manifest.maxByteSize + 100)")
7172
)
7273
),
7374
.button(
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import XCTest
16+
17+
@testable import App
18+
19+
import SPIManifest
20+
21+
22+
final class ValidateSPIManifestControllerTests: XCTestCase {
23+
24+
func test_validationResult_basic() throws {
25+
let yml = ValidateSPIManifest.Model.placeholderManifest
26+
27+
// MUT
28+
let res = ValidateSPIManifestController.validationResult(manifest: yml)
29+
30+
// validate
31+
XCTAssertEqual(res, .valid(try SPIManifest.Manifest(yml: yml)))
32+
}
33+
34+
func test_validationResult_decodingError() throws {
35+
let yml = """
36+
broken:
37+
"""
38+
39+
// MUT
40+
let res = ValidateSPIManifestController.validationResult(manifest: yml)
41+
42+
// validate
43+
XCTAssertEqual(res, .invalid("Decoding failed: Key not found: 'version'."))
44+
}
45+
46+
func test_validationResult_tooLarge() throws {
47+
let targets = (0..<200).map { "Target_\($0)" }.joined(separator: ", ")
48+
let yml = """
49+
version: 1
50+
builder:
51+
configs:
52+
- documentation_targets: [\(targets)]
53+
"""
54+
XCTAssert(yml.count > SPIManifest.Manifest.maxByteSize)
55+
56+
// MUT
57+
let res = ValidateSPIManifestController.validationResult(manifest: yml)
58+
59+
// validate
60+
XCTAssertEqual(res, .invalid("File must not exceed \(SPIManifest.Manifest.maxByteSize) bytes. File size: \(yml.count) bytes."))
61+
}
62+
63+
}

Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_ValidateSPIManifest_show.1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h2 class="trimmed">Validate a Swift Package Index manifest</h2>
7777
<p>Enter the contents of a
7878
<code>.spi.yml</code> file for validation:
7979
</p>
80-
<textarea name="manifest" autofocus rows="15" maxlength="1000">version: 1
80+
<textarea name="manifest" autofocus rows="15" maxlength="1600">version: 1
8181
builder:
8282
configs:
8383
- documentation_targets: [Target1, Target2]</textarea>

0 commit comments

Comments
 (0)