Skip to content

Commit

Permalink
Fix multiple correctness issues (#2978)
Browse files Browse the repository at this point in the history
* Fix dangerous undefined behavior in StackTrace on Linux, add missing locks on logging and metrics mocks in async tests (can't really make them actors).
* Eliminate several runtime aborts during stacktrace gathering (out of bounds indexing, subtraction underflow, incorrect construction of width values)
* Fix misc. warnings (5.8 deprecations, unused declaration using @_silgen_name)
* Remove `#if compiler(>=5.5) && canImport(_Concurrency)` conditionals and `@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)` annotations. We now already require a higher minimum Swift version and the same minimum platform versions; the conditions are just noise now.
* Change Deployment to: have an embedded self-signed TLS cert instead of referring to Tanner's computer, make MemoryCache an actor, have an async entry point, use #fileID, and load a streamed response file from a resource instead of Tanner's computer
* Deprecate the heck out of DecoderUnwrapper, which should never have existed
* Huge cleanups to PlaintextEncoder and PlaintextDecoder to get rid of multiple fatalError()s and vastly improve both performance and correctness.
* Fix numerous issues with the Codable behaviors of URLEncodedFormDecoder and URLEncodedFormEncoder
* Make all content coders and url query coders capable of correctly handling userInfo dictionaries to be passed to the underlying coder implementations.
* Deprecate ValidationKey in favor of using BasicCodingKey directly
* Overhaul Validation to get rid of a ton of Codable misuse
* Minor README update
* Heavy comments cleanup for ContentConfiguration, improve errors it throws, add userInfo specification to JSON*Coder.custom(...)
* Fix another round of Codable shenanigans in ContentContainer and URLQueryContainer. More performant for good measure.
* Temporarily pin APNS provider check
  • Loading branch information
gwynne committed Apr 2, 2023
1 parent 4709b92 commit ba1a308
Show file tree
Hide file tree
Showing 66 changed files with 1,103 additions and 1,141 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/test.yml
@@ -1,8 +1,14 @@
name: test
on: { pull_request: {} }
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [ main ] }

jobs:
test-providers:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
Expand All @@ -12,6 +18,10 @@ jobs:
- vapor/leaf
- vapor/queues
- vapor/apns
include:
- ref: main
- provider: vapor/apns
ref: 3.0.0
runs-on: ubuntu-latest
container: swift:5.7-jammy
steps:
Expand All @@ -24,13 +34,15 @@ jobs:
with:
repository: ${{ matrix.provider }}
path: provider
ref: ${{ matrix.ref }}
- name: Use local Vapor
run: swift package --package-path ./provider edit vapor --path ./vapor
- name: Run tests with Thread Sanitizer
- name: Run tests
env:
SWIFT_DETERMINISTIC_HASHING: 1
run: swift test --sanitize=thread
run: swift test
working-directory: provider

unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@reusable-workflows
with:
Expand Down
25 changes: 15 additions & 10 deletions Package.swift
Expand Up @@ -92,16 +92,21 @@ let package = Package(
]),

// Development
.executableTarget(name: "Development", dependencies: [
.target(name: "Vapor"),
], swiftSettings: [
// Enable better optimizations when building in Release configuration. Despite the use of
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
// builds. See <https://github.com/swift-server/guides#building-for-production> for details.
.unsafeFlags([
"-cross-module-optimization"
], .when(configuration: .release)),
]),
.executableTarget(
name: "Development",
dependencies: [
.target(name: "Vapor"),
],
resources: [.copy("Resources")],
swiftSettings: [
// Enable better optimizations when building in Release configuration. Despite the use of
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
// builds. See <https://github.com/swift-server/guides#building-for-production> for details.
.unsafeFlags([
"-cross-module-optimization"
], .when(configuration: .release)),
]
),

