Skip to content

Commit

Permalink
Merge pull request #168 from DP-3T/develop
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
UBaggeler authored Jun 22, 2020
2 parents d29383c + 410b8c4 commit 30ca279
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for DP3T-SDK iOS

## Version 1.0.1 (22.06.2020)
- Make timeshift detection independent from locale / region settings
- Update last sync timestamps of individual days that were successful even if some others failed

## Version 1.0.0 (19.06.2020)
- Introduce possibility to turn off logging
- Stop tracing when changing state to infected
Expand Down
2 changes: 1 addition & 1 deletion DP3TSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |spec|

spec.name = "DP3TSDK"
spec.version = "1.0.0"
spec.version = "1.0.1"
spec.summary = "Open protocol for COVID-19 proximity tracing using Bluetooth Low Energy on mobile devices"

spec.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ DP3T-SDK is available through [Cocoapods](https://cocoapods.org/)

```ruby

pod 'DP3TSDK', => '1.0.0'
pod 'DP3TSDK', => '1.0.1'

```

Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/DP3TTracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private var instance: DP3TSDK!
/// DP3TTracing
public enum DP3TTracing {
/// The current version of the SDK
public static let frameworkVersion: String = "1.0.0"
public static let frameworkVersion: String = "1.0.1"

/// sets global parameter values which are used throughout the sdk
public static var parameters: DP3TParameters {
Expand Down
20 changes: 6 additions & 14 deletions Sources/DP3TSDK/Networking/ExposeeServiceClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol {
log.log("detected timeshift is %{public}.2f", timeShift)

if timeShift > Default.shared.parameters.networking.allowedServerTimeDiff {
log.error("detected timeshift exceeds threshold %(public).2f", timeShift)
log.error("detected timeshift exceeds threshold %{public}.2f", Default.shared.parameters.networking.allowedServerTimeDiff)
return .timeInconsistency(shift: timeShift)
}

Expand Down Expand Up @@ -275,29 +275,21 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol {
internal extension HTTPURLResponse {
static var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "EEEE, dd MMMM yyyy HH:mm:ss ZZZ"
formatter.dateFormat = "EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'"
formatter.timeZone = TimeZone(abbreviation: "GMT")
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
}()

var date: Date? {
guard let string = value(for: "date") else { return nil }
guard let string = value(forHTTPHeaderField: "date") else { return nil }
return HTTPURLResponse.dateFormatter.date(from: string)
}

var age: TimeInterval {
guard let string = value(for: "Age") else { return 0 }
guard let string = value(forHTTPHeaderField: "Age") else { return 0 }
return TimeInterval(string) ?? 0
}


func value(for key: String) -> String? {
if #available(iOS 13.0, *) {
return value(forHTTPHeaderField: key)
} else {
// https://bugs.swift.org/browse/SR-2429
return (allHeaderFields as NSDictionary)[key] as? String
}
}
}

private struct ExposeeClaims: DP3TClaims {
Expand Down
3 changes: 2 additions & 1 deletion Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,13 @@ class KnownCasesSynchronizer {
return
}

self.defaults.lastSyncTimestamps = lastSyncStore

if let lastError = occuredErrors.last {
self.logger.error("finishing sync with error: %{public}@", lastError.localizedDescription)
callback?(.failure(lastError))
} else {
self.logger.log("finishing sync successful")
self.defaults.lastSyncTimestamps = lastSyncStore
callback?(.success(()))
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/utils/JWTVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DP3TJWTVerifier {
@available(iOS 11.0, *)
@discardableResult
public func verify<ClaimType: DP3TClaims>(claimType: ClaimType.Type, httpResponse: HTTPURLResponse, httpBody: Data, claimsLeeway _: TimeInterval = 10) throws -> ClaimType {
guard let jwtString = httpResponse.value(for: jwtTokenHeaderKey) else {
guard let jwtString = httpResponse.value(forHTTPHeaderField: jwtTokenHeaderKey) else {
throw DP3TNetworkingError.jwtSignatureError(code: 1, debugDescription: "No JWT Token found in the provided response header field \(jwtTokenHeaderKey)")
}
do {
Expand Down
27 changes: 27 additions & 0 deletions Tests/DP3TSDKTests/HTTPURLResponseDateTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

@testable import DP3TSDK
import XCTest

class HTTPURLResponseDateTests: XCTestCase {

func testDateParsing() {
let response = HTTPURLResponse(url: URL(string: "http://dpppt.org")!, statusCode: 200, httpVersion: nil, headerFields: ["date": "Mon, 22 Jun 2020 07:30:50 GMT"])!
let date = response.date!
XCTAssertEqual(date.timeIntervalSince1970, 1592811050)
}

func testAgeParsing(){
let response = HTTPURLResponse(url: URL(string: "http://dpppt.org")!, statusCode: 200, httpVersion: nil, headerFields: ["age": "24"])!
XCTAssertEqual(response.age, 24)
}

}
20 changes: 20 additions & 0 deletions Tests/DP3TSDKTests/KnownCasesSynchronizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ final class KnownCasesSynchronizerTests: XCTestCase {
XCTAssertNotEqual(defaults.lastSyncTimestamps.count, 10)
}

func testStoringOfSuccessfulDates(){
let matcher = MockMatcher()
let service = MockService()
let defaults = MockDefaults()
service.error = .HTTPFailureResponse(status: 400)
service.errorAfter = 5
let sync = KnownCasesSynchronizer(matcher: matcher,
service: service,
defaults: defaults,
descriptor: .init(appId: "ch.dpppt", bucketBaseUrl: URL(string: "http://www.google.de")!, reportBaseUrl: URL(string: "http://www.google.de")!))
let expecation = expectation(description: "syncExpectation")
sync.sync(now: Self.formatter.date(from: "19.05.2020 09:00")!) { _ in
expecation.fulfill()
}
waitForExpectations(timeout: 1)

XCTAssertEqual(service.requests.count, 10)
XCTAssertEqual(defaults.lastSyncTimestamps.count, 5)
}

static var formatter: DateFormatter = {
let df = DateFormatter()
df.dateFormat = "dd.MM.yyyy HH:mm"
Expand Down
11 changes: 7 additions & 4 deletions Tests/DP3TSDKTests/Mocks/MockService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ class MockService: ExposeeServiceClientProtocol {
var error: DP3TNetworkingError?
var publishedUntil: Date = .init()
var data: Data? = "Data".data(using: .utf8)
var errorAfter: Int = 0

func getExposee(batchTimestamp: Date, completion: @escaping (Result<ExposeeSuccess, DP3TNetworkingError>) -> Void) -> URLSessionDataTask {
return session.dataTask(with: .init(url: URL(string: "http://www.google.com")!)) { _, _, _ in
if let error = self.error {
self.queue.sync {
self.requests.append(batchTimestamp)
}

if let error = self.error, self.errorAfter <= 0 {
completion(.failure(error))
} else {
self.queue.sync {
self.requests.append(batchTimestamp)
}
self.errorAfter -= 1
completion(.success(.init(data: self.data, publishedUntil: self.publishedUntil)))
}
}
Expand Down

0 comments on commit 30ca279

Please sign in to comment.