Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign failure test #129

Merged
merged 3 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- master

jobs:
deploy:
name: api.vapor.codes
Expand Down
43 changes: 31 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
name: test
on:
- pull_request
pull_request:
push:
branches:
- master
jobs:
jwt_macos:
runs-on: macos-latest
steps:
- run: sudo xcode-select -s /Applications/Xcode_11.4.app/Contents/Developer
- uses: actions/checkout@v2
- run: swift test --enable-test-discovery --sanitize=thread
jwt_ubuntu:
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
base: ['xenial', 'bionic']
container:
image: vapor/swift:5.2-${{ matrix.base }}-ci
runs-on: ubuntu-latest
image:
# 5.2 Stable
- swift:5.2-xenial
- swift:5.2-bionic
- swift:5.2-focal
- swift:5.2-centos8
- swift:5.2-amazonlinux2
# 5.2 Unstable
- swiftlang/swift:nightly-5.2-xenial
- swiftlang/swift:nightly-5.2-bionic
# 5.3 Unstable
- swiftlang/swift:nightly-5.3-xenial
- swiftlang/swift:nightly-5.3-bionic
# Master Unstable
- swiftlang/swift:nightly-master-xenial
- swiftlang/swift:nightly-master-bionic
- swiftlang/swift:nightly-master-focal
- swiftlang/swift:nightly-master-centos8
- swiftlang/swift:nightly-master-amazonlinux2
container: ${{ matrix.image }}
steps:
- uses: actions/checkout@v2
- run: swift test --enable-test-discovery --sanitize=thread
macOS:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: swift test --enable-test-discovery --sanitize=thread
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Package.pins
Package.resolved
DerivedData
.swiftpm

Tests/LinuxMain.swift
60 changes: 59 additions & 1 deletion Tests/JWTTests/JWTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import JWT
import JWTKit
import XCTVapor

class JWTKitTests: XCTestCase {
class JWTTests: XCTestCase {
// manual authentication using req.jwt.verify
func testManual() throws {
// creates a new application for testing
Expand Down Expand Up @@ -166,6 +166,64 @@ class JWTKitTests: XCTestCase {
}
}

// https://github.com/vapor/jwt-kit/issues/26
func testSignFailureSegfault() throws {
struct UserPayload: JWTPayload {
var id: UUID
var userName: String

func verify(using signer: JWTSigner) throws { }
}

// creates a new application for testing
let app = Application(.testing)
defer { app.shutdown() }

let privateKeyString = """
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAhAHFb1M+P7qjwVlR7Es/3GBq3yICZP1eZ/JShBuLO4stTGHR
akqlOYGC+ayTxOomjp4aHFNxzHxdVe9keGv0UltP8HbRTJTubOlWl2w7zG8xAKOy
2/9s+eE3obxPrf92Ffpbx3nef9hVh8PtiV9vSd8J9QoPtODujCBf+F8n/zIrLB0m
7Tf6e5POZ8aJ93hNyjekljITNHoCwqmkD1HSgXiaoMC17CItJoRLANIMQPNVwe8d
/2ZejydBVEWxNwbTzz6DPBX5uFXhmDmOcUfqT0L9l8iy66e6M/8g6roAYkTKs1vP
PT+NfM8KwyDpx/aMTxaDwjwyOO39erV95GY6ywIDAQABAoIBAC9OazCwBjjUa+bY
WZFyjhotu17nUzBZ1EEwB/4r2MOn5r3euCt9QKTREtziybnhp5uocPcBuGBtmQ04
0yqMlWwGKSmlivAE10TUgiGVugBTQJ5YC7rnWGhcG5GsaGmUiP7rT4S22dO69TvI
LRHzz3ALrAfSaTqK+THiUEIz56N+D3F9B8z35Epxug7+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jwt.signers.use(.rs512(key: .private(pem: [UInt8](privateKeyString.utf8))))

app.get { req -> String in
let authorizationPayload = UserPayload(id: UUID(), userName: "John Smith")
let accessToken = try req.jwt.sign(authorizationPayload)
return accessToken
}

for _ in 0..<1_000 {
try app.test(.GET, "/") { res in
XCTAssertEqual(res.status, .ok)
}
}
}

override func setUp() {
XCTAssert(isLoggingConfigured)
}
Expand Down