mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
## Motivation: There is no way to run code statically like in Obj-C using `+ [NSObject initialize]`, so this ensures (through a new `SwiftLint` rule) that all test classes inherit this common test class instead of `XCTestCase` directly. A future PR will make use of this new `CIRCLECI_TESTS_GENERATE_SNAPSHOTS` environment variable to allow regenerating snapshots in CI. I've also moved the duplicated `CurrentTestCaseTracker` usages to a single point.
50 lines
2.1 KiB
Swift
50 lines
2.1 KiB
Swift
import Nimble
|
|
import XCTest
|
|
|
|
@testable import RevenueCat
|
|
|
|
class ASN1ObjectIdentifierBuilderTests: TestCase {
|
|
|
|
let encoder = ASN1ObjectIdentifierEncoder()
|
|
func testBuildFromPayloadBuildsCorrectlyForDataPayload() {
|
|
let payload = encoder.objectIdentifierPayload(.data)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)) == .data
|
|
}
|
|
|
|
func testBuildFromPayloadBuildsCorrectlyForSignedDataPayload() {
|
|
let payload = encoder.objectIdentifierPayload(.signedData)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)) == .signedData
|
|
}
|
|
|
|
func testBuildFromPayloadBuildsCorrectlyForEnvelopedDataPayload() {
|
|
let payload = encoder.objectIdentifierPayload(.envelopedData)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)) == .envelopedData
|
|
}
|
|
|
|
func testBuildFromPayloadBuildsCorrectlyForSignedAndEnvelopedDataPayload() {
|
|
let payload = encoder.objectIdentifierPayload(.signedAndEnvelopedData)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)) == .signedAndEnvelopedData
|
|
}
|
|
|
|
func testBuildFromPayloadBuildsCorrectlyForDigestedDataPayload() {
|
|
let payload = encoder.objectIdentifierPayload(.digestedData)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)) == .digestedData
|
|
}
|
|
|
|
func testBuildFromPayloadBuildsCorrectlyForEncryptedDataPayload() {
|
|
let payload = encoder.objectIdentifierPayload(.encryptedData)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)) == .encryptedData
|
|
}
|
|
|
|
func testBuildFromPayloadReturnsNilIfIdentifierNotRecognized() {
|
|
let unknownObjectID = [1, 3, 23, 534643, 7454, 1, 7, 2]
|
|
let payload = encoder.encodeASN1ObjectIdentifier(numbers: unknownObjectID)
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)).to(beNil())
|
|
}
|
|
|
|
func testBuildFromPayloadReturnsNilIfIdentifierPayloadEmpty() {
|
|
let payload: ArraySlice<UInt8> = ArraySlice([])
|
|
expect(try ASN1ObjectIdentifierBuilder().build(fromPayload: payload)).to(beNil())
|
|
}
|
|
}
|