Skip to content

Commit

Permalink
Merge branch 'release-1.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Oct 19, 2020
2 parents 1489482 + 332d272 commit 94d7d6c
Show file tree
Hide file tree
Showing 13 changed files with 649 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ xcuserdata
.svn
.swiftpm
.dependencies
.derivedData
.derivedData
package.resolved
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
language: objective-c
osx_image: xcode9
language: swift
osx_image: xcode12

script:
- xcodebuild -project Kvitto.xcodeproj -scheme "Kvitto" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6 Plus' build test
- xcodebuild -project Kvitto.xcodeproj -scheme "Kvitto (iOS)" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone SE (2nd generation)' build test

after_success:
- bash <(curl -s https://codecov.io/bash)
21 changes: 12 additions & 9 deletions Core/Source/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ internal func _dateFromRFC3339String(_ string: String) -> Date?
rfc3339DateFormatter.locale = Locale(identifier: "en_US_POSIX")
rfc3339DateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

if string.count == 24 // e.g. 2020-09-27T12:07:19.686Z
if string.hasSuffix("Z")
{
/// with fractional seconds
rfc3339DateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
}
else if string.count == 20 // e.g. 2020-09-27T12:07:19Z
{
/// no fractional seconds
rfc3339DateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
if string.count == 24 // e.g. 2020-09-27T12:07:19.686Z
{
/// with fractional seconds
rfc3339DateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
}
else if string.count == 20 // e.g. 2020-09-27T12:07:19Z
{
/// no fractional seconds
rfc3339DateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
}
}
else
{
return nil
rfc3339DateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
}

return rfc3339DateFormatter.date(from: string)
Expand Down
21 changes: 17 additions & 4 deletions Core/Source/PKCS7Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,26 @@ import DTFoundation
func unwrapSignedDataSequence(_ sequence: [AnyObject]) -> Data?
{
guard sequence.count==2,
let OID = sequence[0] as? String, OID == "1.2.840.113549.1.7.1",
let dataSequence = sequence[1] as? [Data], dataSequence.count == 1
let OID = sequence[0] as? String,
OID == "1.2.840.113549.1.7.1"
else
{
return nil
}

return dataSequence[0]

if let dataSequence = sequence[1] as? [Data],
dataSequence.count == 1
{
return dataSequence[0]
}

if let array = sequence[1] as? [[Data]],
let dataSequence = array.first,
dataSequence.count == 1
{
return dataSequence[0]
}

return nil
}
}
9 changes: 8 additions & 1 deletion Core/Source/Receipt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ An iTunes store sales receipt.

