Skip to content

Commit 75679ea

Browse files
committed
Drop PackageCollectionsSigning
1 parent 8773395 commit 75679ea

File tree

6 files changed

+144
-238
lines changed

6 files changed

+144
-238
lines changed

Sources/App/Controllers/API/API+PackageCollectionController.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import Fluent
1616
import PackageCollectionsModel
17-
import PackageCollectionsSigning
1817
import Vapor
1918

2019

@@ -23,14 +22,14 @@ extension API {
2322
enum PackageCollectionController {
2423

2524
@Sendable
26-
static func generate(req: Request) async throws -> SignedCollection {
25+
static func generate(req: Request) async throws -> PackageCollection {
2726
AppMetrics.apiPackageCollectionGetTotal?.inc()
2827

2928
let dto = try req.content.decode(PostPackageCollectionDTO.self)
3029

3130
switch dto.selection {
3231
case let .author(author):
33-
return try await SignedCollection.generate(
32+
return try await PackageCollection.generate(
3433
db: req.db,
3534
filterBy: .author(author),
3635
authorName: dto.authorName ?? "Swift Package Index",
@@ -44,7 +43,7 @@ extension API {
4443
guard packageURLs.count <= 20 else {
4544
throw Abort(.badRequest)
4645
}
47-
return try await SignedCollection.generate(
46+
return try await PackageCollection.generate(
4847
db: req.db,
4948
filterBy: .urls(packageURLs),
5049
authorName: dto.authorName ?? "Swift Package Index",
@@ -61,7 +60,7 @@ extension API {
6160
}
6261

6362

64-
extension PackageCollectionSigning.Model.SignedCollection: Vapor.Content {}
63+
extension PackageCollectionModel.V1.Collection: Vapor.Content {}
6564

6665

6766
extension API {

Sources/App/Controllers/PackageCollectionController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Vapor
1717

1818
enum PackageCollectionController {
1919
@Sendable
20-
static func generate(req: Request) async throws -> SignedCollection {
20+
static func generate(req: Request) async throws -> PackageCollection {
2121
AppMetrics.packageCollectionGetTotal?.inc()
2222

2323
guard let collectionType = getCollectionType(req: req) else {
@@ -27,13 +27,13 @@ enum PackageCollectionController {
2727
do {
2828
switch collectionType {
2929
case let .author(owner):
30-
return try await SignedCollection.generate(
30+
return try await PackageCollection.generate(
3131
db: req.db,
3232
filterBy: .author(owner),
3333
authorName: "\(owner) via the Swift Package Index"
3434
)
3535
case let .keyword(keyword):
36-
return try await SignedCollection.generate(
36+
return try await PackageCollection.generate(
3737
db: req.db,
3838
filterBy: .keyword(keyword),
3939
authorName: "Swift Package Index",
@@ -45,7 +45,7 @@ enum PackageCollectionController {
4545
case let .custom(key):
4646
let collection = try await CustomCollection.find(on: req.db, key: key)
4747
.unwrap(or: Abort(.notFound))
48-
return try await SignedCollection.generate(
48+
return try await PackageCollection.generate(
4949
db: req.db,
5050
filterBy: .customCollection(key),
5151
authorName: "Swift Package Index",

Sources/App/Core/Dependencies/EnvironmentClient.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,7 @@ extension EnvironmentClient: DependencyKey {
100100
.flatMap(Double.init)
101101
?? 1.0
102102
},
103-
collectionSigningCertificateChain: {
104-
[
105-
"package_collections.cer",
106-
"AppleWWDRCAG3.cer",
107-
"AppleIncRootCertificate.cer",
108-
].map { SignedCollection.certsDir.appendingPathComponent($0) }
109-
},
103+
collectionSigningCertificateChain: { [] },
110104
collectionSigningPrivateKey: {
111105
Environment.get("COLLECTION_SIGNING_PRIVATE_KEY").map { Data($0.utf8) }
112106
},

Sources/App/Core/PackageCollection+signing.swift

Lines changed: 0 additions & 84 deletions
This file was deleted.

Tests/AppTests/ApiTests.swift

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
@testable import App
1616

1717
import Dependencies
18-
import PackageCollectionsSigning
1918
import SnapshotTesting
2019
import Testing
2120
import XCTVapor
@@ -845,76 +844,76 @@ extension AllTests.ApiTests {
845844
}
846845
}
847846

848-
@Test(.disabled(if: !isRunningInCI() && EnvironmentClient.liveValue.collectionSigningPrivateKey() == nil,
849-
"Skip test for local user due to unset COLLECTION_SIGNING_PRIVATE_KEY env variable"))
850-
func package_collections_owner() async throws {
851-
let event = App.ActorIsolated<TestEvent?>(nil)
852-
try await withDependencies {
853-
$0.date.now = .t0
854-
$0.environment.apiSigningKey = { "secret" }
855-
$0.environment.collectionSigningCertificateChain = EnvironmentClient.liveValue.collectionSigningCertificateChain
856-
$0.environment.collectionSigningPrivateKey = EnvironmentClient.liveValue.collectionSigningPrivateKey
857-
$0.httpClient.postPlausibleEvent = { @Sendable kind, path, _ in
858-
await event.setValue(.init(kind: kind, path: path))
859-
}
860-
} operation: {
861-
try await withApp { app in
862-
// setup
863-
let p1 = Package(id: .id1, url: "1")
864-
try await p1.save(on: app.db)
865-
try await Repository(package: p1,
866-
defaultBranch: "main",
867-
name: "name 1",
868-
owner: "foo",
869-
summary: "foo bar package").save(on: app.db)
870-
let v = try Version(package: p1,
871-
latest: .release,
872-
packageName: "Foo",
873-
reference: .tag(1, 2, 3),
874-
toolsVersion: "5.0")
875-
try await v.save(on: app.db)
876-
try await Product(version: v, type: .library(.automatic), name: "lib")
877-
.save(on: app.db)
878-
879-
do { // MUT
880-
let body: ByteBuffer = .init(string: """
881-
{
882-
"revision": 3,
883-
"authorName": "author",
884-
"keywords": [
885-
"a",
886-
"b"
887-
],
888-
"selection": {
889-
"author": {
890-
"_0": "foo"
891-
}
892-
},
893-
"collectionName": "my collection",
894-
"overview": "my overview"
895-
}
896-
""")
897-
898-
try await app.test(.POST, "api/package-collections",
899-
headers: .bearerApplicationJSON(try .apiToken(secretKey: "secret", tier: .tier3)),
900-
body: body,
901-
afterResponse: { res async throws in
902-
// validation
903-
#expect(res.status == .ok)
904-
let container = try res.content.decode(SignedCollection.self)
905-
#expect(!container.signature.signature.isEmpty)
906-
// more details are tested in PackageCollectionTests
907-
#expect(container.collection.name == "my collection")
908-
})
909-
}
910-
911-
// ensure API event has been reported
912-
await event.withValue {
913-
#expect($0 == .some(.init(kind: .pageview, path: .packageCollections)))
914-
}
915-
}
916-
}
917-
}
847+
// @Test(.disabled(if: !isRunningInCI() && EnvironmentClient.liveValue.collectionSigningPrivateKey() == nil,
848+
// "Skip test for local user due to unset COLLECTION_SIGNING_PRIVATE_KEY env variable"))
849+
// func package_collections_owner() async throws {
850+
// let event = App.ActorIsolated<TestEvent?>(nil)
851+
// try await withDependencies {
852+
// $0.date.now = .t0
853+
// $0.environment.apiSigningKey = { "secret" }
854+
// $0.environment.collectionSigningCertificateChain = EnvironmentClient.liveValue.collectionSigningCertificateChain
855+
// $0.environment.collectionSigningPrivateKey = EnvironmentClient.liveValue.collectionSigningPrivateKey
856+
// $0.httpClient.postPlausibleEvent = { @Sendable kind, path, _ in
857+
// await event.setValue(.init(kind: kind, path: path))
858+
// }
859+
// } operation: {
860+
// try await withApp { app in
861+
// // setup
862+
// let p1 = Package(id: .id1, url: "1")
863+
// try await p1.save(on: app.db)
864+
// try await Repository(package: p1,
865+
// defaultBranch: "main",
866+
// name: "name 1",
867+
// owner: "foo",
868+
// summary: "foo bar package").save(on: app.db)
869+
// let v = try Version(package: p1,
870+
// latest: .release,
871+
// packageName: "Foo",
872+
// reference: .tag(1, 2, 3),
873+
// toolsVersion: "5.0")
874+
// try await v.save(on: app.db)
875+
// try await Product(version: v, type: .library(.automatic), name: "lib")
876+
// .save(on: app.db)
877+
//
878+
// do { // MUT
879+
// let body: ByteBuffer = .init(string: """
880+
// {
881+
// "revision": 3,
882+
// "authorName": "author",
883+
// "keywords": [
884+
// "a",
885+
// "b"
886+
// ],
887+
// "selection": {
888+
// "author": {
889+
// "_0": "foo"
890+
// }
891+
// },
892+
// "collectionName": "my collection",
893+
// "overview": "my overview"
894+
// }
895+
// """)
896+
//
897+
// try await app.test(.POST, "api/package-collections",
898+
// headers: .bearerApplicationJSON(try .apiToken(secretKey: "secret", tier: .tier3)),
899+
// body: body,
900+
// afterResponse: { res async throws in
901+
// // validation
902+
// #expect(res.status == .ok)
903+
// let container = try res.content.decode(SignedCollection.self)
904+
// #expect(!container.signature.signature.isEmpty)
905+
// // more details are tested in PackageCollectionTests
906+
// #expect(container.collection.name == "my collection")
907+
// })
908+
// }
909+
//
910+
// // ensure API event has been reported
911+
// await event.withValue {
912+
// #expect($0 == .some(.init(kind: .pageview, path: .packageCollections)))
913+
// }
914+
// }
915+
// }
916+
// }
918917

919918
@Test(.disabled(if: !isRunningInCI() && EnvironmentClient.liveValue.collectionSigningPrivateKey() == nil,
920919
"Skip test for local user due to unset COLLECTION_SIGNING_PRIVATE_KEY env variable"))

0 commit comments

Comments
 (0)