Skip to content

Commit c1df354

Browse files
committed
Feature flag
1 parent 49db56a commit c1df354

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Sources/PackageCollections/Providers/JSONPackageCollectionProvider.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Dispatch
1313
import struct Foundation.Data
1414
import struct Foundation.Date
1515
import class Foundation.JSONDecoder
16+
import class Foundation.ProcessInfo
1617
import struct Foundation.URL
1718

1819
import PackageCollectionsModel
@@ -24,6 +25,9 @@ import TSCBasic
2425
private typealias JSONModel = PackageCollectionModel.V1
2526

2627
struct JSONPackageCollectionProvider: PackageCollectionProvider {
28+
// FIXME: remove
29+
static let enableSignatureCheck = ProcessInfo.processInfo.environment["ENABLE_COLLECTION_SIGNATURE_CHECK"] != nil
30+
2731
private let configuration: Configuration
2832
private let diagnosticsEngine: DiagnosticsEngine
2933
private let httpClient: HTTPClient
@@ -120,6 +124,11 @@ struct JSONPackageCollectionProvider: PackageCollectionProvider {
120124
do {
121125
// This fails if collection is not signed (i.e., no "signature")
122126
let signedCollection = try self.decoder.decode(JSONModel.SignedCollection.self, from: data)
127+
128+
if !Self.enableSignatureCheck {
129+
return callback(self.makeCollection(from: signedCollection.collection, source: source, signature: Model.SignatureData(from: signedCollection.signature, isVerified: true)))
130+
}
131+
123132
if source.skipSignatureCheck {
124133
// Don't validate signature; set isVerified=false
125134
callback(self.makeCollection(from: signedCollection.collection, source: source, signature: Model.SignatureData(from: signedCollection.signature, isVerified: false)))

Tests/PackageCollectionsTests/JSONPackageCollectionProviderTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import SPMTestSupport
1919
import TSCBasic
2020
import TSCUtility
2121

22+
private let enableSignatureCheck = JSONPackageCollectionProvider.enableSignatureCheck
23+
2224
class JSONPackageCollectionProviderTests: XCTestCase {
2325
func testGood() throws {
2426
fixture(name: "Collections") { directoryPath in
@@ -396,6 +398,10 @@ class JSONPackageCollectionProviderTests: XCTestCase {
396398
}
397399

398400
func testSigned_skipSignatureCheck() throws {
401+
if !enableSignatureCheck {
402+
try XCTSkipIf(true)
403+
}
404+
399405
fixture(name: "Collections") { directoryPath in
400406
let path = directoryPath.appending(components: "JSON", "good_signed.json")
401407
let url = URL(string: "https://www.test.com/collection.json")!
@@ -460,6 +466,10 @@ class JSONPackageCollectionProviderTests: XCTestCase {
460466
}
461467

462468
func testSigned_noTrustedRootCertsConfigured() throws {
469+
if !enableSignatureCheck {
470+
try XCTSkipIf(true)
471+
}
472+
463473
fixture(name: "Collections") { directoryPath in
464474
let path = directoryPath.appending(components: "JSON", "good_signed.json")
465475
let url = URL(string: "https://www.test.com/collection.json")!
@@ -500,6 +510,10 @@ class JSONPackageCollectionProviderTests: XCTestCase {
500510
}
501511

502512
func testSignedBad() throws {
513+
if !enableSignatureCheck {
514+
try XCTSkipIf(true)
515+
}
516+
503517
fixture(name: "Collections") { directoryPath in
504518
let path = directoryPath.appending(components: "JSON", "good_signed.json")
505519
let url = URL(string: "https://www.test.com/collection.json")!

0 commit comments

Comments
 (0)