fileprivate func parseData(_ data: Data) throws -> Bool
{
guard let rootArray = DTASN1Serialization.object(with: data) as? [[AnyObject]]
guard let rootArray = DTASN1Serialization.object(with: data) as? [[Any]]
else
{
throw ReceiptParsingError.invalidRootObject
Expand All @@ -150,6 +150,8 @@ An iTunes store sales receipt.

fileprivate func processItem(_ type: Int, data: Data) throws
{
do {

switch(type)
{
case 0:
Expand Down Expand Up @@ -201,5 +203,10 @@ An iTunes store sales receipt.
// all other types are private
break;
}
}
catch let error
{
print(error.localizedDescription)
}
}
}
2 changes: 1 addition & 1 deletion Externals/DTFoundation
Submodule DTFoundation updated 95 files
+4 −3 .gitignore
+42 −12 Core/Source/DTASN1/DTASN1Parser.m
+3 −3 Core/Source/DTAsyncFileDeleter/DTAsyncFileDeleter.m
+8 −0 Core/Source/DTReachability/DTReachability.h
+7 −4 Core/Source/DTReachability/DTReachability.m
+1 −1 Core/Source/DTVersion.m
+4 −0 Core/Source/OSX/DTScrollView.h
+2 −2 Core/Source/OSX/DTScrollView.m
+4 −0 Core/Source/OSX/NSDocument+DTFoundation.h
+2 −2 Core/Source/OSX/NSDocument+DTFoundation.m
+4 −0 Core/Source/OSX/NSImage+DTUtilities.h
+2 −2 Core/Source/OSX/NSImage+DTUtilities.m
+4 −0 Core/Source/OSX/NSValue+DTConversion.h
+2 −2 Core/Source/OSX/NSValue+DTConversion.m
+4 −0 Core/Source/OSX/NSView+DTAutoLayout.h
+2 −2 Core/Source/OSX/NSView+DTAutoLayout.m
+4 −0 Core/Source/OSX/NSWindowController+DTPanelControllerPresenting.h
+2 −1 Core/Source/OSX/NSWindowController+DTPanelControllerPresenting.m
+1 −1 Core/Source/iOS/BlocksAdditions/DTActionSheet.h
+1 −1 Core/Source/iOS/BlocksAdditions/DTActionSheet.m
+4 −4 Core/Source/iOS/BlocksAdditions/DTAlertView.h
+1 −1 Core/Source/iOS/BlocksAdditions/DTAlertView.m
+1 −1 Core/Source/iOS/BlocksAdditions/UIView+DTActionHandlers.h
+1 −1 Core/Source/iOS/BlocksAdditions/UIView+DTActionHandlers.m
+1 −1 Core/Source/iOS/DTActivityTitleView.h
+13 −6 Core/Source/iOS/DTActivityTitleView.m
+1 −1 Core/Source/iOS/DTCustomColoredAccessory.h
+1 −1 Core/Source/iOS/DTCustomColoredAccessory.m
+1 −1 Core/Source/iOS/DTPieProgressIndicator.h
+1 −1 Core/Source/iOS/DTPieProgressIndicator.m
+1 −1 Core/Source/iOS/DTProgressHUD/DTProgressHUD.h
+13 −2 Core/Source/iOS/DTProgressHUD/DTProgressHUD.m
+1 −1 Core/Source/iOS/DTProgressHUD/DTProgressHUDWindow.h
+1 −1 Core/Source/iOS/DTProgressHUD/DTProgressHUDWindow.m
+1 −1 Core/Source/iOS/DTSidePanel/DTSidePanelController.h
+1 −3 Core/Source/iOS/DTSidePanel/DTSidePanelController.m
+2 −1 Core/Source/iOS/DTSidePanel/DTSidePanelControllerSegue.h
+1 −1 Core/Source/iOS/DTSidePanel/DTSidePanelControllerSegue.m
+1 −1 Core/Source/iOS/DTSidePanel/DTSidePanelPanGestureRecognizer.h
+1 −1 Core/Source/iOS/DTSidePanel/DTSidePanelPanGestureRecognizer.m
+1 −1 Core/Source/iOS/DTSidePanel/UIViewController+DTSidePanelController.h
+1 −1 Core/Source/iOS/DTSidePanel/UIViewController+DTSidePanelController.m
+1 −1 Core/Source/iOS/DTSmartPagingScrollView.h
+1 −2 Core/Source/iOS/DTSmartPagingScrollView.m
+1 −3 Core/Source/iOS/DTTiledLayerWithoutFade.h
+1 −1 Core/Source/iOS/DTTiledLayerWithoutFade.m
+1 −1 Core/Source/iOS/Debug/UIView+DTDebug.h
+1 −1 Core/Source/iOS/Debug/UIView+DTDebug.m
+1 −1 Core/Source/iOS/UIApplication+DTNetworkActivity.h
+1 −1 Core/Source/iOS/UIApplication+DTNetworkActivity.m
+1 −1 Core/Source/iOS/UIImage+DTFoundation.h
+1 −1 Core/Source/iOS/UIImage+DTFoundation.m
+1 −1 Core/Source/iOS/UIScreen+DTFoundation.h
+1 −1 Core/Source/iOS/UIScreen+DTFoundation.m
+1 −1 Core/Source/iOS/UIView+DTFoundation.h
+1 −2 Core/Source/iOS/UIView+DTFoundation.m
+12 −2 DTFoundation.xcodeproj/project.pbxproj
+77 −0 DTFoundation.xcodeproj/xcshareddata/xcschemes/DTFoundation-Package.xcscheme
+28 −4 Package.swift
+0 −22 Test/Resources/zipContent/UnitTests-Info.plist
+4 −0 Test/Source/DTASN1SerializationTest.h
+6 −2 Test/Source/DTASN1SerializationTest.m
+5 −4 Test/Source/DTActionSheetTest.m
+4 −4 Test/Source/DTAlertViewTest.m
+4 −0 Test/Source/DTBase64CodingTest.h
+8 −2 Test/Source/DTBase64CodingTest.m
+4 −0 Test/Source/DTBlockFunctionsTest.h
+6 −1 Test/Source/DTBlockFunctionsTest.m
+4 −0 Test/Source/DTHTMLParserTest.h
+6 −1 Test/Source/DTHTMLParserTest.m
+6 −2 Test/Source/DTLogTest.m
+4 −0 Test/Source/DTScriptingTest.h
+4 −0 Test/Source/DTScriptingTest.m
+4 −0 Test/Source/DTVersionTest.h
+6 −1 Test/Source/DTVersionTest.m
+4 −1 Test/Source/DTZipArchiveTest.h
+8 −1 Test/Source/DTZipArchiveTest.m
+4 −0 Test/Source/NSArrayDTErrorTest.h
+6 −1 Test/Source/NSArrayDTErrorTest.m
+4 −0 Test/Source/NSDictionaryDTErrorTest.h
+6 −1 Test/Source/NSDictionaryDTErrorTest.m
+4 −0 Test/Source/NSStringDTPathsTest.h
+6 −1 Test/Source/NSStringDTPathsTest.m
+5 −1 Test/Source/NSStringDTURLEncodingTest.m
+1 −0 Test/include/DTASN1BitString.h
+1 −0 Test/include/DTScriptExpression.h
+1 −0 Test/include/DTScriptVariable.h
+1 −0 Test/include/DTZipArchive.h
+1 −0 Test/include/DTZipArchiveGZip.h
+1 −0 Test/include/DTZipArchiveNode.h
+1 −0 Test/include/DTZipArchivePKZip.h
+1 −0 Test/include/NSScanner+DTScripting.h
+0 −15 Tests/DTFoundationTests/DTFoundationTests.swift
+0 −9 Tests/DTFoundationTests/XCTestManifests.swift
+0 −7 Tests/LinuxMain.swift
2 changes: 1 addition & 1 deletion Kvitto.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Kvitto'
spec.version = '1.0.4'
spec.version = '1.0.5'
spec.summary = "Parse and validate iTunes App Store receipts"
spec.homepage = "https://github.com/Cocoanetics/Kvitto"
spec.author = { "Oliver Drobnik" => "oliver@cocoanetics.com" }
Expand Down
534 changes: 489 additions & 45 deletions Kvitto.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A795445B1BC3FC1600EC73B1"
BuildableName = "Kvitto.framework"
BlueprintName = "Kvitto"
BuildableName = "Kvitto_iOS.framework"
BlueprintName = "Kvitto (iOS)"
ReferencedContainer = "container:Kvitto.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -32,8 +32,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A795445B1BC3FC1600EC73B1"
BuildableName = "Kvitto.framework"
BlueprintName = "Kvitto"
BuildableName = "Kvitto_iOS.framework"
BlueprintName = "Kvitto (iOS)"
ReferencedContainer = "container:Kvitto.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down Expand Up @@ -64,8 +64,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A795445B1BC3FC1600EC73B1"
BuildableName = "Kvitto.framework"
BlueprintName = "Kvitto"
BuildableName = "Kvitto_iOS.framework"
BlueprintName = "Kvitto (iOS)"
ReferencedContainer = "container:Kvitto.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand All @@ -80,8 +80,8 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A795445B1BC3FC1600EC73B1"
BuildableName = "Kvitto.framework"
BlueprintName = "Kvitto"
BuildableName = "Kvitto_iOS.framework"
BlueprintName = "Kvitto (iOS)"
ReferencedContainer = "container:Kvitto.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
16 changes: 16 additions & 0 deletions Kvitto.xcodeproj/xcshareddata/xcschemes/Kvitto Unit Tests.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A79544641BC3FC1600EC73B1"
BuildableName = "Unit Tests.xctest"
BlueprintName = "Unit Tests"
ReferencedContainer = "container:Kvitto.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
Expand Down
16 changes: 9 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

Expand All @@ -16,20 +15,23 @@ let package = Package(
targets: ["Kvitto"]),
],
dependencies: [
.package(url: "https://github.com/Cocoanetics/DTFoundation.git", from: "1.7.15"),
.package(url: "https://github.com/Cocoanetics/DTFoundation.git",
from: "1.7.16"),
],
targets: [
.target(
name: "Kvitto",
dependencies: [
.product(name: "DTFoundation", package: "DTFoundation"),
.product(name: "DTFoundation",
package: "DTFoundation"),
],
path: "Core/Source"),
path: "Core",
exclude: ["Info.plist"]),
.testTarget(
name: "KvittoTests",
dependencies: ["Kvitto"],
path: "Test/Source",
resources: [.copy("receipt"),
.copy("sandboxReceipt")]),
path: "Test",
exclude: ["Info.plist"],
resources: [.copy("Resources")]),
]
)
Binary file added Test/Resources/storeKitTestReceipt
Binary file not shown.
95 changes: 83 additions & 12 deletions Test/Source/KvittoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import XCTest
import DTFoundation

