-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Update benchmarking + Support Android + add .swift-format + other refinements #227
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2204963
Update benchmarking + other refinements
MahdiBM 2e0c712
enable android CI
MahdiBM 27cc0a7
guard with #if canImport(Testing) for android CI
MahdiBM 39319c6
add .swift-format
MahdiBM f03d9b1
format
MahdiBM 9caf843
use noble instead of jammy
MahdiBM ce64ff6
indentConditionalCompilationBlocks: false
MahdiBM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
name: benchmark | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
sha: | ||
type: string | ||
required: true | ||
description: "The commit SHA to run the benchmarks against." | ||
push: | ||
branches: [main] | ||
pull_request_review: | ||
types: [submitted] | ||
pull_request: | ||
branches: [main] | ||
types: [synchronize] | ||
paths: | ||
- Sources/*.swift | ||
- Benchmarks/ | ||
- .github/workflows/benchmark.yml | ||
|
||
jobs: | ||
benchmark: | ||
if: github.run_attempt > 1 || github.event.review.state == 'approved' || startsWith(github.event_name, 'pull_request') != true | ||
uses: vapor/ci/.github/workflows/run-benchmark.yml@main | ||
with: | ||
sha: ${{ inputs.sha }} | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Packages | ||
.build | ||
.index-build | ||
.DS_Store | ||
*.xcodeproj | ||
Package.pins | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"fileScopedDeclarationPrivacy": { | ||
"accessLevel": "private" | ||
}, | ||
"indentation": { | ||
"spaces": 4 | ||
}, | ||
"indentConditionalCompilationBlocks": true, | ||
"indentSwitchCaseLabels": false, | ||
"lineBreakAroundMultilineExpressionChainComponents": false, | ||
"lineBreakBeforeControlFlowKeywords": false, | ||
"lineBreakBeforeEachArgument": false, | ||
"lineBreakBeforeEachGenericRequirement": false, | ||
"lineLength": 140, | ||
"maximumBlankLines": 1, | ||
"multiElementCollectionTrailingCommas": true, | ||
"noAssignmentInExpressions": { | ||
"allowedFunctions": [ | ||
"XCTAssertNoThrow" | ||
] | ||
}, | ||
"prioritizeKeepingFunctionOutputTogether": false, | ||
"respectsExistingLineBreaks": true, | ||
"rules": { | ||
"AllPublicDeclarationsHaveDocumentation": false, | ||
"AlwaysUseLiteralForEmptyCollectionInit": false, | ||
"AlwaysUseLowerCamelCase": true, | ||
"AmbiguousTrailingClosureOverload": true, | ||
"BeginDocumentationCommentWithOneLineSummary": false, | ||
"DoNotUseSemicolons": true, | ||
"DontRepeatTypeInStaticProperties": true, | ||
"FileScopedDeclarationPrivacy": true, | ||
"FullyIndirectEnum": true, | ||
"GroupNumericLiterals": true, | ||
"IdentifiersMustBeASCII": true, | ||
"NeverForceUnwrap": false, | ||
"NeverUseForceTry": false, | ||
"NeverUseImplicitlyUnwrappedOptionals": false, | ||
"NoAccessLevelOnExtensionDeclaration": true, | ||
"NoAssignmentInExpressions": true, | ||
"NoBlockComments": true, | ||
"NoCasesWithOnlyFallthrough": true, | ||
"NoEmptyTrailingClosureParentheses": true, | ||
"NoLabelsInCasePatterns": true, | ||
"NoLeadingUnderscores": false, | ||
"NoParensAroundConditions": true, | ||
"NoPlaygroundLiterals": true, | ||
"NoVoidReturnOnFunctionSignature": true, | ||
"OmitExplicitReturns": false, | ||
"OneCasePerLine": true, | ||
"OneVariableDeclarationPerLine": true, | ||
"OnlyOneTrailingClosureArgument": true, | ||
"OrderedImports": true, | ||
"ReplaceForEachWithForLoop": true, | ||
"ReturnVoidInsteadOfEmptyTuple": true, | ||
"TypeNamesShouldBeCapitalized": true, | ||
"UseEarlyExits": false, | ||
"UseExplicitNilCheckInConditions": true, | ||
"UseLetInEveryBoundCaseVariable": true, | ||
"UseShorthandTypeNames": true, | ||
"UseSingleLinePropertyGetter": true, | ||
"UseSynthesizedInitializer": true, | ||
"UseTripleSlashForDocumentationComments": true, | ||
"UseWhereClausesInForLoops": false, | ||
"ValidateDocumentationComments": false | ||
}, | ||
"spacesAroundRangeFormationOperators": false, | ||
"tabWidth": 4, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.gitignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were some .index-build stuff trying to slip in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../.swiftformat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ let package = Package( | |
.product(name: "Benchmark", package: "package-benchmark"), | ||
.product(name: "JWTKit", package: "jwt-kit"), | ||
], | ||
path: "Benchmarks/Signing", | ||
path: "Signing", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made these the same as multipart-kit |
||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark") | ||
] | ||
|
@@ -29,7 +29,7 @@ let package = Package( | |
.product(name: "Benchmark", package: "package-benchmark"), | ||
.product(name: "JWTKit", package: "jwt-kit"), | ||
], | ||
path: "Benchmarks/Verifying", | ||
path: "Verifying", | ||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark") | ||
] | ||
|
@@ -40,7 +40,7 @@ let package = Package( | |
.product(name: "Benchmark", package: "package-benchmark"), | ||
.product(name: "JWTKit", package: "jwt-kit"), | ||
], | ||
path: "Benchmarks/TokenLifecycle", | ||
path: "TokenLifecycle", | ||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark") | ||
] | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,119 @@ | ||
import JWTKit | ||
import Testing | ||
#if canImport(Testing) | ||
import Testing | ||
import JWTKit | ||
|
||
#if !canImport(Darwin) | ||
import FoundationEssentials | ||
#else | ||
import Foundation | ||
#endif | ||
#if !canImport(Darwin) | ||
import FoundationEssentials | ||
#else | ||
import Foundation | ||
#endif | ||
|
||
@Suite("Claim Tests") | ||
struct ClaimTests { | ||
@Test("Test Claim with Boolean") | ||
func boolClaim() async throws { | ||
let payload = #"{"trueStr":"true","trueBool":true,"falseStr":"false","falseBool":false}"# | ||
var data = Data(payload.utf8) | ||
let decoded = try! JSONDecoder().decode(BoolPayload.self, from: data) | ||
@Suite("Claim Tests") | ||
struct ClaimTests { | ||
@Test("Test Claim with Boolean") | ||
func boolClaim() async throws { | ||
let payload = #"{"trueStr":"true","trueBool":true,"falseStr":"false","falseBool":false}"# | ||
var data = Data(payload.utf8) | ||
let decoded = try! JSONDecoder().decode(BoolPayload.self, from: data) | ||
|
||
#expect(decoded.trueStr.value == true) | ||
#expect(decoded.trueBool.value == true) | ||
#expect(decoded.falseBool.value == false) | ||
#expect(decoded.falseStr.value == false) | ||
#expect(decoded.trueStr.value == true) | ||
#expect(decoded.trueBool.value == true) | ||
#expect(decoded.falseBool.value == false) | ||
#expect(decoded.falseStr.value == false) | ||
|
||
data = Data(#"{"bad":"Not boolean"}"#.utf8) | ||
#expect(throws: DecodingError.self) { | ||
try JSONDecoder().decode(BoolPayload.self, from: data) | ||
data = Data(#"{"bad":"Not boolean"}"#.utf8) | ||
#expect(throws: DecodingError.self) { | ||
try JSONDecoder().decode(BoolPayload.self, from: data) | ||
} | ||
} | ||
} | ||
|
||
@Test("Test Claim with Locale") | ||
func localeClaim() async throws { | ||
let ptBR = #"{"locale":"pt-BR"}"# | ||
@Test("Test Claim with Locale") | ||
func localeClaim() async throws { | ||
let ptBR = #"{"locale":"pt-BR"}"# | ||
|
||
let plainEnglish = try LocalePayload.from(#"{"locale":"en"}"#) | ||
let brazillianPortugese = try LocalePayload.from(ptBR) | ||
let nadizaDialectSlovenia = try LocalePayload.from(#"{"locale":"sl-nedis"}"#) | ||
let germanSwissPost1996 = try LocalePayload.from(#"{"locale":"de-CH-1996"}"#) | ||
let chineseTraditionalTwoPrivate = try LocalePayload.from( | ||
#"{"locale":"zh-Hant-CN-x-private1-private2"}"#) | ||
let plainEnglish = try LocalePayload.from(#"{"locale":"en"}"#) | ||
let brazillianPortugese = try LocalePayload.from(ptBR) | ||
let nadizaDialectSlovenia = try LocalePayload.from(#"{"locale":"sl-nedis"}"#) | ||
let germanSwissPost1996 = try LocalePayload.from(#"{"locale":"de-CH-1996"}"#) | ||
let chineseTraditionalTwoPrivate = try LocalePayload.from( | ||
#"{"locale":"zh-Hant-CN-x-private1-private2"}"# | ||
) | ||
|
||
#expect(plainEnglish.locale.value.identifier == "en") | ||
#expect(brazillianPortugese.locale.value.identifier == "pt-BR") | ||
#expect(nadizaDialectSlovenia.locale.value.identifier == "sl-nedis") | ||
#expect(germanSwissPost1996.locale.value.identifier == "de-CH-1996") | ||
#expect(chineseTraditionalTwoPrivate.locale.value.identifier == "zh-Hant-CN-x-private1-private2") | ||
#expect(plainEnglish.locale.value.identifier == "en") | ||
#expect(brazillianPortugese.locale.value.identifier == "pt-BR") | ||
#expect(nadizaDialectSlovenia.locale.value.identifier == "sl-nedis") | ||
#expect(germanSwissPost1996.locale.value.identifier == "de-CH-1996") | ||
#expect(chineseTraditionalTwoPrivate.locale.value.identifier == "zh-Hant-CN-x-private1-private2") | ||
|
||
let encoded = try JSONEncoder().encode(brazillianPortugese) | ||
let string = String(bytes: encoded, encoding: .utf8)! | ||
#expect(string == ptBR) | ||
} | ||
let encoded = try JSONEncoder().encode(brazillianPortugese) | ||
let string = String(bytes: encoded, encoding: .utf8)! | ||
#expect(string == ptBR) | ||
} | ||
|
||
@Test("Test Claim with Sindle Audience") | ||
func singleAudienceClaim() async throws { | ||
let id = UUID() | ||
let str = "{\"audience\":\"\(id.uuidString)\"}" | ||
let data = Data(str.utf8) | ||
let decoded = try! JSONDecoder().decode(AudiencePayload.self, from: data) | ||
@Test("Test Claim with Sindle Audience") | ||
func singleAudienceClaim() async throws { | ||
let id = UUID() | ||
let str = "{\"audience\":\"\(id.uuidString)\"}" | ||
let data = Data(str.utf8) | ||
let decoded = try! JSONDecoder().decode(AudiencePayload.self, from: data) | ||
|
||
#expect(decoded.audience.value == [id.uuidString]) | ||
#expect(throws: Never.self) { | ||
try decoded.audience.verifyIntendedAudience(includes: id.uuidString) | ||
#expect(decoded.audience.value == [id.uuidString]) | ||
#expect(throws: Never.self) { | ||
try decoded.audience.verifyIntendedAudience(includes: id.uuidString) | ||
} | ||
#expect { | ||
try decoded.audience.verifyIntendedAudience(includes: UUID().uuidString) | ||
} throws: { error in | ||
guard let jwtError = error as? JWTError else { return false } | ||
return jwtError.errorType == .claimVerificationFailure | ||
&& jwtError.failedClaim is AudienceClaim | ||
&& (jwtError.failedClaim as? AudienceClaim)?.value == [id.uuidString] | ||
} | ||
} | ||
#expect { | ||
try decoded.audience.verifyIntendedAudience(includes: UUID().uuidString) | ||
} throws: { error in | ||
guard let jwtError = error as? JWTError else { return false } | ||
return jwtError.errorType == .claimVerificationFailure | ||
&& jwtError.failedClaim is AudienceClaim | ||
&& (jwtError.failedClaim as? AudienceClaim)?.value == [id.uuidString] | ||
} | ||
} | ||
|
||
@Test("Test Claim with Multiple Audiences") | ||
func multipleAudienceClaims() async throws { | ||
let id1 = UUID() | ||
let id2 = UUID() | ||
let str = "{\"audience\":[\"\(id1.uuidString)\", \"\(id2.uuidString)\"]}" | ||
let data = Data(str.utf8) | ||
let decoded = try! JSONDecoder().decode(AudiencePayload.self, from: data) | ||
@Test("Test Claim with Multiple Audiences") | ||
func multipleAudienceClaims() async throws { | ||
let id1 = UUID() | ||
let id2 = UUID() | ||
let str = "{\"audience\":[\"\(id1.uuidString)\", \"\(id2.uuidString)\"]}" | ||
let data = Data(str.utf8) | ||
let decoded = try! JSONDecoder().decode(AudiencePayload.self, from: data) | ||
|
||
#expect(decoded.audience.value == [id1.uuidString, id2.uuidString]) | ||
#expect(throws: Never.self) { | ||
try decoded.audience.verifyIntendedAudience(includes: id1.uuidString) | ||
#expect(decoded.audience.value == [id1.uuidString, id2.uuidString]) | ||
#expect(throws: Never.self) { | ||
try decoded.audience.verifyIntendedAudience(includes: id1.uuidString) | ||
} | ||
#expect(throws: Never.self) { | ||
try decoded.audience.verifyIntendedAudience(includes: id2.uuidString) | ||
} | ||
#expect { | ||
try decoded.audience.verifyIntendedAudience(includes: UUID().uuidString) | ||
} throws: { error in | ||
guard let jwtError = error as? JWTError else { return false } | ||
return jwtError.errorType == .claimVerificationFailure | ||
&& jwtError.failedClaim is AudienceClaim | ||
&& (jwtError.failedClaim as? AudienceClaim)?.value == [ | ||
id1.uuidString, id2.uuidString, | ||
] | ||
} | ||
} | ||
#expect(throws: Never.self) { | ||
try decoded.audience.verifyIntendedAudience(includes: id2.uuidString) | ||
} | ||
#expect { | ||
try decoded.audience.verifyIntendedAudience(includes: UUID().uuidString) | ||
} throws: { error in | ||
guard let jwtError = error as? JWTError else { return false } | ||
return jwtError.errorType == .claimVerificationFailure | ||
&& jwtError.failedClaim is AudienceClaim | ||
&& (jwtError.failedClaim as? AudienceClaim)?.value == [ | ||
id1.uuidString, id2.uuidString, | ||
] | ||
} | ||
} | ||
|
||
@Test("Test Expiration Encoding") | ||
func expirationEncoding() async throws { | ||
let exp = ExpirationClaim(value: Date(timeIntervalSince1970: 2_000_000_000)) | ||
let parser = DefaultJWTParser() | ||
let keyCollection = await JWTKeyCollection() | ||
.add(hmac: .init(from: "secret".bytes), digestAlgorithm: .sha256, parser: parser) | ||
let jwt = try await keyCollection.sign(ExpirationPayload(exp: exp)) | ||
let parsed = try parser.parse(jwt.bytes, as: ExpirationPayload.self) | ||
let header = parsed.header | ||
@Test("Test Expiration Encoding") | ||
func expirationEncoding() async throws { | ||
let exp = ExpirationClaim(value: Date(timeIntervalSince1970: 2_000_000_000)) | ||
let parser = DefaultJWTParser() | ||
let keyCollection = await JWTKeyCollection() | ||
.add(hmac: .init(from: "secret".bytes), digestAlgorithm: .sha256, parser: parser) | ||
let jwt = try await keyCollection.sign(ExpirationPayload(exp: exp)) | ||
let parsed = try parser.parse(jwt.bytes, as: ExpirationPayload.self) | ||
let header = parsed.header | ||
|
||
let typ = try #require(header.typ) | ||
#expect(typ == "JWT") | ||
let alg = try #require(header.alg) | ||
#expect(alg == "HS256") | ||
#expect(parsed.payload.exp == exp) | ||
_ = try await keyCollection.verify(jwt, as: ExpirationPayload.self) | ||
let typ = try #require(header.typ) | ||
#expect(typ == "JWT") | ||
let alg = try #require(header.alg) | ||
#expect(alg == "HS256") | ||
#expect(parsed.payload.exp == exp) | ||
_ = try await keyCollection.verify(jwt, as: ExpirationPayload.self) | ||
} | ||
} | ||
} | ||
#endif // canImport(Testing) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For vscode users