Skip to content
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
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 8,
"version" : 1
}
}
64 changes: 0 additions & 64 deletions .swiftlint.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ let package = Package(
name: "TelemetryDeckTests",
dependencies: ["TelemetryDeck"],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
)
),
]
)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,11 @@ This allows for compatibility with other logging solutions, such as [swift-log](
Your PRs on TelemetryDeck's Swift SDK are very much welcome. Check out the [SwiftClientTester](https://github.com/TelemetryDeck/SwiftClientTester) project, which provides a harness you can use to work on the library and try out new things.

When making a new release, run `./tag-release.sh MAJOR.MINOR.PATCH` to bump the version string in the SDK, create a new commit and tag that commit accordingly all in one step.

The project includes a Makefile at the root with some useful commands:

- `build`: Build the library
- `lint`: Applies all auto-correctable lint issues and reformats all source files
- `test`: Run unit tests

Before finalising your PR, please run `make lint`.
3 changes: 1 addition & 2 deletions Sources/TelemetryDeck/Signals/Signal+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ extension DefaultSignalPayload {
static var isTestFlight: Bool {
guard !isDebug, !isSimulator else { return false }
guard let receiptURL = Bundle.main.appStoreReceiptURL else { return false }
return receiptURL.lastPathComponent == "sandboxReceipt" ||
receiptURL.path.contains("sandboxReceipt")
return receiptURL.lastPathComponent == "sandboxReceipt" || receiptURL.path.contains("sandboxReceipt")
}

/// Detects if the app is running in an App Store production environment.
Expand Down
6 changes: 3 additions & 3 deletions Sources/TelemetryDeck/TelemetryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,19 @@ public final class TelemetryManager: @unchecked Sendable {

private var _configuration: TelemetryManagerConfiguration
var configuration: TelemetryManagerConfiguration {
get { queue.sync(flags: .barrier) { return _configuration } }
get { queue.sync(flags: .barrier) { _configuration } }
set { queue.sync(flags: .barrier) { _configuration = newValue } }
}

private var _lastTimeImmediateSyncRequested: Date = .distantPast
var lastTimeImmediateSyncRequested: Date {
get { queue.sync(flags: .barrier) { return _lastTimeImmediateSyncRequested } }
get { queue.sync(flags: .barrier) { _lastTimeImmediateSyncRequested } }
set { queue.sync(flags: .barrier) { _lastTimeImmediateSyncRequested = newValue } }
}

private var _lastDateAppEnteredBackground: Date = .distantPast
private var lastDateAppEnteredBackground: Date {
get { queue.sync(flags: .barrier) { return _lastDateAppEnteredBackground } }
get { queue.sync(flags: .barrier) { _lastDateAppEnteredBackground } }
set { queue.sync(flags: .barrier) { _lastDateAppEnteredBackground = newValue } }
}

Expand Down
7 changes: 4 additions & 3 deletions Tests/TelemetryDeckTests/ArrayExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import TelemetryDeck
import Testing

@testable import TelemetryDeck

enum ArrayExtensionTests {
enum CountISODatesOnOrAfter {
@Test
Expand Down Expand Up @@ -32,7 +33,7 @@ enum ArrayExtensionTests {
"2025-01-01", // Duplicate
"2025-02-01",
"2025-02-01", // Duplicate
"2025-03-01"
"2025-03-01",
]

#expect(datesWithDuplicates.countISODatesOnOrAfter(cutoffISODate: "2025-01-01") == 5)
Expand All @@ -58,7 +59,7 @@ enum ArrayExtensionTests {
"2024-02-28", // End of February
"2024-02-29", // Leap year day
"2024-03-01", // Start of March
"2025-01-01" // Far future
"2025-01-01", // Far future
]

// Test year boundaries
Expand Down
54 changes: 28 additions & 26 deletions Tests/TelemetryDeckTests/CryptoHashingTests.swift
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
@testable import TelemetryDeck
import Testing

@testable import TelemetryDeck

#if canImport(CryptoKit)
import CryptoKit
import CryptoKit
#endif

struct CryptoHashingTests {
#if canImport(CryptoKit)
@Test
func cryptoKitAndCommonCryptoHaveSameDigestStringResults() {
let stringToHash = "how do i get cowboy paint off a dog ."
let dataToHash = stringToHash.data(using: .utf8)!
@Test
func cryptoKitAndCommonCryptoHaveSameDigestStringResults() {
let stringToHash = "how do i get cowboy paint off a dog ."
let dataToHash = stringToHash.data(using: .utf8)!

let expectedDigestString = "5b8fab7cf45fcece0e99a05950611b7b355917e4fb6daa73fd3d7590764fa53b"
let expectedDigestString = "5b8fab7cf45fcece0e99a05950611b7b355917e4fb6daa73fd3d7590764fa53b"

#expect(expectedDigestString == CryptoHashing.sha256(string: stringToHash, salt: ""))
#expect(expectedDigestString == CryptoHashing.commonCryptoSha256(strData: dataToHash))
#expect(expectedDigestString == CryptoHashing.sha256(string: stringToHash, salt: ""))
#expect(expectedDigestString == CryptoHashing.commonCryptoSha256(strData: dataToHash))

// even though we already test if we can import CryptoKit, somehow this still fails on iOS 12,
// so we're gating it to iOS 13 et al.
if #available(watchOS 7, iOS 13, macOS 10.14, tvOS 13, *) {
// calling directly to prove that CryptoKit produces same reult, as ``sha256(str:)`` can fall back,
#expect(expectedDigestString == SHA256.hash(data: dataToHash).compactMap { String(format: "%02x", $0) }.joined())
// even though we already test if we can import CryptoKit, somehow this still fails on iOS 12,
// so we're gating it to iOS 13 et al.
if #available(watchOS 7, iOS 13, macOS 10.14, tvOS 13, *) {
// calling directly to prove that CryptoKit produces same reult, as ``sha256(str:)`` can fall back,
#expect(expectedDigestString == SHA256.hash(data: dataToHash).compactMap { String(format: "%02x", $0) }.joined())
}
}
}

@Test
func saltedResultsAreDifferentFromUnsaltedResults() {
let stringToHash = "how do i get cowboy paint off a dog ."
let salt = "q8wMvgVW3LzGCRQiLSLk"
let expectedDigestString = "d46208db801b09cf055fedd7ae0390e9797fc00d1bcdcb3589ea075ca157e0d6"
@Test
func saltedResultsAreDifferentFromUnsaltedResults() {
let stringToHash = "how do i get cowboy paint off a dog ."
let salt = "q8wMvgVW3LzGCRQiLSLk"
let expectedDigestString = "d46208db801b09cf055fedd7ae0390e9797fc00d1bcdcb3589ea075ca157e0d6"

let secondSalt = "x21MTSq3MRSmLjVFsYIe"
let expectedSecondDigestString = "acb027bb031c0f73de26c6b8d0441d9c98449d582a538014c44ca49b4c299aa8"
let secondSalt = "x21MTSq3MRSmLjVFsYIe"
let expectedSecondDigestString = "acb027bb031c0f73de26c6b8d0441d9c98449d582a538014c44ca49b4c299aa8"

#expect(expectedDigestString == CryptoHashing.sha256(string: stringToHash, salt: salt))
#expect(expectedSecondDigestString == CryptoHashing.sha256(string: stringToHash, salt: secondSalt))
#expect(CryptoHashing.sha256(string: stringToHash, salt: salt) != CryptoHashing.sha256(string: stringToHash, salt: secondSalt))
}
#expect(expectedDigestString == CryptoHashing.sha256(string: stringToHash, salt: salt))
#expect(expectedSecondDigestString == CryptoHashing.sha256(string: stringToHash, salt: secondSalt))
#expect(CryptoHashing.sha256(string: stringToHash, salt: salt) != CryptoHashing.sha256(string: stringToHash, salt: secondSalt))
}
#endif
}
7 changes: 4 additions & 3 deletions Tests/TelemetryDeckTests/LogHandlerTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import TelemetryDeck
import Testing

@testable import TelemetryDeck

actor LogHandlerTests {
var counter: Int = 0
var lastLevel: LogHandler.LogLevel?
Expand All @@ -17,7 +18,7 @@ actor LogHandlerTests {
await self.increment()
}
}

#expect(counter == 0)

handler.log(.debug, message: "")
Expand All @@ -40,7 +41,7 @@ actor LogHandlerTests {
await self.setLastLevel(level)
}
}

handler.log(message: "")
try await Task.sleep(nanoseconds: 10_000_000) // 10 milliseconds
#expect(lastLevel == .info)
Expand Down
1 change: 0 additions & 1 deletion Tests/TelemetryDeckTests/SignalCacheConcurrencyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ struct SignalCacheConcurrencyTests {
}
}


/// Validates pop() correctly handles concurrent access without data races.
/// Without barrier on pop(), concurrent calls can corrupt the array.
/// Run multiple iterations to increase probability of catching race condition.
Expand Down
7 changes: 4 additions & 3 deletions Tests/TelemetryDeckTests/SignalPayloadTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import TelemetryDeck
import Testing

@testable import TelemetryDeck

struct DefaultSignalPayloadTests {
@Test
func isSimulatorOrTestFlight() {
Expand Down Expand Up @@ -68,7 +69,7 @@ struct DefaultSignalPayloadTests {
@Test
func operatingSystem() {
let expectedResult: String

#if os(macOS)
expectedResult = "macOS"
#elseif os(iOS)
Expand All @@ -84,7 +85,7 @@ struct DefaultSignalPayloadTests {
#else
return "Unknown Operating System"
#endif

#expect(expectedResult == DefaultSignalPayload.operatingSystem)

print("operatingSystem", DefaultSignalPayload.operatingSystem)
Expand Down
Loading
Loading