@testable import Kvitto
import Kvitto

class DTReceiptTests: XCTestCase
{
Expand Down Expand Up @@ -105,24 +105,95 @@ class DTReceiptTests: XCTestCase
XCTAssertNil(iap.cancellationDate)
// XCTAssertEqual(iap.webOrderLineItemIdentifier, 1000000029801037)
}

func testDecodeStoreKitTestReceipt()
{
guard let receipt = receiptFromTestResource("storeKitTestReceipt", ofType: nil)
else
{
XCTFail("Error parsing receipt")
return
}

XCTAssertEqual(receipt.bundleIdentifier, "com.rd.eehelper")
XCTAssertEqual(receipt.appVersion, "2020.10.02.1149")
XCTAssertEqual(receipt.originalAppVersion, nil)
XCTAssertEqual(receipt.opaqueValue?.count, 8)
XCTAssertEqual(receipt.SHA1Hash?.count, 20)
XCTAssertEqual(receipt.receiptExpirationDate, Date.distantFuture)
XCTAssertNotNil(receipt.receiptCreationDate)
XCTAssertNil(receipt.ageRating)
XCTAssertEqual(receipt.receiptType, "Xcode")

guard let iap = receipt.inAppPurchaseReceipts?.first
else
{
XCTFail("No IAP decoded")
return
}

XCTAssertEqual(iap.productIdentifier, "com.rd.eehelper.pro_subscription")
XCTAssertEqual(iap.transactionIdentifier, "0")
XCTAssertNil(iap.originalTransactionIdentifier)
XCTAssertNotNil(iap.subscriptionExpirationDate)
XCTAssertNil(iap.webOrderLineItemIdentifier)
XCTAssertNotNil(iap.purchaseDate)
XCTAssertNil(iap.cancellationDate)
// XCTAssertEqual(iap.webOrderLineItemIdentifier, 1000000029801037)
}