// Testing
.target(name: "XCTVapor", dependencies: [
Expand Down
7 changes: 3 additions & 4 deletions README.md
@@ -1,5 +1,4 @@
<a href="https://discord.gg/vapor">

<a href="https://discord.gg/vapor">
![Vapor](https://user-images.githubusercontent.com/1342803/75634175-4876d680-5bd9-11ea-90d6-12c7b6a9ee3f.png)
</a>

Expand All @@ -14,10 +13,10 @@
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://github.com/vapor/vapor/actions">
<img src="https://github.com/vapor/vapor/workflows/test/badge.svg?branch=main" alt="Continuous Integration">
<img src="https://github.com/vapor/vapor/actions/workflows/test.yml/badge.svg?branch=main" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="https://img.shields.io/badge/swift-5.2-brightgreen.svg" alt="Swift 5.2">
<img src="https://img.shields.io/badge/swift-5.5-brightgreen.svg" alt="Swift 5.5">
</a>
<a href="https://twitter.com/codevapor">
<img src="https://img.shields.io/badge/twitter-codevapor-5AA9E7.svg" alt="Twitter">
Expand Down
1 change: 1 addition & 0 deletions Sources/Development/Resources/fileio.txt
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut eleifend turpis, quis vestibulum odio. Sed vestibulum, lorem at sagittis mattis, nunc sem euismod augue, id accumsan ipsum turpis bibendum leo. Praesent in faucibus nulla. Sed egestas aliquam velit eu tempor. Quisque egestas risus non justo posuere, id imperdiet erat porta. Phasellus commodo, justo ut volutpat elementum, tortor felis egestas metus, vel congue elit sem in ipsum. Suspendisse potenti. Fusce pharetra pellentesque nulla at blandit. Proin at dui eu ex lacinia tempus. Donec faucibus est vel erat faucibus ullamcorper. Integer vel nisi erat. Sed porta risus magna, eu ultricies massa tempus quis. Donec dignissim fringilla lobortis. Morbi sapien sem, cursus quis sollicitudin id, varius eget purus. Morbi at commodo diam. Duis efficitur blandit nisl nec ultricies. Praesent ultrices nulla eget mattis lobortis. Morbi euismod pharetra purus quis efficitur. Cras nec elit nec purus ullamcorper consequat ut in libero. Duis ultricies hendrerit odio vitae hendrerit. Pellentesque pharetra malesuada purus tincidunt tincidunt. Aliquam volutpat, nisl et porta vehicula, lorem elit ultricies purus, et cursus massa lectus vitae leo. Donec ornare lacinia sem non mollis. Aenean quis nulla vel diam tempus malesuada. Vestibulum in orci purus. Donec et leo luctus, congue massa sed, blandit diam. Aliquam non purus vitae nisl sollicitudin malesuada. Vivamus sed urna convallis, mattis nisi ac, pellentesque dui. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam laoreet erat id vehicula lacinia. In hac habitasse platea dictumst. Duis dapibus, sapien nec dignissim tempus, nulla massa interdum enim, posuere imperdiet nulla justo semper leo. Curabitur tempus rutrum magna, vitae tristique tortor porttitor vitae. Donec molestie nibh sit amet quam elementum, eget maximus neque scelerisque. Pellentesque a elit sed arcu faucibus tempor. Morbi congue, nunc a imperdiet sodales, dolor elit placerat nisl, eu elementum elit mi id diam. Duis pretium quam in tellus scelerisque aliquam. Curabitur egestas euismod nunc, ut tempus est pellentesque sed. Aenean dignissim sodales lorem, quis convallis nibh pretium id. Suspendisse sed elementum lacus. Fusce congue magna hendrerit purus dictum consectetur. Duis ut purus a ipsum facilisis aliquet. Suspendisse nec sollicitudin tellus. Quisque sit amet leo sit amet lorem tincidunt euismod. Cras ut lectus quis lorem fermentum commodo. Quisque euismod non nisi tempor rhoncus. Nam sodales, ante id vehicula pretium, tortor turpis porta ligula, et malesuada ex velit non odio. Proin scelerisque tellus iaculis vulputate tempus. Fusce gravida odio eget dignissim luctus. Phasellus hendrerit ultricies nibh, id consequat libero maximus et. Suspendisse rhoncus orci eget leo fermentum, in pretium ligula fringilla. Ut mollis dictum condimentum. Quisque lacus ipsum, molestie in tristique in, porttitor vel massa. Proin sagittis metus et eleifend rhoncus. Cras porta non turpis vel molestie. Duis bibendum nisl nec lectus cursus pretium. Nam porta nisi id tortor hendrerit, quis feugiat diam eleifend. Ut luctus sagittis nulla. Aliquam at libero lectus. Praesent sed egestas sem, sed tempus neque. Duis ultrices nisl nec laoreet ultricies. Nulla id urna quis lacus tincidunt scelerisque. Sed erat arcu, efficitur sed sagittis nec, venenatis et est. Integer viverra laoreet odio ut posuere. Pellentesque quis libero risus. Ut interdum id magna pellentesque aliquet. Pellentesque id commodo est, a tincidunt ex. Donec elementum urna leo, ac gravida ligula tempus vel. Suspendisse molestie aliquet ligula nec lobortis. Aenean vel elementum massa, at dapibus elit. Fusce ac pellentesque risus, at hendrerit erat. Aenean vel placerat tortor, non finibus risus. Vestibulum ultrices rutrum blandit. Integer id ultrices arcu. Nunc molestie urna vel bibendum imperdiet. Mauris finibus lorem non leo vulputate auctor. Praesent mollis velit vitae magna faucibus venenatis. Donec egestas euismod tortor, quis vehicula elit porta in. Cras tempor justo ut tortor.
78 changes: 45 additions & 33 deletions Sources/Development/configure.swift
@@ -1,54 +1,66 @@
import Vapor
import NIOConcurrencyHelpers
import NIOSSL

public func configure(_ app: Application) throws {
app.logger.logLevel = .debug
app.logger.logLevel = Environment.process.LOG_LEVEL ?? .debug

app.http.server.configuration.hostname = "127.0.0.1"
switch app.environment {
case .tls:
if app.environment == .tls {
app.http.server.configuration.port = 8443
try app.http.server.configuration.tlsConfiguration = .makeServerConfiguration(
certificateChain: [
.certificate(.init(
file: "/Users/tanner0101/dev/vapor/net-kit/certs/cert.pem",
format: .pem
))
],
privateKey: .file("/Users/tanner0101/dev/vapor/net-kit/certs/key.pem")
certificateChain: NIOSSLCertificate.fromPEMBytes(TLSData.sampleServerCertificatePEM).map { .certificate($0) },
privateKey: .privateKey(.init(bytes: TLSData.sampleServerPrivateKeyPEM, format: .pem))
)
default:
app.http.server.configuration.port = 8080
}

// routes
try routes(app)
}

final class MemoryCache {
var storage: [String: String]
var lock: NIOLock
actor MemoryCache {
var storage: [String: String] = [:]

init() {
self.storage = [:]
self.lock = .init()
}

func get(_ key: String) -> String? {
self.lock.lock()
defer { self.lock.unlock() }
return self.storage[key]
}

func set(_ key: String, to value: String?) {
self.lock.lock()
defer { self.lock.unlock() }
self.storage[key] = value
}
func get(_ key: String) -> String? { self.storage[key] }
func set(_ key: String, to value: String?) { self.storage[key] = value }
}

extension Environment {
static var tls: Environment {
return .custom(name: "tls")
static var tls: Environment { .custom(name: "tls") }
}

enum TLSData {
static var sampleServerCertificatePEM: [UInt8] { .init("""
-----BEGIN CERTIFICATE-----
MIIDeTCCAmGgAwIBAgIUMJzqelT95d/JU2Yp4/XHuqhJTs4wDQYJKoZIhvcNAQEL\nBQAwTDELMAkGA1UEBhMCV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pCqfdrOIcDrTK9u/PU9cGdALh
C+4n5ZIHWu66eCvARnqbCTwcOwGMxkKX/4FpI54=
-----END CERTIFICATE-----
""".utf8)
}
static var sampleServerPrivateKeyPEM: [UInt8] { .init("""
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC2rwuxbh8k8BG2\nFBLVAxz3RCwoJWRsqadfqhNV7oUNaj4MexTASlwGGC40shHytRmqKwV3yxlucTR3
0qyWFZoZtlDhjyW2bxbV2Xrn0M/Ad9burH1xCTVmyeivB1GZD8jUSUTkuSAYQ0Yi\nsVEyTk/j4aU9WaKETXf/f7/9CaDOBxFxOKDuyiG+HzOCLlSH03Ym+NmjB+4yjFX1
a+zdszhZ5jHdH5nOctBsf7b69dxDfdpRpUt1ePmE1q+yrLnkGL6ZSYgydBNwIqS1\n0WLWq7Cag51oZLab25J23/S57SiaPci/jugkYn0vMwZ/3KnxaO77iEUMoXdqv53Y
4qkKDqsfAgMBAAECggEANfp17YjY2fy3dwHqaJdhZSx3Eauuxy6/3lPuH6t5E/Qq\n/lwVzxWJqGFXsclV5U2eljndBT71Nj1r3+XXigc6/9Lvhh5aadPcPvbiSoHYCQo/
70j3TcGHTmZlguYaNaxEznkRyrVqptCl9hVHpSIfl/lx7jVAgHA1f0CblWRVZ9qM\nhX42ye0xxamUdfcUFYvZ4n7Tz5G36HP+cOKlrN6nGfhmOf3hb3ILuPymCJdECvFM
xsCXpHA2r4biYMRwkWO2+X5Scx7nVrQYizJG1iTdZnY6g1heRhzUDTcf7yjyr2++\nd+9VRI0KW5gO7q0sIarHgy7ItAAWgjGhGBASU4rebQKBgQC5xeE47WUzA1zQoDof
u55tSp32hHKkw2ysdIO3LUSVHS/VhMMNHTo0fqhvgY7Wd25M9OBVmWbTvnSNmcU+\niVdVcd9rmD+jPEBftwjRKtXkQgJpMNuDszOQ3bJYqAUkRfT7ceuiil3H4Awdq6UE
qvynmn7MYZN7CxcefvOQlSdpKwKBgQD7vjXAOJn7ZyGRsb1lKxNCHL9GvZthsM1h\nvyH8uvUm94Ztw5g9ON2qgPZQIwZxEY+LxnjfqaooKHE38rNdKYHMLsfgNQ2tdopR
2sEqVL0aQP25YAYiL4jI7hGI7GwgiSiywvmhGWjU5ZIu8fKqc+8pZy4vW/EgVctQ\nuLntBvgj3QKBgGaSLEV7RcoBzEhgf1cwB0w+y7Ll9EqmoCUj++mys9BFGjkhIXTn
M1DysdtHRG+D58HT3t1EYrL80GuygGaD/FVwFzTYDiL5zG1MqTCcHxb1n1EnKbyw\nwAL3dVZgBt69RYNjpf/Lt/X47ZegQu+t3OxJcEM2iPCB8hTjcWXeBLGbAoGAEjcT
IJN34M73iNk5gQZ64D/AP1gc1Ba85aO0y9qjPmyOl4adj2B7+YhXSjkekDPbFRwJ\nRvW50CoM9yVigQ0tzR5dbAWqtbBsFbwkWfHDtRCayzz9dJ/H3/IJ5sRkln4WKckd
0uBJy43I5AixrE+zMGW828RlUBelHHQhT9s/PSkCgYA6kQyV5FLBLrmnV5B8bdiU\ndEF7H/YHrRMvzH3bwfgaw7CxjUcreQ2LX84fkUFtZXzR2VS5bdZKGFDmSX0QVGPq
zmVLrxbf0kgQjEEaSHsdIutYblHJg3bSjKoyOC20TB34sps7hpBRq6joJwjWH/rz\n6XoqNBpphe8vTBZn/FSkog==
-----END PRIVATE KEY-----
""".utf8)
}
}
19 changes: 19 additions & 0 deletions Sources/Development/entrypoint.swift
@@ -0,0 +1,19 @@
import Vapor
import Logging

@main
struct Entrypoint {
static func main() async throws {
var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)

let app = Application(env)
defer { app.shutdown() }

try configure(app)
// TODO: Replace with correctly async version of `app.run()`.
try app.start()
try await app.running?.onStop.get()
}
}

12 changes: 0 additions & 12 deletions Sources/Development/main.swift

This file was deleted.

0 comments on commit ba1a308

Please sign in to comment.