// MARK: - Helper

func dataForTestResource(_ name: String?, ofType ext: String?) -> Data?
func urlForTestResource(name: String, ofType ext: String?) -> URL?
{
let bundle = Bundle(for: type(of: self))

#if SWIFT_PACKAGE

// there is a bug where Bundle.module points to the path of xcrun inside the Xcode.app bundle, instead of the test bundle
// that aborts unit tests with message:
// Fatal error: could not load resource bundle: /Applications/Xcode.app/Contents/Developer/usr/bin/Kvitto_KvittoTests.bundle: file KvittoTests/resource_bundle_accessor.swift, line 7

// workaround: try to find the resource bundle at the build path
let buildPathURL = bundle.bundleURL.deletingLastPathComponent()

guard let resourceBundle = Bundle(url: buildPathURL.appendingPathComponent("Kvitto_KvittoTests.bundle")),
let path = resourceBundle.path(forResource: name, ofType: ext) else
{
return nil
}

return URL(fileURLWithPath: path)

#else

guard let path = bundle.path(forResource: name, ofType: ext) else
{
return nil
}

return URL(fileURLWithPath: path)

#endif
}

func dataForTestResource(_ name: String, ofType ext: String?) -> Data?
{
let bundle = Bundle(for: type(of: self))

guard let path = bundle.path(forResource: name, ofType: ext) else { return nil }
guard let url = urlForTestResource(name: name, ofType: ext) else
{
return nil
}

return (try? Data(contentsOf: URL(fileURLWithPath: path)))
return (try? Data(contentsOf: url))
}

func receiptFromTestResource(_ name: String?, ofType ext: String?) -> Receipt?
func receiptFromTestResource(_ name: String, ofType ext: String?) -> Receipt?
{
let bundle = Bundle(for: type(of: self))

guard let URL = bundle.url(forResource: name, withExtension: ext) else { return nil }

return Receipt(contentsOfURL: URL)
guard let url = urlForTestResource(name: name, ofType: ext) else
{
return nil
}

return Receipt(contentsOfURL: url)
}
}

0 comments on commit 94d7d6c

Please sign in to comment.