| /* | |
| * Copyright (C) 2023-2025 Apple Inc. All rights reserved. | |
| * | |
| * Redistribution and use in source and binary forms, with or without | |
| * modification, are permitted provided that the following conditions | |
| * are met: | |
| * 1. Redistributions of source code must retain the above copyright | |
| * notice, this list of conditions and the following disclaimer. | |
| * 2. Redistributions in binary form must reproduce the above copyright | |
| * notice, this list of conditions and the following disclaimer in the | |
| * documentation and/or other materials provided with the distribution. | |
| * | |
| * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| * THE POSSIBILITY OF SUCH DAMAGE. | |
| */ | |
| #import "config.h" | |
| #import "ArgumentCodersCocoa.h" | |
| #import "CoreIPCCFDictionary.h" | |
| #import "CoreIPCError.h" | |
| #import "CoreIPCNSURLCredential.h" | |
| #import "CoreIPCNSURLProtectionSpace.h" | |
| #import "CoreIPCNSURLRequest.h" | |
| #import "CoreIPCPKPayment.h" | |
| #import "CoreIPCPKPaymentMethod.h" | |
| #import "CoreIPCPKPaymentSetupFeature.h" | |
| #import "CoreIPCPKShippingMethod.h" | |
| #import "CoreIPCPlistDictionary.h" | |
| #import "Encoder.h" | |
| #import "MessageSenderInlines.h" | |
| #import "Helpers/Test.h" | |
| #import <CoreVideo/CoreVideo.h> | |
| #import <Foundation/NSValue.h> | |
| #import <Security/Security.h> | |
| #import <WebCore/AttributedString.h> | |
| #import <WebCore/CVUtilities.h> | |
| #import <WebCore/ColorCocoa.h> | |
| #import <WebCore/IOSurface.h> | |
| #import <limits.h> | |
| #import <pal/spi/cf/CFNetworkSPI.h> | |
| #import <pal/spi/cocoa/ContactsSPI.h> | |
| #import <pal/spi/cocoa/WebFilterEvaluatorSPI.h> | |
| #import <wtf/RetainPtr.h> | |
| #import <wtf/cocoa/TypeCastsCocoa.h> | |
| #import <wtf/spi/cocoa/SecuritySPI.h> | |
| #import <wtf/text/Base64.h> | |
| #if PLATFORM(IOS_FAMILY) | |
| #import <WebCore/WAKAppKitStubs.h> | |
| #endif | |
| #import <pal/cocoa/AVFoundationSoftLink.h> | |
| #import <pal/cocoa/ContactsSoftLink.h> | |
| #import <pal/cocoa/DataDetectorsCoreSoftLink.h> | |
| #import <pal/cocoa/PassKitSoftLink.h> | |
| #import <pal/cocoa/WebContentAnalysisSoftLink.h> | |
| #import <pal/ios/UIKitSoftLink.h> | |
| #import <pal/mac/DataDetectorsSoftLink.h> | |
| // This test makes it trivial to test round trip encoding and decoding of a particular object type. | |
| // The primary focus here is Objective-C and similar types - Objects that exist on the platform or in | |
| // runtime that the WebKit project doesn't have direct control of. | |
| // To test a new ObjC type: | |
| // 1 - Add that type to ObjCHolderForTesting's ValueType variant | |
| // 2 - Run a test exercising that type | |
| @interface NSURLProtectionSpace (WebKitNSURLProtectionSpace) | |
| - (void)_setDistinguishedNames:(NSArray<NSData *> *)distinguishedNames; | |
| @end | |
| class SerializationTestSender final : public IPC::MessageSender { | |
| public: | |
| ~SerializationTestSender() final { }; | |
| private: | |
| bool performSendWithAsyncReplyWithoutUsingIPCConnection(UniqueRef<IPC::Encoder>&&, CompletionHandler<void(IPC::Decoder*)>&&) const final; | |
| IPC::Connection* messageSenderConnection() const final { return nullptr; } | |
| uint64_t messageSenderDestinationID() const final { return 0; } | |
| }; | |
| bool SerializationTestSender::performSendWithAsyncReplyWithoutUsingIPCConnection(UniqueRef<IPC::Encoder>&& encoder, CompletionHandler<void(IPC::Decoder*)>&& completionHandler) const | |
| { | |
| auto decoder = IPC::Decoder::create(encoder->span(), encoder->releaseAttachments()); | |
| ASSERT(decoder); | |
| completionHandler(decoder.get()); | |
| return true; | |
| } | |
| struct CFHolderForTesting { | |
| void encode(IPC::Encoder&) const; | |
| static std::optional<CFHolderForTesting> decode(IPC::Decoder&); | |
| CFTypeRef valueAsCFType() const | |
| { | |
| RetainPtr<CFTypeRef> result; | |
| WTF::switchOn(value, [&] (std::nullptr_t) { | |
| result = nullptr; | |
| }, [&](auto&& arg) { | |
| result = arg.get(); | |
| }); | |
| return result.autorelease(); | |
| } | |
| using ValueType = Variant< | |
| std::nullptr_t, | |
| RetainPtr<CFBooleanRef>, | |
| RetainPtr<CFCharacterSetRef>, | |
| RetainPtr<CFDataRef>, | |
| RetainPtr<CFDateRef>, | |
| RetainPtr<CFDictionaryRef>, | |
| RetainPtr<CFNullRef>, | |
| RetainPtr<CFNumberRef>, | |
| RetainPtr<CFStringRef>, | |
| RetainPtr<CFURLRef>, | |
| RetainPtr<CVPixelBufferRef>, | |
| RetainPtr<CGColorRef>, | |
| RetainPtr<CGColorSpaceRef>, | |
| RetainPtr<SecCertificateRef>, | |
| #if HAVE(SEC_KEYCHAIN) | |
| RetainPtr<SecKeychainItemRef>, | |
| #endif | |
| RetainPtr<SecAccessControlRef>, | |
| RetainPtr<SecTrustRef> | |
| >; | |
| ValueType value; | |
| }; | |
| void CFHolderForTesting::encode(IPC::Encoder& encoder) const | |
| { | |
| encoder << value; | |
| } | |
| std::optional<CFHolderForTesting> CFHolderForTesting::decode(IPC::Decoder& decoder) | |
| { | |
| std::optional<ValueType> value; | |
| decoder >> value; | |
| if (!value) | |
| return std::nullopt; | |
| return { { | |
| WTF::move(*value) | |
| } }; | |
| } | |
| namespace IPC { | |
| template<> struct ArgumentCoder<CFHolderForTesting> { | |
| template<typename Encoder> | |
| static void encode(Encoder& encoder, const CFHolderForTesting& holder) | |
| { | |
| holder.encode(encoder); | |
| } | |
| static std::optional<CFHolderForTesting> decode(Decoder& decoder) | |
| { | |
| return CFHolderForTesting::decode(decoder); | |
| } | |
| }; | |
| } | |
| static bool cvPixelBufferRefsEqual(CVPixelBufferRef pixelBuffer1, CVPixelBufferRef pixelBuffer2) | |
| { | |
| CVPixelBufferLockBaseAddress(pixelBuffer1, 0); | |
| CVPixelBufferLockBaseAddress(pixelBuffer2, 0); | |
| size_t pixelBuffer1Size = CVPixelBufferGetDataSize(pixelBuffer1); | |
| size_t pixelBuffer2Size = CVPixelBufferGetDataSize(pixelBuffer2); | |
| if (pixelBuffer1Size != pixelBuffer2Size) | |
| return false; | |
| auto base1 = CVPixelBufferGetBaseAddress(pixelBuffer1); | |
| auto base2 = CVPixelBufferGetBaseAddress(pixelBuffer2); | |
| bool areEqual = !memcmp(base1, base2, pixelBuffer1Size); | |
| CVPixelBufferUnlockBaseAddress(pixelBuffer1, 0); | |
| CVPixelBufferUnlockBaseAddress(pixelBuffer2, 0); | |
| return areEqual; | |
| } | |
| static bool secTrustRefsEqual(SecTrustRef trust1, SecTrustRef trust2) | |
| { | |
| // SecTrust doesn't compare equal after round-tripping through SecTrustSerialize/SecTrustDeserialize <rdar://122051396> | |
| // Therefore, we compare all the attributes we can access to verify equality. | |
| bool equal; | |
| #if HAVE(WK_SECURE_CODING_SECTRUST) | |
| RetainPtr<CFPropertyListRef> trust1Plist; | |
| RetainPtr<CFErrorRef> plistError; | |
| { | |
| // FIXME: The Security framework API is missing the `CF_RETURNS_RETAINED` annotation (rdar://161546781). | |
| CFErrorRef rawError = NULL; | |
| trust1Plist = adoptCF(SecTrustCopyPropertyListRepresentation(trust1, &rawError)); | |
| SUPPRESS_RETAINPTR_CTOR_ADOPT plistError = adoptCF(rawError); | |
| } | |
| EXPECT_FALSE(plistError); | |
| plistError = NULL; | |
| RetainPtr<CFPropertyListRef> trust2Plist; | |
| { | |
| CFErrorRef rawError = NULL; | |
| trust2Plist = adoptCF(SecTrustCopyPropertyListRepresentation(trust2, &rawError)); | |
| SUPPRESS_RETAINPTR_CTOR_ADOPT plistError = adoptCF(rawError); | |
| } | |
| EXPECT_FALSE(plistError); | |
| EXPECT_TRUE(CFGetTypeID(trust1Plist.get()) == CFDictionaryGetTypeID()); | |
| EXPECT_TRUE(CFGetTypeID(trust2Plist.get()) == CFDictionaryGetTypeID()); | |
| equal = CFEqual(trust1Plist.get(), trust2Plist.get()); | |
| EXPECT_TRUE(equal); | |
| #endif | |
| SecKeyRef pk1 = SecTrustCopyPublicKey(trust1); | |
| SecKeyRef pk2 = SecTrustCopyPublicKey(trust2); | |
| EXPECT_TRUE(pk1); | |
| EXPECT_TRUE(pk2); | |
| equal = CFEqual(pk1, pk2); | |
| CFRelease(pk1); | |
| CFRelease(pk2); | |
| EXPECT_TRUE(equal); | |
| if (!equal) | |
| return false; | |
| equal = (SecTrustGetCertificateCount(trust1) == SecTrustGetCertificateCount(trust2)); | |
| EXPECT_TRUE(equal); | |
| if (!equal) | |
| return false; | |
| RetainPtr<CFDataRef> ex1 = adoptCF(SecTrustCopyExceptions(trust1)); | |
| RetainPtr<CFDataRef> ex2 = adoptCF(SecTrustCopyExceptions(trust2)); | |
| EXPECT_TRUE(ex1); | |
| EXPECT_TRUE(ex2); | |
| equal = CFEqual(ex1.get(), ex2.get()); | |
| CFPropertyListFormat format; | |
| RetainPtr<CFErrorRef> error; | |
| RetainPtr<CFPropertyListRef> ex1plist; | |
| { | |
| CFErrorRef rawError = NULL; | |
| ex1plist = adoptCF(CFPropertyListCreateWithData( | |
| kCFAllocatorDefault, | |
| ex1.get(), | |
| kCFPropertyListImmutable, | |
| &format, | |
| &rawError | |
| )); | |
| SUPPRESS_RETAINPTR_CTOR_ADOPT error = adoptCF(rawError); | |
| } | |
| EXPECT_FALSE(error); | |
| error = NULL; | |
| RetainPtr<CFPropertyListRef> ex2plist; | |
| { | |
| CFErrorRef rawError = NULL; | |
| ex2plist = adoptCF(CFPropertyListCreateWithData( | |
| kCFAllocatorDefault, | |
| ex2.get(), | |
| kCFPropertyListImmutable, | |
| &format, | |
| &rawError | |
| )); | |
| SUPPRESS_RETAINPTR_CTOR_ADOPT error = adoptCF(rawError); | |
| } | |
| EXPECT_FALSE(error); | |
| equal = CFEqual(ex1plist.get(), ex2plist.get()); | |
| EXPECT_TRUE(equal); | |
| if (!equal) | |
| return false; | |
| CFArrayRef array1, array2; | |
| EXPECT_TRUE(SecTrustCopyPolicies(trust1, &array1) == errSecSuccess); | |
| EXPECT_TRUE(SecTrustCopyPolicies(trust2, &array2) == errSecSuccess); | |
| equal = CFEqual(array1, array2); | |
| CFRelease(array1); | |
| CFRelease(array2); | |
| EXPECT_TRUE(equal); | |
| if (!equal) | |
| return false; | |
| #if HAVE(SECTRUST_COPYPROPERTIES) | |
| array1 = SecTrustCopyProperties(trust1); | |
| array2 = SecTrustCopyProperties(trust2); | |
| if (array1 && array2) { | |
| equal = CFEqual(array1, array2); | |
| CFRelease(array1); | |
| CFRelease(array2); | |
| EXPECT_TRUE(equal); | |
| if (!equal) | |
| return false; | |
| } | |
| bool onlyOneIsNil = (!array1 && array2) || (!array2 && array1); | |
| EXPECT_FALSE(onlyOneIsNil); | |
| #endif | |
| Boolean bool1, bool2; | |
| EXPECT_TRUE(SecTrustGetNetworkFetchAllowed(trust1, &bool1) == errSecSuccess); | |
| EXPECT_TRUE(SecTrustGetNetworkFetchAllowed(trust2, &bool2) == errSecSuccess); | |
| equal = (bool1 == bool2); | |
| EXPECT_TRUE(equal); | |
| if (!equal) | |
| return false; | |
| SecTrustResultType result1, result2; | |
| EXPECT_TRUE(SecTrustGetTrustResult(trust1, &result1) == errSecSuccess); | |
| EXPECT_TRUE(SecTrustGetTrustResult(trust2, &result2) == errSecSuccess); | |
| equal = (result1 == result2); | |
| EXPECT_TRUE(equal); | |
| return equal; | |
| } | |
| CFHolderForTesting cfHolder(CFTypeRef type) | |
| { | |
| if (!type) | |
| return { nullptr }; | |
| CFTypeID typeID = CFGetTypeID(type); | |
| if (typeID == CFBooleanGetTypeID()) | |
| return { (CFBooleanRef)type }; | |
| if (typeID == CFCharacterSetGetTypeID()) | |
| return { (CFCharacterSetRef)type }; | |
| if (typeID == CFDataGetTypeID()) | |
| return { (CFDataRef)type }; | |
| if (typeID == CFDateGetTypeID()) | |
| return { (CFDateRef)type }; | |
| if (typeID == CFDictionaryGetTypeID()) | |
| return { (CFDictionaryRef)type }; | |
| if (typeID == CFNullGetTypeID()) | |
| return { }; // FIXME: Test CFNullRef. | |
| if (typeID == CFNumberGetTypeID()) | |
| return { (CFNumberRef)type }; | |
| if (typeID == CFStringGetTypeID()) | |
| return { (CFStringRef)type }; | |
| if (typeID == CFURLGetTypeID()) | |
| return { (CFURLRef)type }; | |
| if (typeID == CVPixelBufferGetTypeID()) | |
| return { (CVPixelBufferRef)type }; | |
| if (typeID == CGColorSpaceGetTypeID()) | |
| return { (CGColorSpaceRef)type }; | |
| if (typeID == CGColorGetTypeID()) | |
| return { (CGColorRef)type }; | |
| if (typeID == SecCertificateGetTypeID()) | |
| return { (SecCertificateRef)type }; | |
| #if HAVE(SEC_KEYCHAIN) | |
| ALLOW_DEPRECATED_DECLARATIONS_BEGIN | |
| if (typeID == SecKeychainItemGetTypeID()) | |
| return { (SecKeychainItemRef)type }; | |
| ALLOW_DEPRECATED_DECLARATIONS_END | |
| #endif | |
| if (typeID == SecAccessControlGetTypeID()) | |
| return { (SecAccessControlRef)type }; | |
| if (typeID == SecTrustGetTypeID()) | |
| return { (SecTrustRef)type }; | |
| ASSERT_NOT_REACHED(); | |
| return { }; | |
| } | |
| bool arraysEqual(CFArrayRef, CFArrayRef); | |
| bool dictionariesEqual(CFDictionaryRef, CFDictionaryRef); | |
| inline bool operator==(const CFHolderForTesting& a, const CFHolderForTesting& b) | |
| { | |
| auto aObject = a.valueAsCFType(); | |
| auto bObject = b.valueAsCFType(); | |
| if (!aObject && !bObject) | |
| return true; | |
| EXPECT_TRUE(aObject); | |
| EXPECT_TRUE(bObject); | |
| if (CFEqual(aObject, bObject)) | |
| return true; | |
| // Sometimes the CF input and CF output fail the CFEqual call above (Such as CFDictionaries containing certain things) | |
| // In these cases, give the Obj-C equivalent equality check a chance. | |
| if ([(NSObject *)aObject isEqual: (NSObject *)bObject]) | |
| return true; | |
| auto aTypeID = CFGetTypeID(aObject); | |
| auto bTypeID = CFGetTypeID(bObject); | |
| if (aTypeID == CVPixelBufferGetTypeID() && bTypeID == CVPixelBufferGetTypeID()) | |
| return cvPixelBufferRefsEqual((CVPixelBufferRef)aObject, (CVPixelBufferRef)bObject); | |
| if (aTypeID == SecTrustGetTypeID() && bTypeID == SecTrustGetTypeID()) | |
| return secTrustRefsEqual((SecTrustRef)aObject, (SecTrustRef)bObject); | |
| if (aTypeID == CFArrayGetTypeID() && bTypeID == CFArrayGetTypeID()) | |
| return arraysEqual((CFArrayRef)aObject, (CFArrayRef)bObject); | |
| if (aTypeID == CFDictionaryGetTypeID() && bTypeID == CFDictionaryGetTypeID()) | |
| return dictionariesEqual((CFDictionaryRef)aObject, (CFDictionaryRef)bObject); | |
| return false; | |
| } | |
| inline bool operator!=(const CFHolderForTesting& a, const CFHolderForTesting& b) | |
| { | |
| return !(a == b); | |
| } | |
| bool arraysEqual(CFArrayRef a, CFArrayRef b) | |
| { | |
| auto aCount = CFArrayGetCount(a); | |
| auto bCount = CFArrayGetCount(b); | |
| if (aCount != bCount) | |
| return false; | |
| for (CFIndex i = 0; i < aCount; i++) { | |
| if (cfHolder(CFArrayGetValueAtIndex(a, i)) != cfHolder(CFArrayGetValueAtIndex(b, i))) | |
| return false; | |
| } | |
| return true; | |
| } | |
| bool dictionariesEqual(CFDictionaryRef a, CFDictionaryRef b) | |
| { | |
| auto aCount = CFDictionaryGetCount(a); | |
| auto bCount = CFDictionaryGetCount(b); | |
| if (aCount != bCount) | |
| return false; | |
| struct Context { | |
| WTF_DEPRECATED_MAKE_STRUCT_FAST_ALLOCATED(Context); | |
| Context(bool& result, CFDictionaryRef b) | |
| : result(result) | |
| , b(b) { } | |
| bool& result; | |
| CFDictionaryRef b; | |
| CFIndex keyCount { 0 }; | |
| }; | |
| bool result { true }; | |
| auto context = makeUnique<Context>(result, b); | |
| CFDictionaryApplyFunction(a, [](CFTypeRef key, CFTypeRef value, void* voidContext) { | |
| auto& context = *static_cast<Context*>(voidContext); | |
| if (cfHolder(CFDictionaryGetValue(context.b, key)) != cfHolder(value)) | |
| context.result = false; | |
| context.keyCount++; | |
| }, context.get()); | |
| return context->keyCount == aCount; | |
| } | |
| struct ObjCHolderForTesting { | |
| void encode(IPC::Encoder&) const; | |
| static std::optional<ObjCHolderForTesting> decode(IPC::Decoder&); | |
| id valueAsID() const | |
| { | |
| RetainPtr<id> result; | |
| WTF::switchOn(value, [&] (std::nullptr_t) { | |
| result = nil; | |
| }, [&](auto&& arg) { | |
| result = arg.get(); | |
| }); | |
| return result.autorelease(); | |
| } | |
| typedef Variant< | |
| std::nullptr_t, | |
| RetainPtr<NSDate>, | |
| RetainPtr<NSString>, | |
| RetainPtr<NSURL>, | |
| RetainPtr<NSData>, | |
| RetainPtr<NSNumber>, | |
| RetainPtr<NSArray>, | |
| RetainPtr<NSDictionary>, | |
| RetainPtr<NSError>, | |
| RetainPtr<NSNull>, | |
| RetainPtr<NSLocale>, | |
| #if ENABLE(DATA_DETECTION) | |
| #if PLATFORM(MAC) | |
| RetainPtr<WKDDActionContext>, | |
| #endif | |
| RetainPtr<DDScannerResult>, | |
| #endif | |
| #if USE(AVFOUNDATION) | |
| RetainPtr<AVOutputContext>, | |
| #endif | |
| RetainPtr<NSPersonNameComponents>, | |
| RetainPtr<NSPresentationIntent>, | |
| RetainPtr<NSURLProtectionSpace>, | |
| RetainPtr<NSURLRequest>, | |
| RetainPtr<NSURLCredential>, | |
| #if USE(PASSKIT) | |
| RetainPtr<CNContact>, | |
| RetainPtr<CNPhoneNumber>, | |
| RetainPtr<CNPostalAddress>, | |
| RetainPtr<NSDateComponents>, | |
| RetainPtr<PKContact>, | |
| RetainPtr<PKDateComponentsRange>, | |
| RetainPtr<PKPaymentMerchantSession>, | |
| RetainPtr<PKPaymentMethod>, | |
| RetainPtr<PKPaymentToken>, | |
| RetainPtr<PKShippingMethod>, | |
| RetainPtr<PKPayment>, | |
| RetainPtr<PKPaymentSetupFeature>, | |
| #endif | |
| #if !HAVE(WEBCONTENTRESTRICTIONS) && HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER) | |
| RetainPtr<WebFilterEvaluator>, | |
| #endif | |
| RetainPtr<NSShadow>, | |
| RetainPtr<NSValue> | |
| > ValueType; | |
| ValueType value; | |
| }; | |
| void ObjCHolderForTesting::encode(IPC::Encoder& encoder) const | |
| { | |
| encoder << value; | |
| } | |
| std::optional<ObjCHolderForTesting> ObjCHolderForTesting::decode(IPC::Decoder& decoder) | |
| { | |
| std::optional<ValueType> value; | |
| decoder >> value; | |
| if (!value) | |
| return std::nullopt; | |
| return { { | |
| WTF::move(*value) | |
| } }; | |
| } | |
| namespace IPC { | |
| template<> struct ArgumentCoder<ObjCHolderForTesting> { | |
| template<typename Encoder> | |
| static void encode(Encoder& encoder, const ObjCHolderForTesting& holder) | |
| { | |
| holder.encode(encoder); | |
| } | |
| static std::optional<ObjCHolderForTesting> decode(Decoder& decoder) | |
| { | |
| return ObjCHolderForTesting::decode(decoder); | |
| } | |
| }; | |
| } | |
| @interface NSDateComponents () | |
| -(BOOL)oldIsEqual:(id)other; | |
| @end | |
| static BOOL nsDateComponentsTesting_isEqual(NSDateComponents *a, SEL, NSDateComponents *b) | |
| { | |
| // Override the equality check of NSDateComponents objects to only look at the identifier string | |
| // values for the NSCalendar and NSTimeZone objects. | |
| // Instances of those objects can be configured "weirdly" at runtime and have undesirable isEqual: behaviors, | |
| // but in practice for WebKit CoreIPC only the default values for each are important. | |
| NSCalendar *aCalendar = a.calendar; | |
| NSCalendar *bCalendar = b.calendar; | |
| NSTimeZone *aTimeZone = a.timeZone; | |
| NSTimeZone *bTimeZone = b.timeZone; | |
| a.calendar = nil; | |
| a.timeZone = nil; | |
| b.calendar = nil; | |
| b.timeZone = nil; | |
| BOOL result = [a oldIsEqual:b]; | |
| if (aCalendar && result) | |
| result = [aCalendar.calendarIdentifier isEqual:bCalendar.calendarIdentifier]; | |
| if (aTimeZone && result) | |
| result = [aTimeZone.name isEqual:bTimeZone.name]; | |
| a.calendar = aCalendar; | |
| a.timeZone = aTimeZone; | |
| b.calendar = bCalendar; | |
| b.timeZone = bTimeZone; | |
| return result; | |
| } | |
| #if PLATFORM(MAC) | |
| static BOOL wkDDActionContext_isEqual(WKDDActionContext *a, SEL, WKDDActionContext *b) | |
| { | |
| if (![a.authorNameComponents isEqual:b.authorNameComponents]) | |
| return false; | |
| if (!CFEqual(a.mainResult, b.mainResult)) | |
| return false; | |
| if (a.allResults.count != b.allResults.count) | |
| return false; | |
| for (size_t i = 0; i < a.allResults.count; ++i) { | |
| if (!CFEqual((__bridge DDResultRef)a.allResults[i], (__bridge DDResultRef)b.allResults[i])) | |
| return false; | |
| } | |
| if (!NSEqualRects(a.highlightFrame, b.highlightFrame)) | |
| return false; | |
| return true; | |
| } | |
| #endif | |
| static bool wkNSURLProtectionSpace_isEqual(NSURLProtectionSpace *a, SEL, NSURLProtectionSpace* b) | |
| { | |
| if (![a.host isEqual: b.host]) { | |
| if (!(a.host == nil && b.host == nil)) | |
| return false; | |
| } | |
| if (!(a.port == b.port)) | |
| return false; | |
| if (![a.protocol isEqual:b.protocol]) | |
| return false; | |
| if (!([a.realm isEqual:b.realm] || (!a.realm && a.realm == b.realm))) | |
| return false; | |
| if (![a.authenticationMethod isEqual:b.authenticationMethod]) | |
| return false; | |
| if (!([a.distinguishedNames isEqual:b.distinguishedNames] || (!a.distinguishedNames && a.distinguishedNames == b.distinguishedNames))) | |
| return false; | |
| if (!a.serverTrust != !b.serverTrust) | |
| return false; | |
| if (a.serverTrust && !secTrustRefsEqual(a.serverTrust, b.serverTrust)) | |
| return false; | |
| return true; | |
| } | |
| #if USE(PASSKIT) | |
| static bool CNPostalAddressTesting_isEqual(CNPostalAddress *a, CNPostalAddress *b) | |
| { | |
| // CNPostalAddress treats a nil formattedAddress and empty formattedAddress the same for equality. | |
| // But, there's other behavior with CNPostalAddress where nil-vs-empty makes a critical difference. | |
| // To regression test our IPC of the object, we explicitly make sure that "nil goes in, nil comes out" | |
| if (a.formattedAddress && !b.formattedAddress) | |
| return false; | |
| if (!a.formattedAddress && b.formattedAddress) | |
| return false; | |
| return [a isEqual:b]; | |
| } | |
| #endif | |
| static bool NSURLCredentialTesting_isEqual(NSURLCredential *a, NSURLCredential *b) | |
| { | |
| if (a.persistence != b.persistence) | |
| return false; | |
| if (a.user && ![a.user isEqualToString:b.user]) | |
| return false; | |
| if (a.password && ![a.password isEqualToString:b.password]) | |
| return false; | |
| if (a.hasPassword != b.hasPassword) | |
| return false; | |
| if (a.certificates.count != b.certificates.count) | |
| return false; | |
| return true; | |
| } | |
| #if USE(PASSKIT) || (!HAVE(WEBCONTENTRESTRICTIONS) && HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)) | |
| static BOOL wkSecureCoding_isEqual(id a, SEL, id b) | |
| { | |
| RetainPtr<WKKeyedCoder> aCoder = adoptNS([WKKeyedCoder new]); | |
| RetainPtr<WKKeyedCoder> bCoder = adoptNS([WKKeyedCoder new]); | |
| [a encodeWithCoder:aCoder.get()]; | |
| [b encodeWithCoder:bCoder.get()]; | |
| return [[aCoder accumulatedDictionary] isEqual:[bCoder accumulatedDictionary]]; | |
| } | |
| #endif // USE(PASSKIT) || (!HAVE(WEBCONTENTRESTRICTIONS) && HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER)) | |
| inline bool operator==(const ObjCHolderForTesting& a, const ObjCHolderForTesting& b) | |
| { | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ | |
| // These classes do not have isEqual: methods useful for our unit testing, so we'll swap it in ourselves. | |
| auto oldIsEqual = class_getMethodImplementation([NSDateComponents class], @selector(isEqual:)); | |
| class_replaceMethod([NSDateComponents class], @selector(isEqual:), (IMP)nsDateComponentsTesting_isEqual, "v@:@"); | |
| class_addMethod([NSDateComponents class], @selector(oldIsEqual:), oldIsEqual, "v@:@"); | |
| auto oldIsEqual2 = class_getMethodImplementation([NSURLProtectionSpace class], @selector(isEqual:)); | |
| class_replaceMethod([NSURLProtectionSpace class], @selector(isEqual:), (IMP)wkNSURLProtectionSpace_isEqual, "v@:@"); | |
| class_addMethod([NSURLProtectionSpace class], @selector(oldIsEqual:), oldIsEqual2, "v@:@"); | |
| #if USE(PASSKIT) | |
| class_addMethod(PAL::getPKPaymentMethodClassSingleton(), @selector(isEqual:), (IMP)wkSecureCoding_isEqual, "v@:@"); | |
| class_addMethod(PAL::getPKPaymentTokenClassSingleton(), @selector(isEqual:), (IMP)wkSecureCoding_isEqual, "v@:@"); | |
| class_addMethod(PAL::getPKDateComponentsRangeClassSingleton(), @selector(isEqual:), (IMP)wkSecureCoding_isEqual, "v@:@"); | |
| class_addMethod(PAL::getPKShippingMethodClassSingleton(), @selector(isEqual:), (IMP)wkSecureCoding_isEqual, "v@:@"); | |
| class_addMethod(PAL::getPKPaymentClassSingleton(), @selector(isEqual:), (IMP)wkSecureCoding_isEqual, "v@:@"); | |
| #endif | |
| #if ENABLE(DATA_DETECTION) && PLATFORM(MAC) | |
| class_addMethod(PAL::getWKDDActionContextClassSingleton(), @selector(isEqual:), (IMP)wkDDActionContext_isEqual, "v@:@"); | |
| #endif | |
| #if !HAVE(WEBCONTENTRESTRICTIONS) && HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER) | |
| class_addMethod(PAL::getWebFilterEvaluatorClassSingleton(), @selector(isEqual:), (IMP)wkSecureCoding_isEqual, "v@:@"); | |
| #endif | |
| }); | |
| id aObject = a.valueAsID(); | |
| id bObject = b.valueAsID(); | |
| if (!aObject && !bObject) | |
| return true; | |
| EXPECT_TRUE(aObject != nil); | |
| EXPECT_TRUE(bObject != nil); | |
| #if USE(PASSKIT) | |
| if ([aObject isKindOfClass:PAL::getCNPostalAddressClassSingleton()]) | |
| return CNPostalAddressTesting_isEqual(aObject, bObject); | |
| #endif | |
| if ([aObject isKindOfClass:NSURLCredential.class]) | |
| return NSURLCredentialTesting_isEqual(aObject, bObject); | |
| return [aObject isEqual:bObject]; | |
| } | |
| class ObjCPingBackMessage { | |
| public: | |
| using Arguments = std::tuple<ObjCHolderForTesting>; | |
| using ReplyArguments = std::tuple<ObjCHolderForTesting>; | |
| // We can use any MessageName here that is not classified as async-with-reply (the | |
| // WithoutUsingIPCConnection path does not encode an async reply ID header field). | |
| static constexpr IPC::MessageName name() { return IPC::MessageName::IPCTester_EmptyMessage; } | |
| static IPC::MessageName asyncMessageReplyName() { return IPC::MessageName::IPCTester_AsyncPingReply; } | |
| static constexpr bool isSync = false; | |
| ObjCPingBackMessage(const ObjCHolderForTesting& holder) | |
| : m_holder(holder) | |
| { | |
| } | |
| template<typename Encoder> void encode(Encoder& encoder) | |
| { | |
| encoder << m_holder; | |
| } | |
| private: | |
| const ObjCHolderForTesting& m_holder; | |
| }; | |
| class CFPingBackMessage { | |
| public: | |
| using Arguments = std::tuple<CFHolderForTesting>; | |
| using ReplyArguments = std::tuple<CFHolderForTesting>; | |
| // We can use any MessageName here that is not classified as async-with-reply (the | |
| // WithoutUsingIPCConnection path does not encode an async reply ID header field). | |
| static constexpr IPC::MessageName name() { return IPC::MessageName::IPCTester_EmptyMessage; } | |
| static IPC::MessageName asyncMessageReplyName() { return IPC::MessageName::IPCTester_AsyncPingReply; } | |
| static constexpr bool isSync = false; | |
| CFPingBackMessage(const CFHolderForTesting& holder) | |
| : m_holder(holder) | |
| { | |
| } | |
| template<typename Encoder> void encode(Encoder& encoder) | |
| { | |
| encoder << m_holder; | |
| } | |
| private: | |
| const CFHolderForTesting& m_holder; | |
| }; | |
| /* | |
| Certificate and private key were generated by running this command: | |
| openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes | |
| and entering this information: | |
| Country Name (2 letter code) []:US | |
| State or Province Name (full name) []:New Mexico | |
| Locality Name (eg, city) []:Santa Fe | |
| Organization Name (eg, company) []:Self | |
| Organizational Unit Name (eg, section) []:Myself | |
| Common Name (eg, fully qualified host name) []:Me | |
| Email Address []:me@example.com | |
| Getting encoded data: | |
| $ openssl rsa -in key.pem -outform DER | base64 | |
| $ openssl x509 -in cert.pem -outform DER | base64 | |
| */ | |
| String privateKeyDataBase64("" | |
| "MIIJKgIBAAKCAgEAu4RuNu7ekW19odDzXwgJBtHoQ9p4cy1iuzYiuGaXrvPUP5uR2MpyY9ptp8iHVn" | |
| "1tt9zMl1suwuAGXZtI5AZhgnL3prlD8eZIEbcbvN6JwdkzMt4aWwvSooNJTSucMXwpy/vEd8Q7AD/R" | |
| "bSNVuFtsl0ACuOpwdGCX1Pg+hak2WrPpZ+mUMnTH3AyQH0vnjsiiGo40L7vtpG3fFHwXpY4dI8lEgC" | |
| "Q3ikxgOFO8qZIfvcZjOt2O0sBZ8i5mgHWKrVJ9iJ+QkbUmEvsz7VsDc0RHC7kzeF0VWGLIkJQ5tIWV" | |
| "KTNCbWSbqI4Gt3qge80u9bK/37ohdnWOuR3V25lOfvAZeGgLg/Rm6BZiYAl/C6n0Neh1TDhUPLUDXA" | |
| "LEf1kTP8FUk1477H2dVcg8ry2F5pjYRsJcdhPLChOJEv4UL5acxjYf8iukeHEVslnULXPBHCRcRq63" | |
| "u10QcEO+MFMnUc+yvPXZCI+P+cJZqo7OzxVxLRNhKvnx21/bqdSVNLymtTazDRVplsaWGH1s+Ol9QB" | |
| "0Cb2us+liosO43CouytSaGJludU/cEO43DUGOvTdQanaLg8t8AM+FxO7MSo3EO9gDUU/v6HV9GyeWG" | |
| "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MVrcSVxsWtbh7XV4l3qccr9I34pkx/MqGY" | |
| "GmLR3lVIZxVrVPDbd7LgvlLXT72oRGL4T2Ojae/i5zsFm+FU+jxTPB3p0ZbFHMqftJ0pD9J7kLE+xY" | |
| "uuA19Zoq6WfjZ20c1966oJU5pNsk0roAIpFiwzEso55s9wd9nmgo4tiQKCAQEAlKOIoqlHvreCgmUm" | |
| "gnSVky1n/trksNMImxksR0gyMq26XL59Mz8auzy/6XCyb6Lok6/WitK3Tv/1Uqa9CTSCrP5PMtk7bk" | |
| "FO9WssqtTp3YExFisdEUq/vjrhXfxMe5gPs+6MkbpElE/AKpL1tXJF8rgtpZzJYubbRaiQ1vhGVMa+" | |
| "eY+ZwBb6cnI2k94CgVqofc8uHjv4zse0lA47mdOShr97MDV1FCOeSPg1WBwDPbrMMpre8Q8W0w+wj4" | |
| "qiViPFcuPO+jToizb9VX4TIgiSFUQ5ZlQ0O5RlPSqnjcSntLIdq0nKn8bcre/6CkAsMBytaHcEoDck" | |
| "6I0QC5zps4Kj7g=="_s); | |
| String certDataBase64("" | |
| "MIIFgDCCA2gCCQC9pt3ltu0TzTANBgkqhkiG9w0BAQsFADCBgTELMAkGA1UEBhMCVVMxEzARBgNVBA" | |
| "gMCk5ldyBNZXhpY28xETAPBgNVBAcMCFNhbnRhIEZlMQ0wCwYDVQQKDARTZWxmMQ8wDQYDVQQLDAZN" | |
| "eXNlbGYxCzAJBgNVBAMMAk1lMR0wGwYJKoZIhvcNAQkBFg5tZUBleGFtcGxlLmNvbTAeFw0yMzExMT" | |
| "AxOTE5NTdaFw0yNDExMDkxOTE5NTdaMIGBMQswCQYDVQQGEwJVUzETMBEGA1UECAwKTmV3IE1leGlj" | |
| "bzERMA8GA1UEBwwIU2FudGEgRmUxDTALBgNVBAoMBFNlbGYxDzANBgNVBAsMBk15c2VsZjELMAkGA1" | |
| "UEAwwCTWUxHTAbBgkqhkiG9w0BCQEWDm1lQGV4YW1wbGUuY29tMIICIjANBgkqhkiG9w0BA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2E8SN1yn67rOSYBCB6USag9PXK7E" | |
| "F9wRm02TP+nuqdM/dYLoxCmOgLbsCnu+DrM1HqMrh6mPkpF6dmDazdX/aKVb6Da7E4J0NmG3TQmZeg" | |
| "JI3IBlwik6OrRprkb/jNmWZEfoCIuvckTGAmnEYmcIRx7nxzpT6KXNdyKaWTEcRkujFqv+mzEpFbaZ" | |
| "N2Skkd5zvkCB7rSVdVXdAVVF+qHNf5C47RtTt21Fr7qG/miTeOhCakhuKGNGkV6XwQCCPERC3YSF0K" | |
| "Gz9lE+7wW1g0PBpQBaxC5EIyXlxUQwBo0O/L9ouyKjobVCQB5PPxyKIQbn/NdBXRWnoV6bzxOz04yd" | |
| "KB60HHk4YvR2oWqd2iJChiDA9k4nb2CvxtfV8MaskXZ+6oKR2LEowlc+KefHOdeTroXmIAN+5u2eBl" | |
| "vcUc7R4j6cg="_s); | |
| static RetainPtr<SecCertificateRef> createCertificate() | |
| { | |
| RetainPtr certData = adoptNS([[NSData alloc] initWithBase64EncodedString:certDataBase64.createNSString().get() options:0]); | |
| RetainPtr cert = adoptCF(SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef)certData.get())); | |
| EXPECT_NOT_NULL(cert); | |
| return cert; | |
| } | |
| static RetainPtr<SecKeyRef> createPrivateKey() | |
| { | |
| RetainPtr keyData = adoptNS([[NSData alloc] initWithBase64EncodedString:privateKeyDataBase64.createNSString().get() options:0]); | |
| NSDictionary *keyAttrs = @{ | |
| (id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA, | |
| (id)kSecAttrKeySizeInBits: @4096, | |
| (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate | |
| }; | |
| RetainPtr privateKey = adoptCF(SecKeyCreateWithData((CFDataRef)keyData.get(), (CFDictionaryRef)keyAttrs, NULL)); | |
| EXPECT_NOT_NULL(privateKey); | |
| return privateKey; | |
| } | |
| static RetainPtr<NSPersonNameComponents> personNameComponentsForTesting() | |
| { | |
| RetainPtr phoneticComponents = adoptNS([[NSPersonNameComponents alloc] init]); | |
| phoneticComponents.get().familyName = @"Family"; | |
| phoneticComponents.get().middleName = @"Middle"; | |
| phoneticComponents.get().namePrefix = @"Doctor"; | |
| phoneticComponents.get().givenName = @"Given"; | |
| phoneticComponents.get().nickname = @"Buddy"; | |
| RetainPtr components = adoptNS([[NSPersonNameComponents alloc] init]); | |
| components.get().familyName = @"Familia"; | |
| components.get().middleName = @"Median"; | |
| components.get().namePrefix = @"Physician"; | |
| components.get().givenName = @"Gifted"; | |
| components.get().nickname = @"Pal"; | |
| components.get().phoneticRepresentation = phoneticComponents.get(); | |
| return components; | |
| } | |
| #if HAVE(SEC_KEYCHAIN) | |
| static SecKeychainRef getTempKeychain() | |
| { | |
| SecKeychainRef keychainRef = NULL; | |
| uuid_t uu; | |
| char pass[PATH_MAX]; | |
| uuid_generate_random(uu); | |
| uuid_unparse_upper(uu, pass); | |
| UInt32 passLen = (UInt32)strlen(pass); | |
| NSString* path = [NSString stringWithFormat:@"%@/%s", NSTemporaryDirectory(), pass]; | |
| [NSFileManager.defaultManager removeItemAtPath:path error:NULL]; | |
| EXPECT_TRUE(SecKeychainCreate(path.fileSystemRepresentation, passLen, pass, false, NULL, &keychainRef) == errSecSuccess); | |
| EXPECT_NOT_NULL(keychainRef); | |
| EXPECT_TRUE(SecKeychainUnlock(keychainRef, passLen, pass, TRUE) == errSecSuccess); | |
| return keychainRef; | |
| } | |
| static void destroyTempKeychain(SecKeychainRef keychainRef) | |
| { | |
| if (keychainRef) { | |
| SecKeychainDelete(keychainRef); | |
| CFRelease(keychainRef); | |
| } | |
| } | |
| #endif // HAVE(SEC_KEYCHAIN) | |
| #if USE(PASSKIT) | |
| static RetainPtr<CNMutablePostalAddress> postalAddressForTesting() | |
| { | |
| RetainPtr<CNMutablePostalAddress> address = adoptNS([PAL::getCNMutablePostalAddressClassSingleton() new]); | |
| address.get().street = @"1 Apple Park Way"; | |
| address.get().subLocality = @"Birdland"; | |
| address.get().city = @"Cupertino"; | |
| address.get().subAdministrativeArea = @"Santa Clara County"; | |
| address.get().state = @"California"; | |
| address.get().postalCode = @"95014"; | |
| address.get().country = @"United States of America"; | |
| address.get().ISOCountryCode = @"US"; | |
| address.get().formattedAddress = @"Hello world"; | |
| return address; | |
| } | |
| static RetainPtr<PKContact> pkContactForTesting() | |
| { | |
| RetainPtr<PKContact> contact = adoptNS([PAL::getPKContactClassSingleton() new]); | |
| contact.get().name = personNameComponentsForTesting().get(); | |
| contact.get().emailAddress = @"admin@webkit.org"; | |
| contact.get().phoneNumber = [PAL::getCNPhoneNumberClassSingleton() phoneNumberWithDigits:@"4085551234" countryCode:@"us"]; | |
| contact.get().postalAddress = postalAddressForTesting().get(); | |
| ALLOW_DEPRECATED_DECLARATIONS_BEGIN | |
| contact.get().supplementarySubLocality = @"City 17"; | |
| ALLOW_DEPRECATED_DECLARATIONS_END | |
| return contact; | |
| } | |
| #endif // USE(PASSKIT) | |
| static void runTestNS(ObjCHolderForTesting&& holderArg) | |
| { | |
| __block bool done = false; | |
| __block ObjCHolderForTesting holder = WTF::move(holderArg); | |
| auto sender = SerializationTestSender { }; | |
| sender.sendWithAsyncReplyWithoutUsingIPCConnection(ObjCPingBackMessage(holder), ^(ObjCHolderForTesting&& result) { | |
| EXPECT_TRUE(holder == result); | |
| done = true; | |
| }); | |
| // The completion handler should be called synchronously, so this should be true already. | |
| EXPECT_TRUE(done); | |
| }; | |
| static void runTestCFWithExpectedResult(const CFHolderForTesting& holderArg, const CFHolderForTesting& expectedResult) | |
| { | |
| __block bool done = false; | |
| __block CFHolderForTesting holder = expectedResult; | |
| auto sender = SerializationTestSender { }; | |
| sender.sendWithAsyncReplyWithoutUsingIPCConnection(CFPingBackMessage(holderArg), ^(CFHolderForTesting&& result) { | |
| EXPECT_TRUE(holder == result); | |
| done = true; | |
| }); | |
| // The completion handler should be called synchronously, so this should be true already. | |
| EXPECT_TRUE(done); | |
| }; | |
| static void runTestCF(const CFHolderForTesting& holderArg) | |
| { | |
| runTestCFWithExpectedResult(holderArg, holderArg); | |
| }; | |
| TEST(IPCSerialization, Plist) | |
| { | |
| NSDictionary *plist = @{ | |
| @"key1": @"A String", | |
| @"key2": @1.0, | |
| @"key3": @[ | |
| @{ | |
| @"date": NSDate.now, | |
| @"number": @2.0, | |
| @"string": @"A String" | |
| }, | |
| ], | |
| @"key4": [NSData dataWithBytes:"Data test" length:strlen("Data test")] | |
| }; | |
| auto p = WebKit::CoreIPCPlistDictionary(plist); | |
| auto d = p.toID(); | |
| EXPECT_TRUE([d.get() isEqual:plist]); | |
| } | |
| TEST(IPCSerialization, Basic) | |
| { | |
| // CVPixelBuffer | |
| auto s1 = WebCore::IOSurface::create(nullptr, { 5, 5 }, WebCore::ColorSpace::SRGB()); | |
| auto pixelBuffer = WebCore::createCVPixelBuffer(s1->surface()); | |
| runTestCF({ pixelBuffer->get() }); | |
| // NSString/CFString | |
| runTestNS({ @"Hello world" }); | |
| runTestCF({ CFSTR("Hello world") }); | |
| // NSURL/CFURL | |
| NSURL *url = [NSURL URLWithString:@"https://webkit.org/"]; | |
| runTestNS({ url }); | |
| runTestCF({ (__bridge CFURLRef)url }); | |
| // NSData/CFData | |
| runTestNS({ [NSData dataWithBytes:"Data test" length:strlen("Data test")] }); | |
| RetainPtr cfData = adoptCF(CFDataCreate(kCFAllocatorDefault, (const UInt8 *)"Data test", strlen("Data test"))); | |
| runTestCF({ cfData.get() }); | |
| // NSDate | |
| NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; | |
| [dateComponents setYear:2007]; | |
| [dateComponents setMonth:1]; | |
| [dateComponents setDay:9]; | |
| [dateComponents setHour:10]; | |
| [dateComponents setMinute:00]; | |
| [dateComponents setSecond:0]; | |
| runTestNS({ [[NSCalendar currentCalendar] dateFromComponents:dateComponents] }); | |
| // CFBoolean | |
| runTestCF({ kCFBooleanTrue }); | |
| runTestCF({ kCFBooleanFalse }); | |
| // CGColor | |
| RetainPtr sRGBColorSpace = adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceSRGB)); | |
| constexpr CGFloat testComponents[4] = { 1, .75, .5, .25 }; | |
| RetainPtr cgColor = adoptCF(CGColorCreate(sRGBColorSpace.get(), testComponents)); | |
| runTestCF({ cgColor.get() }); | |
| // CGColorSpace | |
| runTestCF({ sRGBColorSpace.get() }); | |
| RetainPtr grayColorSpace = adoptCF(CGColorSpaceCreateDeviceGray()); | |
| runTestCF({ grayColorSpace.get() }); | |
| auto runNumberTest = [&](NSNumber *number) { | |
| ObjCHolderForTesting::ValueType numberVariant; | |
| numberVariant.emplace<RetainPtr<NSNumber>>(number); | |
| runTestNS({ numberVariant }); | |
| }; | |
| // CFCharacterSet | |
| RetainPtr characterSet = CFCharacterSetGetPredefined(kCFCharacterSetWhitespaceAndNewline); | |
| runTestCF({ characterSet.get() }); | |
| // NSNumber | |
| runNumberTest([NSNumber numberWithChar: CHAR_MIN]); | |
| runNumberTest([NSNumber numberWithUnsignedChar: CHAR_MAX]); | |
| runNumberTest([NSNumber numberWithShort: SHRT_MIN]); | |
| runNumberTest([NSNumber numberWithUnsignedShort: SHRT_MAX]); | |
| runNumberTest([NSNumber numberWithInt: INT_MIN]); | |
| runNumberTest([NSNumber numberWithUnsignedInt: UINT_MAX]); | |
| runNumberTest([NSNumber numberWithLong: LONG_MIN]); | |
| runNumberTest([NSNumber numberWithUnsignedLong: ULONG_MAX]); | |
| runNumberTest([NSNumber numberWithLongLong: LLONG_MIN]); | |
| runNumberTest([NSNumber numberWithUnsignedLongLong: ULLONG_MAX]); | |
| runNumberTest([NSNumber numberWithFloat: 3.14159]); | |
| runNumberTest([NSNumber numberWithDouble: 9.98989898989]); | |
| runNumberTest([NSNumber numberWithBool: true]); | |
| runNumberTest([NSNumber numberWithBool: false]); | |
| runNumberTest([NSNumber numberWithInteger: NSIntegerMax]); | |
| runNumberTest([NSNumber numberWithInteger: NSIntegerMin]); | |
| runNumberTest([NSNumber numberWithUnsignedInteger: NSUIntegerMax]); | |
| // NSArray | |
| runTestNS({ @[ @"Array test", @1, @{ @"hello": @9 }, @[ @"Another", @3, @"array"], url, [NSData dataWithBytes:"Data test" length:strlen("Data test")] ] }); | |
| // NSDictionary | |
| runTestNS({ @{ @"Dictionary": @[ @"array value", @12 ] } }); | |
| // CFDictionary with a non-toll-free bridged CFType, also run as NSDictionary | |
| RetainPtr cfDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 1, NULL, NULL)); | |
| CFDictionaryAddValue(cfDictionary.get(), CFSTR("MyKey"), cgColor.get()); | |
| runTestCF({ cfDictionary.get() }); | |
| runTestNS({ bridge_cast(cfDictionary.get()) }); | |
| // NSError | |
| RetainPtr<SecCertificateRef> cert = createCertificate(); | |
| RetainPtr<SecKeyRef> key = createPrivateKey(); | |
| RetainPtr<SecIdentityRef> identity = adoptCF(SecIdentityCreate(kCFAllocatorDefault, cert.get(), key.get())); | |
| NSError *error1 = [NSError errorWithDomain:@"TestWTFDomain" code:1 userInfo:@{ NSLocalizedDescriptionKey : @"TestWTF Error" }]; | |
| runTestNS({ error1 }); | |
| NSError *error2 = [NSError errorWithDomain:@"TestWTFDomain" code:2 userInfo:@{ | |
| NSLocalizedDescriptionKey: @"Localized Description", | |
| NSLocalizedFailureReasonErrorKey: @"Localized Failure Reason Error", | |
| NSUnderlyingErrorKey: error1, | |
| }]; | |
| runTestNS({ error2 }); | |
| NSError *error3 = [NSError errorWithDomain:@"TestUserInfo" code:3 userInfo:@{ | |
| NSLocalizedDescriptionKey: @"Localized Description", | |
| NSLocalizedFailureReasonErrorKey: @"Localized Failure Reason Error", | |
| NSUnderlyingErrorKey: error1, | |
| @"Key1" : @"String value", | |
| @"Key2" : url, | |
| @"Key3" : [NSNumber numberWithFloat: 3.14159], | |
| @"Key4" : @[ @"String in Array"], | |
| @"Key5" : @{ @"InnerKey1" : [NSNumber numberWithBool: true] }, | |
| @"NSErrorClientCertificateChainKey" : @[ (__bridge id) identity.get(), @10 ] | |
| }]; | |
| // Test converting SecIdentity objects to SecCertificate objects | |
| WebKit::CoreIPCError filteredError3 = WebKit::CoreIPCError(error3); | |
| RetainPtr<id> error4 = filteredError3.toID(); | |
| auto error3Size = [[[error3 userInfo] objectForKey:@"NSErrorClientCertificateChainKey"] count]; | |
| auto error4Size = [[[error4.get() userInfo] objectForKey:@"NSErrorClientCertificateChainKey"] count]; | |
| EXPECT_TRUE(error3Size == (error4Size + 1)); // The @10 in error3 will be filtered out. | |
| runTestNS({ (NSError *)error4.get() }); | |
| // Test filtering out unexpected types in NSErrorClientCertificateChainKey array | |
| NSError *error5 = [NSError errorWithDomain:@"TestUserInfoFilter" code:5 userInfo:@{ | |
| @"NSErrorClientCertificateChainKey" : @[ @(65) ] | |
| }]; | |
| WebKit::CoreIPCError filteredError5 = WebKit::CoreIPCError(error5); | |
| RetainPtr<id> error6 = filteredError5.toID(); | |
| EXPECT_EQ([[[error6.get() userInfo] objectForKey:@"NSErrorClientCertificateChainKey"] count], (NSUInteger)0); | |
| // Test that a bad key value type is filtered out | |
| NSError *error7 = [NSError errorWithDomain:@"TestBadKeyValue" code:7 userInfo:@{ | |
| @"NSErrorClientCertificateChainKey" : @(66) | |
| }]; | |
| WebKit::CoreIPCError filteredError7 = WebKit::CoreIPCError(error7); | |
| RetainPtr<id> error8 = filteredError7.toID(); | |
| EXPECT_EQ([[error8.get() userInfo] objectForKey:@"NSErrorClientCertificateChainKey"], nil); | |
| // Test type checking for NSURLErrorFailingURLPeerTrustErrorKey | |
| NSError *error9 = [NSError errorWithDomain:@"TestPeerCertificates" code:9 userInfo:@{ | |
| NSURLErrorFailingURLPeerTrustErrorKey : @[ (__bridge id) cert.get() ] | |
| }]; | |
| WebKit::CoreIPCError filteredError9 = WebKit::CoreIPCError(error9); | |
| RetainPtr<id> error10 = filteredError9.toID(); | |
| EXPECT_EQ([[error10.get() userInfo] objectForKey:@"NSErrorPeerCertificateChainKey"], nil); | |
| EXPECT_EQ([[error10.get() userInfo] objectForKey:@"NSURLErrorFailingURLPeerTrustErrorKey" ], nil); | |
| // Test value for NSErrorPeerCertificateChainKey is expected type (SecCertificate) | |
| NSError *error11 = [NSError errorWithDomain:@"TestPeerCertificates" code:11 userInfo:@{ | |
| @"NSErrorPeerCertificateChainKey" : @[ (__bridge id) cert.get() ] | |
| }]; | |
| WebKit::CoreIPCError filteredError11 = WebKit::CoreIPCError(error11); | |
| RetainPtr<id> error12 = filteredError11.toID(); | |
| EXPECT_EQ([[[error12.get() userInfo] objectForKey:@"NSErrorPeerCertificateChainKey"] count], (NSUInteger)1); | |
| runTestNS({ (NSError *)error12.get() }); | |
| // NSLocale | |
| for (NSString* identifier : [NSLocale availableLocaleIdentifiers]) | |
| runTestNS({ [NSLocale localeWithLocaleIdentifier: identifier] }); | |
| // NSPersonNameComponents | |
| auto components = personNameComponentsForTesting(); | |
| runTestNS({ components.get().phoneticRepresentation }); | |
| runTestNS({ components.get() }); | |
| components.get().namePrefix = nil; | |
| runTestNS({ components.get() }); | |
| components.get().givenName = nil; | |
| runTestNS({ components.get() }); | |
| components.get().middleName = nil; | |
| runTestNS({ components.get() }); | |
| components.get().familyName = nil; | |
| runTestNS({ components.get() }); | |
| components.get().nickname = nil; | |
| runTestNS({ components.get() }); | |
| #if USE(PASSKIT) | |
| // CNPhoneNumber | |
| // Digits must be non-null at init-time, but countryCode can be null. | |
| // However, Contacts will calculate a default country code if you pass in a null one, | |
| // so testing encode/decode of such an instance is pointless. | |
| RetainPtr<CNPhoneNumber> phoneNumber = [PAL::getCNPhoneNumberClassSingleton() phoneNumberWithDigits:@"4085551234" countryCode:@"us"]; | |
| runTestNS({ phoneNumber.get() }); | |
| // CNPostalAddress | |
| RetainPtr<CNMutablePostalAddress> address = postalAddressForTesting(); | |
| runTestNS({ address.get() }); | |
| address.get().formattedAddress = nil; | |
| runTestNS({ address.get() }); | |
| // PKContact | |
| auto pkContact = pkContactForTesting(); | |
| runTestNS({ pkContact.get() }); | |
| pkContact.get().name = nil; | |
| runTestNS({ pkContact.get() }); | |
| pkContact.get().postalAddress = nil; | |
| runTestNS({ pkContact.get() }); | |
| pkContact.get().phoneNumber = nil; | |
| runTestNS({ pkContact.get() }); | |
| pkContact.get().emailAddress = nil; | |
| runTestNS({ pkContact.get() }); | |
| pkContact.get().supplementarySubLocality = nil; | |
| runTestNS({ pkContact.get() }); | |
| #endif // USE(PASSKIT) | |
| // CFURL | |
| // The following URL described is quite nonsensical. | |
| const UInt8 baseBytes[10] = { 'h', 't', 't', 'p', ':', '/', '/', 0xE2, 0x80, 0x80 }; | |
| RetainPtr baseURL = adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, baseBytes, 10, kCFStringEncodingUTF8, nullptr, true)); | |
| const UInt8 compoundBytes[10] = { 'p', 'a', 't', 'h' }; | |
| RetainPtr compoundURL = adoptCF(CFURLCreateAbsoluteURLWithBytes(nullptr, compoundBytes, 4, kCFStringEncodingUTF8, baseURL.get(), true)); | |
| runTestCF({ baseURL.get() }); | |
| runTestCF({ compoundURL.get() }); | |
| auto runValueTest = [&](NSValue *value) { | |
| ObjCHolderForTesting::ValueType valueVariant; | |
| valueVariant.emplace<RetainPtr<NSValue>>(value); | |
| runTestNS({ valueVariant }); | |
| }; | |
| // NSValue, wrapping any of the following classes: | |
| // - NSRange | |
| // - NSRect | |
| runValueTest([NSValue valueWithRange:NSMakeRange(1, 2)]); | |
| runValueTest([NSValue valueWithRect:NSMakeRect(1, 2, 79, 80)]); | |
| // SecTrust -- evaluate the trust of the cert created above | |
| SecTrustRef trustRef = NULL; | |
| RetainPtr policy = adoptCF(SecPolicyCreateBasicX509()); | |
| EXPECT_TRUE(SecTrustCreateWithCertificates(cert.get(), policy.get(), &trustRef) == errSecSuccess); | |
| EXPECT_NOT_NULL(trustRef); | |
| RetainPtr trust = adoptCF(trustRef); | |
| runTestCF({ trust.get() }); | |
| EXPECT_TRUE(SecTrustEvaluateWithError(trust.get(), NULL) == errSecSuccess); | |
| runTestCF({ trust.get() }); | |
| NSDictionary *protection = @{ | |
| (id)kSecUseDataProtectionKeychain : @(YES), | |
| (id)kSecAttrSynchronizable : @(NO), | |
| (id)kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly : @(YES), | |
| (id)kSecAttrAccessibleWhenUnlocked: @(YES) }; | |
| SecAccessControlCreateFlags flags = (kSecAccessControlDevicePasscode | kSecAccessControlBiometryAny | kSecAccessControlOr); | |
| RetainPtr accessControlRef = adoptCF(SecAccessControlCreateWithFlags(kCFAllocatorDefault, (CFTypeRef)protection, flags, NULL)); | |
| EXPECT_NOT_NULL(accessControlRef); | |
| runTestCF({ accessControlRef.get() }); | |
| // SecKeychainItem | |
| #if HAVE(SEC_KEYCHAIN) | |
| ALLOW_DEPRECATED_DECLARATIONS_BEGIN | |
| // Store the certificate created above into the temp keychain | |
| SecKeychainRef tempKeychain = getTempKeychain(); | |
| CFDataRef certData = NULL; | |
| EXPECT_TRUE(SecItemExport(cert.get(), kSecFormatX509Cert, kSecItemPemArmour, nil, &certData) == errSecSuccess); | |
| CFArrayRef itemsPtr = NULL; | |
| EXPECT_TRUE(SecKeychainItemImport(certData, CFSTR(".pem"), NULL, NULL, 0, NULL, tempKeychain, &itemsPtr) == errSecSuccess); | |
| EXPECT_NOT_NULL(itemsPtr); | |
| RetainPtr items = adoptCF(itemsPtr); | |
| EXPECT_GT(CFArrayGetCount(items.get()), 0); | |
| RetainPtr keychainItemRef = (SecKeychainItemRef)CFArrayGetValueAtIndex(items.get(), 0); | |
| EXPECT_NOT_NULL(keychainItemRef.get()); | |
| runTestCF({ keychainItemRef.get() }); | |
| CFRelease(certData); | |
| destroyTempKeychain(tempKeychain); | |
| ALLOW_DEPRECATED_DECLARATIONS_END | |
| #endif // HAVE(SEC_KEYCHAIN) | |
| runTestCFWithExpectedResult({ (__bridge CFDictionaryRef) @{ | |
| NSNull.null : NSData.data, | |
| url : (id)trust.get(), | |
| @"should be removed before encoding" : NSUUID.UUID, | |
| NSUUID.UUID : @"should also be removed before encoding", | |
| } }, { (__bridge CFDictionaryRef) @{ | |
| NSNull.null : NSData.data, | |
| url : (id)trust.get() | |
| } }); | |
| // NSPresentationIntent | |
| NSInteger intentID = 1; | |
| NSPresentationIntent *paragraphIntent = [NSPresentationIntent paragraphIntentWithIdentity:intentID++ nestedInsideIntent:nil]; | |
| runTestNS({ paragraphIntent }); | |
| NSPresentationIntent *headingIntent = [NSPresentationIntent headerIntentWithIdentity:intentID++ level:1 nestedInsideIntent:nil]; | |
| runTestNS({ headingIntent }); | |
| NSPresentationIntent *codeBlockIntent = [NSPresentationIntent codeBlockIntentWithIdentity:intentID++ languageHint:@"Swift" nestedInsideIntent:paragraphIntent]; | |
| runTestNS({ codeBlockIntent }); | |
| NSPresentationIntent *thematicBreakIntent = [NSPresentationIntent thematicBreakIntentWithIdentity:intentID++ nestedInsideIntent:nil]; | |
| runTestNS({ thematicBreakIntent }); | |
| NSPresentationIntent *orderedListIntent = [NSPresentationIntent orderedListIntentWithIdentity:intentID++ nestedInsideIntent:paragraphIntent]; | |
| runTestNS({ orderedListIntent }); | |
| NSPresentationIntent *unorderedListIntent = [NSPresentationIntent unorderedListIntentWithIdentity:intentID++ nestedInsideIntent:paragraphIntent]; | |
| runTestNS({ unorderedListIntent }); | |
| NSPresentationIntent *listItemIntent = [NSPresentationIntent listItemIntentWithIdentity:intentID++ ordinal:1 nestedInsideIntent:orderedListIntent]; | |
| runTestNS({ listItemIntent }); | |
| NSPresentationIntent *blockQuoteIntent = [NSPresentationIntent blockQuoteIntentWithIdentity:intentID++ nestedInsideIntent:paragraphIntent]; | |
| runTestNS({ blockQuoteIntent }); | |
| NSPresentationIntent *tableIntent = [NSPresentationIntent tableIntentWithIdentity:intentID++ columnCount:2 alignments:@[@(NSPresentationIntentTableColumnAlignmentLeft), @(NSPresentationIntentTableColumnAlignmentRight)] nestedInsideIntent:unorderedListIntent]; | |
| runTestNS({ tableIntent }); | |
| NSPresentationIntent *tableHeaderRowIntent = [NSPresentationIntent tableHeaderRowIntentWithIdentity:intentID++ nestedInsideIntent:tableIntent]; | |
| runTestNS({ tableHeaderRowIntent }); | |
| NSPresentationIntent *tableRowIntent = [NSPresentationIntent tableRowIntentWithIdentity:intentID++ row:1 nestedInsideIntent:tableIntent]; | |
| runTestNS({ tableRowIntent }); | |
| NSPresentationIntent *tableCellIntent = [NSPresentationIntent tableCellIntentWithIdentity:intentID++ column:1 nestedInsideIntent:tableRowIntent]; | |
| runTestNS({ tableCellIntent }); | |
| runTestNS({ NSNull.null }); | |
| runTestCF({ kCFNull }); | |
| runTestNS({ nil }); | |
| runTestCF({ nullptr }); | |
| // NSURLProtectionSpace | |
| RetainPtr<NSURLProtectionSpace> protectionSpace = adoptNS([[NSURLProtectionSpace alloc] initWithHost:@"127.0.0.1" port:8000 protocol:NSURLProtectionSpaceHTTP realm:@"testrealm" authenticationMethod:NSURLAuthenticationMethodHTTPBasic]); | |
| runTestNS({ protectionSpace.get() }); | |
| RetainPtr<NSURLProtectionSpace> protectionSpace2 = adoptNS([[NSURLProtectionSpace alloc] initWithHost:@"127.0.0.1" port:443 protocol:NSURLProtectionSpaceHTTPS realm:nil authenticationMethod:NSURLAuthenticationMethodServerTrust]); | |
| NSData *distinguishedNamesData = [NSData dataWithBytes:"AAAA" length:4]; | |
| NSArray *distinguishedNames = @[distinguishedNamesData]; | |
| [protectionSpace2.get() _setServerTrust:trustRef]; | |
| [protectionSpace2.get() _setDistinguishedNames:distinguishedNames]; | |
| runTestNS({ protectionSpace2.get() }); | |
| NSString* nilString = nil; | |
| RetainPtr<NSURLProtectionSpace> protectionSpace3 = adoptNS([[NSURLProtectionSpace alloc] initWithHost:nilString port:443 protocol:NSURLProtectionSpaceHTTPS realm:nil authenticationMethod:NSURLAuthenticationMethodServerTrust]); | |
| [protectionSpace3.get() _setServerTrust:nil]; | |
| [protectionSpace3.get() _setDistinguishedNames:nil]; | |
| runTestNS({ protectionSpace3.get() }); | |
| runTestNS({ [NSURLCredential credentialForTrust:trust.get()] }); | |
| #if HAVE(DICTIONARY_SERIALIZABLE_NSURLCREDENTIAL) && !HAVE(WK_SECURE_CODING_NSURLCREDENTIAL) | |
| runTestNS({ [NSURLCredential credentialWithIdentity:identity.get() certificates:@[(id)cert.get()] persistence:NSURLCredentialPersistencePermanent] }); | |
| runTestNS({ [NSURLCredential credentialWithIdentity:identity.get() certificates:nil persistence:NSURLCredentialPersistenceForSession] }); | |
| #endif | |
| runTestNS({ [NSURLCredential credentialWithUser:@"user" password:@"password" persistence:NSURLCredentialPersistenceSynchronizable] }); | |
| } | |
| TEST(IPCSerialization, NSErrorNetworkResolutionReport) | |
| { | |
| NSDictionary *resolutionReport = @{ | |
| @"provider" : @"Cloudflare DNS", | |
| @"dnsFailureReason" : @"censored", | |
| @"extendedDNSErrorExtraText" : @"some extra text", | |
| @"interfaces" : @[ | |
| @{ @"type" : @"wifi", @"name" : @"en0" }, | |
| @{ @"type" : @"wired", @"name" : @"en1" }, | |
| ], | |
| }; | |
| NSError *originalError = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCannotFindHost userInfo:@{ | |
| NSLocalizedDescriptionKey : @"A server with the specified hostname could not be found.", | |
| @"networkResolutionReport" : resolutionReport, | |
| }]; | |
| WebKit::CoreIPCError ipcError = WebKit::CoreIPCError(originalError); | |
| RetainPtr<id> roundTripped = ipcError.toID(); | |
| NSDictionary *roundTrippedReport = [[roundTripped userInfo] objectForKey:@"networkResolutionReport"]; | |
| ASSERT_TRUE([roundTrippedReport isKindOfClass:NSDictionary.class]); | |
| EXPECT_TRUE([[roundTrippedReport objectForKey:@"dnsFailureReason"] isEqual:@"censored"]); | |
| EXPECT_TRUE([[roundTrippedReport objectForKey:@"provider"] isEqual:@"Cloudflare DNS"]); | |
| EXPECT_TRUE([[roundTrippedReport objectForKey:@"extendedDNSErrorExtraText"] isEqual:@"some extra text"]); | |
| NSArray *roundTrippedInterfaces = [roundTrippedReport objectForKey:@"interfaces"]; | |
| ASSERT_TRUE([roundTrippedInterfaces isKindOfClass:NSArray.class]); | |
| ASSERT_EQ([roundTrippedInterfaces count], (NSUInteger)2); | |
| EXPECT_TRUE([[[roundTrippedInterfaces objectAtIndex:0] objectForKey:@"type"] isEqual:@"wifi"]); | |
| EXPECT_TRUE([[[roundTrippedInterfaces objectAtIndex:0] objectForKey:@"name"] isEqual:@"en0"]); | |
| EXPECT_TRUE([[[roundTrippedInterfaces objectAtIndex:1] objectForKey:@"type"] isEqual:@"wired"]); | |
| EXPECT_TRUE([[[roundTrippedInterfaces objectAtIndex:1] objectForKey:@"name"] isEqual:@"en1"]); | |
| runTestNS({ (NSError *)roundTripped.get() }); | |
| } | |
| #if HAVE(WK_SECURE_CODING_SECTRUST) | |
| String cert1("" | |
| "MIIHezCCBmOgAwIBAgIQfrZYqgaHdOKdEb5ZVqa0LTANBgkqhkiG9w0BAQsFADBRMQswCQYDVQQGEw" | |
| "JVUzETMBEGA1UEChMKQXBwbGUgSW5jLjEtMCsGA1UEAxMkQXBwbGUgUHVibGljIEVWIFNlcnZlciBS" | |
| "U0EgQ0EgMiAtIEcxMB4XDTI0MTIwOTE3NTcwNFoXDTI1MDQwODE5NTY1NlowgccxHTAbBgNVBA8MFF" | |
| "ByaXZhdGUgT3JnYW5pemF0aW9uMRMwEQYLKwYBBAGCNzwCAQMTAlVTMRswGQYLKwYBBAGCNzwCAQIM" | |
| "CkNhbGlmb3JuaWExETAPBgNVBAUTCEMwODA2NTkyMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaW" | |
| "Zvcm5pYTESMBAGA1UEBwwJQ3VwZXJ0aW5vMRMwEQYDVQQKDApBcHBsZSBJbmMuMRYwFAYDVQQDDA13" | |
| "d3cuYXBwbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxlSqT8ZVN6y8/a3TDd" | |
| "V9zwNyhjeCH7AEckmzN810eAKJ/079QHFI+5KisoP9Uuu0W/dWO/NVFSH6cf6zA6I1qvewAkkaocJE" | |
| "TuO+OKosPXWZpAGFUcoT1j098EQy2OCLD5DfYYGYZDIFqGzGw9jgxA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wEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFLE+w2" | |
| "kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3" | |
| "DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMU" | |
| "u4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jFhS9O" | |
| "MPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ" | |
| "3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCevEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8" | |
| "nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K"_s); | |
| String extendedKeyUsage1("VR0lAA=="_s); | |
| String extendedKeyUsage2("KwYBBQUHAwE="_s); | |
| String extendedKeyUsage3("KwYBBAGCNwoDAw=="_s); | |
| String extendedKeyUsage4("YIZIAYb4QgQB"_s); | |
| TEST(IPCSerialization, SecTrustRef) | |
| { | |
| NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
| [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; | |
| [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; | |
| NSDictionary *appleCertificatePlist = @{ | |
| @"anchorsOnly" : @(NO), | |
| @"certificates" : @[ | |
| [[NSData alloc] initWithBase64EncodedString:cert1.createNSString().get() options:0], | |
| [[NSData alloc] initWithBase64EncodedString:cert2.createNSString().get() options:0] | |
| ], | |
| @"chain" : @[ | |
| [[NSData alloc] initWithBase64EncodedString:chain1.createNSString().get() options:0], | |
| [[NSData alloc] initWithBase64EncodedString:chain2.createNSString().get() options:0], | |
| [[NSData alloc] initWithBase64EncodedString:chain3.createNSString().get() options:0], | |
| ], | |
| @"details" : @[ | |
| @{ }, | |
| @{ }, | |
| @{ }, | |
| ], | |
| @"info" : @{ | |
| @"Builder" : @{ | |
| @"RevocationDbIgnored" : @(NO), | |
| @"RevocationIfTrusted" : @(YES), | |
| @"RevocationOnline" : @(NO) | |
| }, | |
| @"CertificateTransparency" : @(YES), | |
| @"CompanyName" : @"Apple Inc.", | |
| @"ExtendedValidation" : @(YES), | |
| @"Organization" : @"Apple Inc.", | |
| @"Revocation" : @(YES), | |
| @"RevocationInfo" : @[ | |
| @{ | |
| @"ocsp" : @{ | |
| @"isDefinitive" : @(YES), | |
| @"isRevoked" : @(NO), | |
| @"nextUpdate" : @(792270694), | |
| @"thisUpdate" : @(791669495) | |
| } | |
| }, | |
| @{ | |
| @"ocsp" : @{ }, | |
| @"valid" : @{ | |
| @"anchorHash" : [NSData dataWithBytes:"AAAA" length:strlen("AAAA")], | |
| @"certHash" : [NSData dataWithBytes:"BBBB" length:strlen("AAAA")], | |
| @"checkOCSP" : @(NO), | |
| @"complete" : @(YES), | |
| @"format" : @(1), | |
| @"hasDateConstraints" : @(NO), | |
| @"hasNameConstraints" : @(NO), | |
| @"hasPolicyConstraints" : @(YES), | |
| @"isDefinitive" : @(YES), | |
| @"isOnList" : @(NO), | |
| @"isRevoked" : @(NO), | |
| @"issuerHash" : [NSData dataWithBytes:"CCCC" length:strlen("AAAA")], | |
| @"knownOnly" : @(NO), | |
| @"noCACheck" : @(NO), | |
| @"overridable" : @(NO), | |
| @"policyConstraints" : [NSData dataWithBytes:"DDDD" length:strlen("AAAA")], | |
| @"requireCT" : @(NO), | |
| @"valid" : @(NO) | |
| } | |
| }, | |
| @{ | |
| @"ocsp" : @{ } | |
| } | |
| ], | |
| @"RevocationValidUntil" : [dateFormatter dateFromString:@"2024-12-20 15:15:45 +0000"], | |
| @"TrustExpirationDate" : [dateFormatter dateFromString:@"2024-12-20 15:15:45 +0000"], | |
| @"TrustExtendedValidation" : @(YES), | |
| @"TrustResultNotAfter" : [dateFormatter dateFromString:@"2024-12-20 06:12:43 +0000"], | |
| @"TrustResultNotBefore" : [dateFormatter dateFromString:@"2024-12-20 03:42:43 +0000"], | |
| @"TrustRevocationChecked" : @(YES), | |
| }, | |
| @"keychainsAllowed" : @(YES), | |
| @"policies" : @[ | |
| @{ | |
| @"SecPolicyOid" : @"1.2.840.113635.100.1.3", | |
| @"SecPolicyPolicyName" : @"sslServer", | |
| @"policyOptions" : @{ | |
| @"BasicConstraints" : @(YES), | |
| @"CriticalExtensions" : @(YES), | |
| @"DuplicateExtension" : @(YES), | |
| @"ExtendedKeyUsage" : @[ | |
| [NSData new], | |
| [[NSData alloc] initWithBase64EncodedString:extendedKeyUsage1.createNSString().get() options:0], | |
| [[NSData alloc] initWithBase64EncodedString:extendedKeyUsage2.createNSString().get() options:0], | |
| [[NSData alloc] initWithBase64EncodedString:extendedKeyUsage3.createNSString().get() options:0], | |
| [[NSData alloc] initWithBase64EncodedString:extendedKeyUsage4.createNSString().get() options:0], | |
| ], | |
| @"GrayListedLeaf" : @(YES), | |
| @"IdLinkage" : @(YES), | |
| @"KeySize" : @{ | |
| @"42" : @(2048), | |
| @"73" : @(256) | |
| }, | |
| @"KeyUsage" : @[ | |
| @(1), | |
| @(0) | |
| ], | |
| @"NonEmptySubject" : @(YES), | |
| @"OtherTrustValidityPeriod": @[ | |
| @[ | |
| [dateFormatter dateFromString:@"2019-06-30 23:00:00 +0000"], | |
| @(71283600) | |
| ] | |
| ], | |
| @"SSLHostname" : @"www.apple.com", | |
| @"ServerAuthEKU" : @(YES), | |
| @"SignatureHashAlgorithms" : @[ | |
| @"SignatureDigestMD2", | |
| @"SignatureDigestMD4", | |
| @"SignatureDigestMD5", | |
| @"SignatureDigestSHA1" | |
| ], | |
| @"SystemTrustValidityPeriod" : @[ | |
| @[ | |
| [dateFormatter dateFromString:@"2018-03-01 00:00:00 +0000"], | |
| @(71283600) | |
| ], | |
| @[ | |
| [dateFormatter dateFromString:@"2020-09-01 00:00:00 +0000"], | |
| @(34387200) | |
| ] | |
| ], | |
| @"SystemTrustedCTRequired" : @(YES), | |
| @"TemporalValidity" : @(YES), | |
| @"UnparseableExtension" : @(YES), | |
| @"WeakKeySize" : @(YES), | |
| @"WeakSignature" : @(YES) | |
| } | |
| } | |
| ], | |
| @"result" : @(4), | |
| @"verifyDate" : [dateFormatter dateFromString:@"2024-12-20 04:57:08 +0000"], | |
| @"responses" : @[ | |
| [NSData dataWithBytes:"AAAA" length:strlen("AAAA")] | |
| ], | |
| @"scts" : @[ | |
| [NSData dataWithBytes:"BBBB" length:strlen("BBBB")] | |
| ], | |
| @"anchors" : @[ | |
| [[NSData alloc] initWithBase64EncodedString:cert1.createNSString().get() options:0] | |
| ], | |
| @"trustedLogs" : @[ | |
| [NSData dataWithBytes:"CCCC" length:strlen("CCCC")] | |
| ], | |
| @"exceptions" : @[ | |
| @{ | |
| @"Exception1" : @(YES), | |
| @"Exception2" : @(NO), | |
| @"Exception3" : [NSData dataWithBytes:"DDDD" length:strlen("DDDD")], | |
| @"Exception4" : @(3) | |
| } | |
| ] | |
| }; | |
| // The inline dictionary above does not compare equal. Do a serialization loop to get types which will compare equal. | |
| CFErrorRef error = NULL; | |
| RetainPtr<CFDataRef> dataBlob = adoptCF(CFPropertyListCreateData( | |
| kCFAllocatorDefault, | |
| appleCertificatePlist, | |
| kCFPropertyListBinaryFormat_v1_0, | |
| 0, | |
| &error | |
| )); | |
| EXPECT_FALSE(error); | |
| CFPropertyListFormat format; | |
| RetainPtr<CFPropertyListRef> recreatedAppleCertificatePlist = adoptCF(CFPropertyListCreateWithData( | |
| kCFAllocatorDefault, | |
| dataBlob.get(), | |
| kCFPropertyListImmutable, | |
| &format, | |
| &error | |
| )); | |
| EXPECT_FALSE(error); | |
| RetainPtr<SecTrustRef> trust = adoptCF(SecTrustCreateFromPropertyListRepresentation(recreatedAppleCertificatePlist.get(), &error)); | |
| EXPECT_FALSE(error); | |
| RetainPtr<CFPropertyListRef> plistFromGeneratedObject = adoptCF(SecTrustCopyPropertyListRepresentation(trust.get(), &error)); | |
| bool loopedPlistEqual = CFEqual(recreatedAppleCertificatePlist.get(), plistFromGeneratedObject.get()); | |
| EXPECT_TRUE(loopedPlistEqual); | |
| runTestCF({ trust.get() }); | |
| } | |
| // rdar://191576139: newer Security frameworks put an NSArray inside the SSL policy's KeySize option dictionary. | |
| TEST(IPCSerialization, SecTrustRefKeySizeWithArrayValue) | |
| { | |
| RetainPtr certificate = adoptCF(SecCertificateCreateWithData(nullptr, (__bridge CFDataRef)adoptNS([[NSData alloc] initWithBase64EncodedString:cert1.createNSString().get() options:0]).get())); | |
| ASSERT_NOT_NULL(certificate.get()); | |
| RetainPtr policy = adoptCF(SecPolicyCreateSSL(true, CFSTR("example.local"))); | |
| SecTrustRef trustRef = nullptr; | |
| EXPECT_EQ(SecTrustCreateWithCertificates(certificate.get(), policy.get(), &trustRef), errSecSuccess); | |
| RetainPtr originalTrust = adoptCF(trustRef); | |
| RetainPtr originalPlist = adoptCF(SecTrustCopyPropertyListRepresentation(originalTrust.get(), nullptr)); | |
| RetainPtr plist = adoptNS([(NSDictionary *)originalPlist.get() mutableCopy]); | |
| RetainPtr policies = adoptNS([plist.get()[@"policies"] mutableCopy]); | |
| RetainPtr sslPolicy = adoptNS([policies.get()[0] mutableCopy]); | |
| RetainPtr policyOptions = adoptNS([sslPolicy.get()[@"policyOptions"] mutableCopy]); | |
| RetainPtr keySize = adoptNS([policyOptions.get()[@"KeySize"] mutableCopy]); | |
| ASSERT_NOT_NULL(keySize.get()); | |
| keySize.get()[@"111"] = @[ @11, @12, @13, @14, @15, @16, @17, @18, @19 ]; | |
| policyOptions.get()[@"KeySize"] = keySize.get(); | |
| sslPolicy.get()[@"policyOptions"] = policyOptions.get(); | |
| policies.get()[0] = sslPolicy.get(); | |
| plist.get()[@"policies"] = policies.get(); | |
| CFErrorRef rawError = nullptr; | |
| RetainPtr trust = adoptCF(SecTrustCreateFromPropertyListRepresentation((__bridge CFTypeRef)plist.get(), &rawError)); | |
| RetainPtr error = adoptCF(rawError); | |
| EXPECT_NULL(error.get()); | |
| ASSERT_NOT_NULL(trust.get()); | |
| RetainPtr roundTrippedTrust = WebKit::CoreIPCSecTrust(trust.get()).createSecTrust(); | |
| ASSERT_NOT_NULL(roundTrippedTrust.get()); | |
| RetainPtr roundTrippedPlist = adoptCF(SecTrustCopyPropertyListRepresentation(roundTrippedTrust.get(), nullptr)); | |
| NSDictionary *roundTrippedKeySize = ((NSDictionary *)roundTrippedPlist.get())[@"policies"][0][@"policyOptions"][@"KeySize"]; | |
| EXPECT_TRUE([roundTrippedKeySize isEqualToDictionary:keySize.get()]); | |
| runTestCF({ trust.get() }); | |
| RetainPtr protectionSpace = adoptNS([[NSURLProtectionSpace alloc] initWithHost:@"example.local" port:443 protocol:NSURLProtectionSpaceHTTPS realm:nil authenticationMethod:NSURLAuthenticationMethodServerTrust]); | |
| [protectionSpace _setServerTrust:trust.get()]; | |
| RetainPtr decoded = dynamic_objc_cast<NSURLProtectionSpace>(WebKit::CoreIPCNSURLProtectionSpace(protectionSpace.get()).toID().get()); | |
| ASSERT_NOT_NULL(decoded.get()); | |
| EXPECT_NOT_NULL(decoded.get().serverTrust); | |
| runTestNS({ protectionSpace.get() }); | |
| } | |
| #endif | |
| TEST(IPCSerialization, NSShadow) | |
| { | |
| auto runTestNSShadow = [&](CGSize shadowOffset, CGFloat shadowBlurRadius, PlatformColor *shadowColor) { | |
| RetainPtr<NSShadow> shadow = adoptNS([[PlatformNSShadow alloc] init]); | |
| [shadow setShadowOffset:shadowOffset]; | |
| [shadow setShadowBlurRadius:shadowBlurRadius]; | |
| [shadow setShadowColor:shadowColor]; | |
| runTestNS({ shadow.get() }); | |
| }; | |
| runTestNSShadow({ 5.7, 10.5 }, 0.49, nil); | |
| RetainPtr<PlatformColor> platformColor = cocoaColor(WebCore::Color::blue); | |
| runTestNSShadow({ 10.5, 5.7 }, 0.79, platformColor.get()); | |
| } | |
| TEST(IPCSerialization, NSURLRequest) | |
| { | |
| RetainPtr url = [NSURL URLWithString:@"https://webkit.org/"]; | |
| RetainPtr urlRequest = [NSURLRequest requestWithURL:url.get()]; | |
| runTestNS({ urlRequest }); | |
| NSDictionary *jsonDict = @{ | |
| @"a" : @1, | |
| @"b" : @2 | |
| }; | |
| RetainPtr postData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:Nil]; | |
| RetainPtr postRequest = [[NSMutableURLRequest alloc] initWithURL:url.get()]; | |
| [postRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; | |
| [postRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
| [postRequest setHTTPMethod:@"POST"]; | |
| [postRequest setHTTPBody:postData.get()]; | |
| [postRequest _setPrivacyProxyFailClosed:YES]; | |
| runTestNS({ postRequest.get() }); | |
| url = nil; | |
| urlRequest = [NSURLRequest requestWithURL:url.get()]; | |
| runTestNS({ urlRequest }); | |
| } | |
| #if PLATFORM(COCOA) | |
| @interface NSURLRequest (WKSecureCoding) | |
| - (NSDictionary *)_webKitPropertyListData; | |
| - (instancetype)_initWithWebKitPropertyListData:(NSDictionary *)plist; | |
| @end | |
| TEST(IPCSerialization, NSURLRequestProtocolProperties) | |
| { | |
| WebKit::CoreIPCNSURLRequestData requestData; | |
| requestData.url = WebKit::CoreIPCURL([NSURL URLWithString:@"https://webkit.org/"]); | |
| requestData.timeout = 60.0; | |
| WebKit::ProtocolProperties props; | |
| props.isTopLevelNavigation = true; | |
| props.allowAllPOSTCaching = false; | |
| props.siteForCookies = WebKit::CoreIPCString(@"webkit.org"); | |
| props.cachePartitionKey = WebKit::CoreIPCString(@"testPartition"); | |
| props.wkVeryLowLoadPriority = true; | |
| props.fileProtocolExpectedDevice = WebKit::CoreIPCNumber(@123); | |
| props.shouldSniff = false; | |
| props.contentDecoderSkipURLCheck = true; | |
| props.adIdentifier = WebKit::CoreIPCString(@"test-ad-id"); | |
| props.maximumRequestCount = WebKit::CoreIPCNumber(@5); | |
| props.apProxyIsRecursive = true; | |
| props.requestType = WebKit::APProxyRequestType::WebView; | |
| requestData.protocolProperties = WTF::move(props); | |
| WebKit::CoreIPCNSURLRequest wrapper(WTF::move(requestData)); | |
| RetainPtr<id> reconstructed = wrapper.toID(); | |
| EXPECT_TRUE([reconstructed isKindOfClass:[NSURLRequest class]]); | |
| // Verify the reconstructed NSURLRequest has all protocol properties | |
| RetainPtr reconstructedRequest = (NSURLRequest *)reconstructed.get(); | |
| RetainPtr plistData = [reconstructedRequest _webKitPropertyListData]; | |
| RetainPtr protocolProperties = [plistData.get() objectForKey:@"protocolProperties"]; | |
| EXPECT_TRUE(protocolProperties != nil); | |
| EXPECT_EQ([protocolProperties count], 12U); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"_kCFHTTPCookiePolicyPropertyIsTopLevelNavigation"] boolValue]); | |
| EXPECT_FALSE([[protocolProperties objectForKey:@"kCFURLRequestAllowAllPOSTCaching"] boolValue]); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"_kCFHTTPCookiePolicyPropertySiteForCookies"] isEqualToString:@"webkit.org"]); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"_kCFURLCachePartitionKey"] isEqualToString:@"testPartition"]); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"WKVeryLowLoadPriority"] boolValue]); | |
| EXPECT_EQ([[protocolProperties objectForKey:@"NSURLRequestFileProtocolExpectedDevice"] intValue], 123); | |
| EXPECT_FALSE([[protocolProperties objectForKey:@"_kCFURLConnectionPropertyShouldSniff"] boolValue]); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"kCFURLRequestContentDecoderSkipURLCheck"] boolValue]); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"adIdentifier"] isEqualToString:@"test-ad-id"]); | |
| EXPECT_EQ([[protocolProperties objectForKey:@"maximumRequestCount"] intValue], 5); | |
| EXPECT_TRUE([[protocolProperties objectForKey:@"com.apple.ap.pc.proxy-is-recursive"] boolValue]); | |
| EXPECT_EQ([[protocolProperties objectForKey:@"requestType"] intValue], 1); | |
| // Test full round-trip serialization | |
| runTestNS({ reconstructedRequest }); | |
| // Test with partial fields set | |
| WebKit::CoreIPCNSURLRequestData requestData2; | |
| requestData2.url = WebKit::CoreIPCURL([NSURL URLWithString:@"https://example.com/"]); | |
| requestData2.timeout = 30.0; | |
| WebKit::ProtocolProperties props2; | |
| props2.isTopLevelNavigation = false; | |
| props2.cachePartitionKey = WebKit::CoreIPCString(@"partition2"); | |
| requestData2.protocolProperties = WTF::move(props2); | |
| WebKit::CoreIPCNSURLRequest wrapper2(WTF::move(requestData2)); | |
| RetainPtr<id> reconstructed2 = wrapper2.toID(); | |
| EXPECT_TRUE([reconstructed2 isKindOfClass:[NSURLRequest class]]); | |
| RetainPtr reconstructedRequest2 = (NSURLRequest *)reconstructed2.get(); | |
| RetainPtr plistData2 = [reconstructedRequest2 _webKitPropertyListData]; | |
| RetainPtr protocolProperties2 = [plistData2.get() objectForKey:@"protocolProperties"]; | |
| EXPECT_TRUE(protocolProperties2 != nil); | |
| EXPECT_EQ([protocolProperties2 count], 2U); | |
| EXPECT_FALSE([[protocolProperties2 objectForKey:@"_kCFHTTPCookiePolicyPropertyIsTopLevelNavigation"] boolValue]); | |
| EXPECT_TRUE([[protocolProperties2 objectForKey:@"_kCFURLCachePartitionKey"] isEqualToString:@"partition2"]); | |
| runTestNS({ reconstructedRequest2 }); | |
| // Test edge cases | |
| WebKit::CoreIPCNSURLRequestData requestData3; | |
| requestData3.url = WebKit::CoreIPCURL([NSURL URLWithString:@"https://test.org/"]); | |
| requestData3.timeout = 15.0; | |
| WebKit::ProtocolProperties props3; | |
| props3.siteForCookies = WebKit::CoreIPCString(@""); | |
| props3.cachePartitionKey = WebKit::CoreIPCString(@"🎉"); | |
| props3.fileProtocolExpectedDevice = WebKit::CoreIPCNumber(@0); | |
| requestData3.protocolProperties = WTF::move(props3); | |
| WebKit::CoreIPCNSURLRequest wrapper3(WTF::move(requestData3)); | |
| RetainPtr<id> reconstructed3 = wrapper3.toID(); | |
| EXPECT_TRUE([reconstructed3 isKindOfClass:[NSURLRequest class]]); | |
| RetainPtr reconstructedRequest3 = (NSURLRequest *)reconstructed3.get(); | |
| RetainPtr plistData3 = [reconstructedRequest3 _webKitPropertyListData]; | |
| RetainPtr protocolProperties3 = [plistData3.get() objectForKey:@"protocolProperties"]; | |
| EXPECT_TRUE(protocolProperties3 != nil); | |
| EXPECT_EQ([protocolProperties3 count], 3U); | |
| EXPECT_TRUE([[protocolProperties3 objectForKey:@"_kCFHTTPCookiePolicyPropertySiteForCookies"] isEqualToString:@""]); | |
| EXPECT_TRUE([[protocolProperties3 objectForKey:@"_kCFURLCachePartitionKey"] isEqualToString:@"🎉"]); | |
| EXPECT_EQ([[protocolProperties3 objectForKey:@"NSURLRequestFileProtocolExpectedDevice"] intValue], 0); | |
| runTestNS({ reconstructedRequest3 }); | |
| } | |
| TEST(IPCSerialization, NSURLRequestNSURLProtocolProperties) | |
| { | |
| RetainPtr request = adoptNS([[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://webkit.org/"]]); | |
| [NSURLProtocol setProperty:@"ad-123" forKey:@"adIdentifier" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@3 forKey:@"maximumRequestCount" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@YES forKey:@"com.apple.ap.pc.proxy-is-recursive" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@2 forKey:@"requestType" inRequest:request.get()]; | |
| WebKit::CoreIPCNSURLRequest wrapper(request.get()); | |
| RetainPtr reconstructed = dynamic_objc_cast<NSURLRequest>(wrapper.toID().get()); | |
| EXPECT_TRUE(reconstructed); | |
| EXPECT_TRUE([[NSURLProtocol propertyForKey:@"adIdentifier" inRequest:reconstructed.get()] isEqualToString:@"ad-123"]); | |
| EXPECT_EQ([[NSURLProtocol propertyForKey:@"maximumRequestCount" inRequest:reconstructed.get()] intValue], 3); | |
| EXPECT_TRUE([[NSURLProtocol propertyForKey:@"com.apple.ap.pc.proxy-is-recursive" inRequest:reconstructed.get()] boolValue]); | |
| EXPECT_EQ([[NSURLProtocol propertyForKey:@"requestType" inRequest:reconstructed.get()] integerValue], 2); | |
| runTestNS({ request.get() }); | |
| } | |
| TEST(IPCSerialization, NSURLRequestArbitraryAppProperties) | |
| { | |
| // App-supplied properties via NSURLProtocol +setProperty:forKey:inRequest: that are | |
| // not in the typed allowlist must still round-trip through IPC, but only when they | |
| // are plist-primitive values (NSNumber/NSString/NSData) and the key is not in a | |
| // reserved CFNetwork/Foundation/WebKit/Apple namespace. | |
| RetainPtr request = adoptNS([[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://webkit.org/"]]); | |
| // Allowed app-supplied entries: number, string, bool (NSNumber), data. | |
| [NSURLProtocol setProperty:@"hello" forKey:@"com.example.appName" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@42 forKey:@"com.example.requestCount" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@YES forKey:@"com.example.featureFlag" inRequest:request.get()]; | |
| RetainPtr<NSData> blob = [NSData dataWithBytes:"\x01\x02\x03\x04" length:4]; | |
| [NSURLProtocol setProperty:blob.get() forKey:@"com.example.blob" inRequest:request.get()]; | |
| // Disallowed values: complex container types must be dropped on the wire. | |
| [NSURLProtocol setProperty:@{ @"nested": @1 } forKey:@"com.example.dictValue" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@[ @"a", @"b" ] forKey:@"com.example.arrayValue" inRequest:request.get()]; | |
| // Disallowed key: reserved-prefix keys an app should not be able to spoof over IPC. | |
| [NSURLProtocol setProperty:@"injected" forKey:@"_kCFFutureInternalProperty" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@"injected" forKey:@"NSURLRequestFutureInternalProperty" inRequest:request.get()]; | |
| [NSURLProtocol setProperty:@"injected" forKey:@"com.apple.something-private" inRequest:request.get()]; | |
| WebKit::CoreIPCNSURLRequest wrapper(request.get()); | |
| RetainPtr reconstructed = dynamic_objc_cast<NSURLRequest>(wrapper.toID().get()); | |
| EXPECT_TRUE(reconstructed); | |
| EXPECT_TRUE([[NSURLProtocol propertyForKey:@"com.example.appName" inRequest:reconstructed.get()] isEqualToString:@"hello"]); | |
| EXPECT_EQ([[NSURLProtocol propertyForKey:@"com.example.requestCount" inRequest:reconstructed.get()] intValue], 42); | |
| EXPECT_TRUE([[NSURLProtocol propertyForKey:@"com.example.featureFlag" inRequest:reconstructed.get()] boolValue]); | |
| EXPECT_TRUE([[NSURLProtocol propertyForKey:@"com.example.blob" inRequest:reconstructed.get()] isEqualToData:blob.get()]); | |
| EXPECT_NULL([NSURLProtocol propertyForKey:@"com.example.dictValue" inRequest:reconstructed.get()]); | |
| EXPECT_NULL([NSURLProtocol propertyForKey:@"com.example.arrayValue" inRequest:reconstructed.get()]); | |
| EXPECT_NULL([NSURLProtocol propertyForKey:@"_kCFFutureInternalProperty" inRequest:reconstructed.get()]); | |
| EXPECT_NULL([NSURLProtocol propertyForKey:@"NSURLRequestFutureInternalProperty" inRequest:reconstructed.get()]); | |
| EXPECT_NULL([NSURLProtocol propertyForKey:@"com.apple.something-private" inRequest:reconstructed.get()]); | |
| // Full wire-format round-trip on a request containing only the allowed entries — | |
| // runTestNS asserts that the original and the round-tripped request compare equal, | |
| // so we cannot include the keys we expect to be stripped above. | |
| RetainPtr cleanRequest = adoptNS([[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://webkit.org/"]]); | |
| [NSURLProtocol setProperty:@"hello" forKey:@"com.example.appName" inRequest:cleanRequest.get()]; | |
| [NSURLProtocol setProperty:@42 forKey:@"com.example.requestCount" inRequest:cleanRequest.get()]; | |
| [NSURLProtocol setProperty:@YES forKey:@"com.example.featureFlag" inRequest:cleanRequest.get()]; | |
| [NSURLProtocol setProperty:blob.get() forKey:@"com.example.blob" inRequest:cleanRequest.get()]; | |
| runTestNS({ cleanRequest.get() }); | |
| } | |
| TEST(IPCSerialization, NSURLRequestAttribution) | |
| { | |
| WebKit::CoreIPCNSURLRequestData requestData; | |
| requestData.url = WebKit::CoreIPCURL([NSURL URLWithString:@"https://webkit.org/"]); | |
| requestData.attribution = WebKit::NSURLRequestAttribution::User; | |
| RetainPtr request = dynamic_objc_cast<NSURLRequest>(WebKit::CoreIPCNSURLRequest(WTF::move(requestData)).toID().get()); | |
| RetainPtr reconstructed = dynamic_objc_cast<NSURLRequest>(WebKit::CoreIPCNSURLRequest(request.get()).toID().get()); | |
| EXPECT_EQ([reconstructed attribution], NSURLRequestAttributionUser); | |
| } | |
| #endif // PLATFORM(COCOA) | |
| #if USE(AVFOUNDATION) && PLATFORM(MAC) | |
| TEST(IPCSerialization, AVOutputContext) | |
| { | |
| RetainPtr<AVOutputContext> outputContext = adoptNS([[PAL::getAVOutputContextClassSingleton() alloc] init]); | |
| runTestNS({ outputContext.get() }); | |
| } | |
| #endif // USE(AVFOUNDATION) && PLATFORM(MAC) | |
| #if USE(PASSKIT) && HAVE(WK_SECURE_CODING_PKPAYMENTSETUPFEATURE) | |
| TEST(IPCSerialization, PKPaymentSetupFeature) | |
| { | |
| WebKit::CoreIPCPKPaymentSetupFeatureData data; | |
| Vector<RetainPtr<NSString>> identifiers; | |
| identifiers.append(@"identifier1"); | |
| identifiers.append(@"identifier2"); | |
| identifiers.append(@"identifier3"); | |
| data.identifiers = WTF::move(identifiers); | |
| data.localizedDisplayName = @"Test Payment Feature"; | |
| data.type = WebKit::PKPaymentSetupFeatureType::AppleCard; | |
| data.state = WebKit::PKPaymentSetupFeatureState::Supported; | |
| data.supportedOptions = WebKit::PKPaymentSetupFeatureSupportedOptions::Installments; | |
| data.supportedDevices = OptionSet<WebKit::PKPaymentSetupFeatureSupportedDevices> { | |
| WebKit::PKPaymentSetupFeatureSupportedDevices::Phone, | |
| WebKit::PKPaymentSetupFeatureSupportedDevices::Watch | |
| }; | |
| data.productIdentifier = @"product123"; | |
| data.partnerIdentifier = @"partner456"; | |
| data.featureIdentifier = @(789); | |
| data.lastUpdated = [NSDate dateWithTimeIntervalSince1970:1000000]; | |
| data.expiry = [NSDate dateWithTimeIntervalSince1970:2000000]; | |
| data.productType = @(5); | |
| data.productState = @(6); | |
| data.notificationTitle = @"Setup Complete"; | |
| data.notificationMessage = @"Your payment feature is ready"; | |
| data.discoveryCardIdentifier = @"discovery999"; | |
| WebKit::CoreIPCPKPaymentSetupFeature PaymentSetupFeature { std::optional { WTF::move(data) } }; | |
| RetainPtr<PKPaymentSetupFeature> feature = PaymentSetupFeature.toID(); | |
| runTestNS({ feature.get() }); | |
| } | |
| #endif | |
| #if USE(PASSKIT) && HAVE(WK_SECURE_CODING_PKPAYMENT) | |
| TEST(IPCSerialization, PKPayment) | |
| { | |
| RetainPtr<PKPaymentMethod> paymentMethod = adoptNS([PAL::getPKPaymentMethodClassSingleton() new]); | |
| paymentMethod.get().displayName = @"WebKitPay"; | |
| paymentMethod.get().network = @"WebKitCard"; | |
| paymentMethod.get().type = PKPaymentMethodTypeCredit; | |
| RetainPtr<PKPaymentToken> paymentToken = adoptNS([PAL::getPKPaymentTokenClassSingleton() new]); | |
| paymentToken.get().paymentMethod = paymentMethod.get(); | |
| paymentToken.get().transactionIdentifier = @"WebKitTXIdentifier"; | |
| paymentToken.get().paymentData = adoptNS([NSData new]); | |
| WebKit::CoreIPCPKPaymentData data; | |
| data.token = paymentToken.get(); | |
| data.shippingContact = pkContactForTesting().get(); | |
| data.billingContact = pkContactForTesting().get(); | |
| RetainPtr<PKShippingMethod> shippingMethod = adoptNS([PAL::getPKShippingMethodClassSingleton() new]); | |
| shippingMethod.get().identifier = @"WebKitPostalService"; | |
| shippingMethod.get().detail = @"Ships in 1 to 2 bugzillas"; | |
| data.shippingMethod = shippingMethod.get(); | |
| data.credential = [NSData dataWithBytes:"AAAA" length:4]; | |
| data.biometryAttempts = @(2); | |
| data.installmentAuthorizationToken = @"InstallmentToken123"; | |
| WebKit::CoreIPCPKPayment paymentWrapper { std::optional { WTF::move(data) } }; | |
| RetainPtr<PKPayment> payment = paymentWrapper.toID(); | |
| EXPECT_TRUE([payment isKindOfClass:PAL::getPKPaymentClassSingleton()]); | |
| runTestNS({ payment.get() }); | |
| WebKit::CoreIPCPKPayment nilWrapper(nil); | |
| RetainPtr<id> nilPayment = nilWrapper.toID(); | |
| EXPECT_TRUE(nilPayment.get() == nil); | |
| } | |
| #endif | |
| #if !HAVE(WEBCONTENTRESTRICTIONS) && HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER) | |
| @interface WebFilterEvaluator (IPCSerializationTesting) | |
| - (instancetype)initWithCoder:(NSCoder *)coder; | |
| @end | |
| TEST(IPCSerialization, WebFilterEvaluator) | |
| { | |
| // WebFilterEvaluator does not implement -_initWithWebKitPropertyListData:, so both ends of the | |
| // IPC need to go through WKKeyedCoder instead of a WebKit secure coding property list. | |
| RetainPtr coder = adoptNS([[WKKeyedCoder alloc] initWithDictionary:@{ | |
| @"WebContentFilterStateKey": @(kWFEStateBlocked), | |
| @"WebContentFilterURLKey": [NSURL URLWithString:@"https://webkit.org/"], | |
| @"WebContentFilterPageTitleKey": @"WebKit" | |
| }]); | |
| RetainPtr<WebFilterEvaluator> evaluator = adoptNS([PAL::allocWebFilterEvaluatorInstance() initWithCoder:coder.get()]); | |
| EXPECT_NOT_NULL(evaluator.get()); | |
| runTestNS({ evaluator.get() }); | |
| } | |
| #endif // !HAVE(WEBCONTENTRESTRICTIONS) && HAVE(PARENTAL_CONTROLS_WITH_UNBLOCK_HANDLER) | |
| #if PLATFORM(MAC) | |
| static RetainPtr<DDScannerResult> fakeDataDetectorResultForTesting() | |
| { | |
| RetainPtr scanner = adoptCF(PAL::softLink_DataDetectorsCore_DDScannerCreate(DDScannerTypeStandard, 0, nullptr)); | |
| auto stringToScan = CFSTR("webkit.org"); | |
| RetainPtr query = adoptCF(PAL::softLink_DataDetectorsCore_DDScanQueryCreateFromString(kCFAllocatorDefault, stringToScan, CFRangeMake(0, CFStringGetLength(stringToScan)))); | |
| if (!PAL::softLink_DataDetectorsCore_DDScannerScanQuery(scanner.get(), query.get())) | |
| return nil; | |
| RetainPtr results = adoptCF(PAL::softLink_DataDetectorsCore_DDScannerCopyResultsWithOptions(scanner.get(), DDScannerCopyResultsOptionsNoOverlap)); | |
| if (!CFArrayGetCount(results.get())) | |
| return nil; | |
| return [[PAL::getDDScannerResultClassSingleton() resultsFromCoreResults:results.get()] firstObject]; | |
| } | |
| #if HAVE(WK_SECURE_CODING_DATA_DETECTORS) | |
| static RetainPtr<DDScannerResult> fakeDataDetectorResultWithContextualData() | |
| { | |
| NSDictionary *plist = @{ | |
| @"AR": [NSValue valueWithRange:NSMakeRange(0, 10)], | |
| @"MS": @"webkit.org", | |
| @"T": @"Link", | |
| @"P": @1, | |
| @"VN": @1, | |
| @"C": @{ | |
| @"C": @"addressBookUID-12345", | |
| @"D": @"webkit.org", | |
| @"U": @"uuid-67890-abcdef", | |
| @"urlificationBegin": @2, | |
| @"urlificationLength": @8 | |
| } | |
| }; | |
| return adoptNS([[PAL::getDDScannerResultClassSingleton() alloc] _initWithWebKitPropertyListData:plist]); | |
| } | |
| TEST(IPCSerialization, DDScannerResultPlist) | |
| { | |
| auto scannerResult = fakeDataDetectorResultWithContextualData(); | |
| EXPECT_NOT_NULL(scannerResult.get()); | |
| NSDictionary *originalPlist = [scannerResult _webKitPropertyListData]; | |
| NSDictionary *originalContextualData = originalPlist[@"C"]; | |
| EXPECT_NOT_NULL(originalContextualData); | |
| EXPECT_TRUE([originalContextualData[@"C"] isEqualToString:@"addressBookUID-12345"]); | |
| EXPECT_TRUE([originalContextualData[@"D"] isEqualToString:@"webkit.org"]); | |
| EXPECT_TRUE([originalContextualData[@"U"] isEqualToString:@"uuid-67890-abcdef"]); | |
| EXPECT_TRUE([originalContextualData[@"urlificationBegin"] isEqualToNumber:@2]); | |
| EXPECT_TRUE([originalContextualData[@"urlificationLength"] isEqualToNumber:@8]); | |
| __block bool done = false; | |
| __block ObjCHolderForTesting holder { scannerResult.get() }; | |
| auto sender = SerializationTestSender { }; | |
| sender.sendWithAsyncReplyWithoutUsingIPCConnection(ObjCPingBackMessage(holder), ^(ObjCHolderForTesting&& result) { | |
| EXPECT_TRUE(holder == result); | |
| id resultObject = result.valueAsID(); | |
| EXPECT_NOT_NULL(resultObject); | |
| EXPECT_TRUE([resultObject isKindOfClass:PAL::getDDScannerResultClassSingleton()]); | |
| NSDictionary *resultPlist = [resultObject _webKitPropertyListData]; | |
| NSDictionary *resultContextualData = resultPlist[@"C"]; | |
| EXPECT_NOT_NULL(resultContextualData); | |
| EXPECT_TRUE([resultContextualData[@"C"] isEqualToString:@"addressBookUID-12345"]); | |
| EXPECT_TRUE([resultContextualData[@"D"] isEqualToString:@"webkit.org"]); | |
| EXPECT_TRUE([resultContextualData[@"U"] isEqualToString:@"uuid-67890-abcdef"]); | |
| EXPECT_TRUE([resultContextualData[@"urlificationBegin"] isEqualToNumber:@2]); | |
| EXPECT_TRUE([resultContextualData[@"urlificationLength"] isEqualToNumber:@8]); | |
| done = true; | |
| }); | |
| EXPECT_TRUE(done); | |
| } | |
| #endif // HAVE(WK_SECURE_CODING_DATA_DETECTORS) | |
| #if HAVE(WK_SECURE_CODING_NSURLCREDENTIAL) | |
| @interface NSURLCredential (WKSecureCodingForTesting) | |
| - (instancetype)_initWithWebKitPropertyListData:(NSDictionary *)plist; | |
| - (NSDictionary *)_webKitPropertyListData; | |
| @end | |
| TEST(IPCSerialization, NSURLCredentialKerberosFlags) | |
| { | |
| RetainPtr credential = adoptNS([[NSURLCredential alloc] _initWithWebKitPropertyListData:@{ | |
| @"type": @(kURLCredentialKerberosTicket), | |
| @"uuid": @"uuid", | |
| @"flags": @{ @"name": @"value" }, | |
| }]); | |
| IPC::Encoder encoder(IPC::MessageName::IPCTester_EmptyMessage, 0); | |
| encoder << WebKit::CoreIPCNSURLCredential { credential.get() }; | |
| auto decoder = IPC::Decoder::create(encoder.span(), encoder.releaseAttachments()); | |
| auto decoded = decoder->decode<WebKit::CoreIPCNSURLCredentialData>(); | |
| EXPECT_FALSE(decoded->flags->isEmpty()); | |
| } | |
| TEST(IPCSerialization, NSURLCredentialAttributes) | |
| { | |
| RetainPtr credential = adoptNS([[NSURLCredential alloc] _initWithWebKitPropertyListData:@{ | |
| @"type": @(kURLCredentialInternetPassword), | |
| @"persistence": @(kCFURLCredentialPersistenceForSession), | |
| @"attributes": @{ @"name": @"value" }, | |
| }]); | |
| IPC::Encoder encoder(IPC::MessageName::IPCTester_EmptyMessage, 0); | |
| encoder << WebKit::CoreIPCNSURLCredential { credential.get() }; | |
| auto decoder = IPC::Decoder::create(encoder.span(), encoder.releaseAttachments()); | |
| auto decoded = decoder->decode<WebKit::CoreIPCNSURLCredentialData>(); | |
| EXPECT_EQ(decoded->attributes->size(), 1u); | |
| } | |
| TEST(IPCSerialization, NSURLCredentialAttributesToID) | |
| { | |
| using Attributes = WebKit::CoreIPCNSURLCredentialData::Attributes; | |
| WebKit::CoreIPCNSURLCredentialData credentialData; | |
| credentialData.type = WebKit::CoreIPCNSURLCredentialType::Password; | |
| credentialData.attributes = Vector<Attributes> { { WebKit::CoreIPCString(@"key"), WebKit::CoreIPCString(@"value") } }; | |
| WebKit::CoreIPCNSURLCredential wrapper(WTF::move(credentialData)); | |
| RetainPtr reconstructed = dynamic_objc_cast<NSURLCredential>(wrapper.toID().get()); | |
| RetainPtr attributes = dynamic_objc_cast<NSDictionary>([[reconstructed _webKitPropertyListData] objectForKey:@"attributes"]); | |
| EXPECT_TRUE([[attributes objectForKey:@"key"] isEqual:@"value"]); | |
| } | |
| #endif // HAVE(WK_SECURE_CODING_NSURLCREDENTIAL) | |
| @interface PKPaymentMerchantSession () | |
| - (instancetype)initWithMerchantIdentifier:(NSString *)merchantIdentifier | |
| merchantSessionIdentifier:(NSString *)merchantSessionIdentifier | |
| nonce:(NSString *)nonce | |
| epochTimestamp:(NSUInteger)epochTimestamp | |
| expiresAt:(NSUInteger)expiresAt | |
| displayName:(NSString *)displayName | |
| initiativeContext:(NSString *)initiativeContext | |
| initiative:(NSString *)initiative | |
| ampEnrollmentPinning:(NSData *)ampEnrollmentPinning | |
| operationalAnalyticsIdentifier:(NSString *)operationalAnalyticsIdentifier | |
| signedFields:(NSArray<NSString *> *)signedFields | |
| signature:(NSData *)signature; | |
| - (instancetype)initWithMerchantIdentifier:(NSString *)merchantIdentifier | |
| merchantSessionIdentifier:(NSString *)merchantSessionIdentifier | |
| nonce:(NSString *)nonce | |
| epochTimestamp:(NSUInteger)epochTimestamp | |
| expiresAt:(NSUInteger)expiresAt | |
| domain:(NSString *)domainName | |
| displayName:(NSString *)displayName | |
| operationalAnalyticsIdentifier:(NSString *)operationalAnalyticsIdentifier | |
| signature:(NSData *)signature; | |
| #if HAVE(PASSKIT_DELEGATED_REQUEST) | |
| - (instancetype)initWithDelegateDisplayName:(NSString *)delegateDisplayName | |
| merchantIdentifier:(NSString *)merchantIdentifier | |
| displayName:(NSString *)displayName | |
| initiative:(NSString *)initiative | |
| initiativeContext:(NSString *)initiativeContext | |
| merchantSessionIdentifier:(NSString *)merchantSessionIdentifier | |
| nonce:(NSString *)nonce | |
| epochTimestamp:(NSUInteger)epochTimestamp | |
| expiresAt:(NSUInteger)expiresAt | |
| operationalAnalyticsIdentifier:(NSString *)operationalAnalyticsIdentifier | |
| signedFields:(NSArray<NSString *> *)signedFields | |
| signature:(NSData *)signature; | |
| #endif | |
| @end | |
| TEST(IPCSerialization, DataDetectors) | |
| { | |
| // DDScannerResult | |
| // - Note: For now, there's no reasonable way to create anything but an empty DDScannerResult object | |
| auto scannerResult = fakeDataDetectorResultForTesting(); | |
| runTestNS({ scannerResult.get() }); | |
| // DDActionContext/DDSecureActionContext | |
| RetainPtr actionContext = adoptNS([PAL::allocWKDDActionContextInstance() init]); | |
| [actionContext setAllResults:@[ (__bridge id)scannerResult.get().coreResult ]]; | |
| [actionContext setMainResult:scannerResult.get().coreResult]; | |
| auto components = personNameComponentsForTesting(); | |
| [actionContext setAuthorNameComponents:components.get()]; | |
| [actionContext setHighlightFrame:NSMakeRect(1, 2, 3, 4)]; | |
| runTestNS({ actionContext.get() }); | |
| } | |
| TEST(IPCSerialization, SecureCoding) | |
| { | |
| // PKPaymentMerchantSession | |
| // This initializer doesn't exercise retryNonce or domain | |
| RetainPtr<PKPaymentMerchantSession> session = adoptNS([[PAL::getPKPaymentMerchantSessionClassSingleton() alloc] | |
| initWithMerchantIdentifier:@"WebKit Open Source Project" | |
| merchantSessionIdentifier:@"WebKitMerchantSession" | |
| nonce:@"WebKitNonce" | |
| epochTimestamp:1000000000 | |
| expiresAt:2000000000 | |
| displayName:@"WebKit" | |
| initiativeContext:@"WebKit IPC Testing" | |
| initiative:@"WebKit Regression Test Suite" | |
| ampEnrollmentPinning:nil | |
| operationalAnalyticsIdentifier:@"WebKitOperations42" | |
| signedFields:@[ @"FirstField", @"AndTheSecond" ] | |
| signature:[NSData new]]); | |
| runTestNS({ session.get() }); | |
| // This initializer adds in domain, but retryNonce is still unexercised | |
| session = adoptNS([[PAL::getPKPaymentMerchantSessionClassSingleton() alloc] | |
| initWithMerchantIdentifier:@"WebKit Open Source Project" | |
| merchantSessionIdentifier:@"WebKitMerchantSession" | |
| nonce:@"WebKitNonce" | |
| epochTimestamp:1000000000 | |
| expiresAt:2000000000 | |
| domain:@"webkit.org" | |
| displayName:@"WebKit" | |
| operationalAnalyticsIdentifier:@"WebKitOperations42" | |
| signature:[NSData new]]); | |
| runTestNS({ session.get() }); | |
| #if HAVE(PASSKIT_DELEGATED_REQUEST) | |
| // This initializer adopts delegate fields, but retryNonce and domain are unexercised | |
| session = adoptNS([[PAL::getPKPaymentMerchantSessionClassSingleton() alloc] | |
| initWithDelegateDisplayName:@"WebKit (Delegate)" | |
| merchantIdentifier:@"WebKit Open Source Project" | |
| displayName:@"WebKit" | |
| initiative:@"WebKit Regression Test Suite" | |
| initiativeContext:@"WebKit IPC Testing" | |
| merchantSessionIdentifier:@"WebKitMerchantSession" | |
| nonce:@"WebKitNonce" | |
| epochTimestamp:1000000000 | |
| expiresAt:2000000000 | |
| operationalAnalyticsIdentifier:@"WebKitOperations42" | |
| signedFields:@[ @"FirstField", @"AndTheSecond" ] | |
| signature:[NSData new]]); | |
| runTestNS({ session.get() }); | |
| #endif | |
| RetainPtr<CNPostalAddress> address = postalAddressForTesting(); | |
| RetainPtr<CNLabeledValue> labeledPostalAddress = adoptNS([[PAL::getCNLabeledValueClassSingleton() alloc] initWithLabel:@"Work" value:address.get()]); | |
| RetainPtr<CNLabeledValue> labeledEmailAddress = adoptNS([[PAL::getCNLabeledValueClassSingleton() alloc] initWithLabel:@"WorkSPAM" value:@"spam@webkit.org"]); | |
| RetainPtr<CNMutableContact> billingContact = adoptNS([PAL::getCNMutableContactClassSingleton() new]); | |
| billingContact.get().contactType = CNContactTypePerson; | |
| billingContact.get().namePrefix = @"Mrs"; | |
| billingContact.get().givenName = @"WebKit"; | |
| billingContact.get().middleName = @"von"; | |
| billingContact.get().familyName = @"WebKittington"; | |
| billingContact.get().nameSuffix = @"The Third"; | |
| billingContact.get().organizationName = @"WebKit"; | |
| billingContact.get().jobTitle = @"Web Kitten"; | |
| billingContact.get().note = @"The Coolest Kitten out there"; | |
| billingContact.get().postalAddresses = @[ labeledPostalAddress.get() ]; | |
| billingContact.get().emailAddresses = @[ labeledEmailAddress.get() ]; | |
| runTestNS({ billingContact.get() }); | |
| RetainPtr<PKPaymentMethod> paymentMethod = adoptNS([PAL::getPKPaymentMethodClassSingleton() new]); | |
| paymentMethod.get().displayName = @"WebKitPay"; | |
| paymentMethod.get().network = @"WebKitCard"; | |
| paymentMethod.get().type = PKPaymentMethodTypeCredit; | |
| paymentMethod.get().billingAddress = billingContact.get(); | |
| runTestNS({ paymentMethod.get() }); | |
| RetainPtr<PKPaymentToken> paymentToken = adoptNS([PAL::getPKPaymentTokenClassSingleton() new]); | |
| paymentToken.get().paymentMethod = paymentMethod.get(); | |
| paymentToken.get().transactionIdentifier = @"WebKitTXIdentifier"; | |
| paymentToken.get().paymentData = [NSData new]; | |
| paymentToken.get().redeemURL = [NSURL URLWithString:@"https://webkit.org/"]; | |
| paymentToken.get().retryNonce = @"ANonce"; | |
| runTestNS({ paymentToken.get() }); | |
| RetainPtr<NSDateComponents> startComponents = adoptNS([NSDateComponents new]); | |
| runTestNS({ startComponents.get() }); | |
| [startComponents setValue:1 forComponent:NSCalendarUnitEra]; | |
| [startComponents setValue:2 forComponent:NSCalendarUnitYear]; | |
| [startComponents setValue:3 forComponent:NSCalendarUnitYearForWeekOfYear]; | |
| [startComponents setValue:4 forComponent:NSCalendarUnitQuarter]; | |
| [startComponents setValue:5 forComponent:NSCalendarUnitMonth]; | |
| [startComponents setValue:6 forComponent:NSCalendarUnitHour]; | |
| [startComponents setValue:7 forComponent:NSCalendarUnitMinute]; | |
| [startComponents setValue:8 forComponent:NSCalendarUnitSecond]; | |
| [startComponents setValue:9 forComponent:NSCalendarUnitNanosecond]; | |
| [startComponents setValue:10 forComponent:NSCalendarUnitWeekOfYear]; | |
| [startComponents setValue:11 forComponent:NSCalendarUnitWeekOfMonth]; | |
| [startComponents setValue:12 forComponent:NSCalendarUnitWeekday]; | |
| [startComponents setValue:13 forComponent:NSCalendarUnitWeekdayOrdinal]; | |
| [startComponents setValue:14 forComponent:NSCalendarUnitDay]; | |
| startComponents.get().calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierBuddhist]; | |
| startComponents.get().timeZone = [NSTimeZone timeZoneWithName:@"Asia/Calcutta"]; | |
| runTestNS({ startComponents.get() }); | |
| startComponents = adoptNS([NSDateComponents new]); | |
| startComponents.get().day = 1; | |
| startComponents.get().month = 4; | |
| startComponents.get().year = 1976; | |
| startComponents.get().calendar = NSCalendar.currentCalendar; | |
| RetainPtr<NSDateComponents> endComponents = adoptNS([NSDateComponents new]); | |
| endComponents.get().day = 9; | |
| endComponents.get().month = 1; | |
| endComponents.get().year = 2007; | |
| endComponents.get().calendar = NSCalendar.currentCalendar; | |
| runTestNS({ endComponents.get() }); | |
| RetainPtr<PKDateComponentsRange> dateRange = adoptNS([[PAL::getPKDateComponentsRangeClassSingleton() alloc] initWithStartDateComponents:startComponents.get() endDateComponents:endComponents.get()]); | |
| runTestNS({ dateRange.get() }); | |
| RetainPtr<PKShippingMethod> shippingMethod = adoptNS([PAL::getPKShippingMethodClassSingleton() new]); | |
| shippingMethod.get().identifier = @"WebKitPostalService"; | |
| shippingMethod.get().detail = @"Ships in 1 to 2 bugzillas"; | |
| shippingMethod.get().dateComponentsRange = dateRange.get(); | |
| runTestNS({ shippingMethod.get() }); | |
| RetainPtr<PKPayment> payment = adoptNS([PAL::getPKPaymentClassSingleton() new]); | |
| payment.get().token = paymentToken.get(); | |
| payment.get().billingContact = pkContactForTesting().get(); | |
| payment.get().shippingContact = pkContactForTesting().get(); | |
| payment.get().shippingMethod = shippingMethod.get(); | |
| runTestNS({ payment.get() }); | |
| } | |
| #if USE(PASSKIT) && HAVE(WK_SECURE_CODING_PKSHIPPINGMETHOD) | |
| TEST(IPCSerialization, PKShippingMethod) | |
| { | |
| RetainPtr<NSDateComponents> startComponents = adoptNS([NSDateComponents new]); | |
| startComponents.get().day = 15; | |
| startComponents.get().month = 6; | |
| startComponents.get().year = 2026; | |
| startComponents.get().calendar = NSCalendar.currentCalendar; | |
| RetainPtr<NSDateComponents> endComponents = adoptNS([NSDateComponents new]); | |
| endComponents.get().day = 20; | |
| endComponents.get().month = 6; | |
| endComponents.get().year = 2026; | |
| endComponents.get().calendar = NSCalendar.currentCalendar; | |
| RetainPtr<PKDateComponentsRange> dateRange = adoptNS([[PAL::getPKDateComponentsRangeClassSingleton() alloc] initWithStartDateComponents:startComponents.get() endDateComponents:endComponents.get()]); | |
| WebKit::CoreIPCPKShippingMethodData data; | |
| data.label = @"Standard Shipping"; | |
| data.amount = [NSDecimalNumber decimalNumberWithString:@"5.99"]; | |
| data.type = WebKit::PKPaymentSummaryItemType::Final; | |
| data.localizedTitle = @"Standard"; | |
| data.localizedAmount = @"$5.99"; | |
| data.useDarkColor = false; | |
| data.useLargeFont = false; | |
| data.identifier = @"standard-shipping"; | |
| data.detail = @"Arrives in 3-5 business days"; | |
| data.dateComponentsRange = dateRange; | |
| WebKit::CoreIPCPKShippingMethod shippingMethod { std::optional { WTF::move(data) } }; | |
| RetainPtr<PKShippingMethod> method = shippingMethod.toID(); | |
| runTestNS({ method.get() }); | |
| } | |
| #endif | |
| #endif // PLATFORM(MAC) | |
| TEST(CoreIPCCFDictionary, InsertDifferentValueTypes) | |
| { | |
| // Test that a CoreIPCCFDictionary can be created, encoded, and decoded with valid key-value pairs. | |
| // Keys will be string type (CFStringRef). | |
| // Values will be all possible variants from IPC::CFType. | |
| RetainPtr cfDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); | |
| // CFBooleanRef | |
| RetainPtr booleanKey = adoptCF(CFSTR("booleanKey")); | |
| RetainPtr booleanValue = adoptCF(kCFBooleanFalse); | |
| CFDictionaryAddValue(cfDictionary.get(), booleanKey.get(), booleanValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 1); | |
| // CFCharacterSetRef | |
| RetainPtr charSetKey = adoptCF(CFSTR("charSetKey")); | |
| RetainPtr charSetValue = adoptCF(CFCharacterSetCreateWithCharactersInString(kCFAllocatorDefault, CFSTR("ABC"))); | |
| CFDictionaryAddValue(cfDictionary.get(), charSetKey.get(), charSetValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 2); | |
| // CFDataRef | |
| RetainPtr dataKey = adoptCF(CFSTR("dataKey")); | |
| RetainPtr dataValue = adoptCF(CFDataCreate(kCFAllocatorDefault, (const UInt8 *)"Data test", strlen("Data test"))); | |
| CFDictionaryAddValue(cfDictionary.get(), dataKey.get(), dataValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 3); | |
| // CFDateRef | |
| RetainPtr dateKey = adoptCF(CFSTR("dateKey")); | |
| RetainPtr dateValue = adoptCF(CFDateCreate(kCFAllocatorDefault, 1.23)); | |
| CFDictionaryAddValue(cfDictionary.get(), dateKey.get(), dateValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 4); | |
| // CFDictionaryRef | |
| RetainPtr dictKey = adoptCF(CFSTR("dictKey")); | |
| RetainPtr dictValue = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); | |
| RetainPtr key1 = adoptCF(CFSTR("key1")); | |
| RetainPtr value1 = adoptCF(CFSTR("value1")); | |
| CFDictionaryAddValue(dictValue.get(), key1.get(), value1.get()); | |
| CFDictionaryAddValue(cfDictionary.get(), dictKey.get(), dictValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 5); | |
| // CFNullRef | |
| RetainPtr nullKey = adoptCF(CFSTR("nullKey")); | |
| RetainPtr nullValue = adoptCF(kCFNull); | |
| CFDictionaryAddValue(cfDictionary.get(), nullKey.get(), nullValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 6); | |
| // CFNumberRef | |
| RetainPtr numberKey = adoptCF(CFSTR("numberKey")); | |
| int32_t num = 123; | |
| RetainPtr numberValue = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, (const void*)&num)); | |
| CFDictionaryAddValue(cfDictionary.get(), numberKey.get(), numberValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 7); | |
| // CFStringRef | |
| RetainPtr stringKey = adoptCF(CFSTR("stringKey")); | |
| RetainPtr stringValue = adoptCF(CFSTR("stringValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), stringKey.get(), stringValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 8); | |
| // CFURLRef | |
| RetainPtr urlKey = adoptCF(CFSTR("urlKey")); | |
| RetainPtr url = adoptCF(CFSTR("localhost.com")); | |
| RetainPtr urlValue = adoptCF(CFURLCreateWithString(kCFAllocatorDefault, url.get(), NULL)); | |
| CFDictionaryAddValue(cfDictionary.get(), urlKey.get(), urlValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 9); | |
| // SecCertificateRef | |
| RetainPtr secCertificateKey = adoptCF(CFSTR("secCertificateKey")); | |
| auto secCertificateValue = createCertificate(); | |
| CFDictionaryAddValue(cfDictionary.get(), secCertificateKey.get(), secCertificateValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 10); | |
| // SecTrustRef | |
| auto certificate = createCertificate(); | |
| NSArray* certArray = @[(__bridge id) certificate.get()]; | |
| RetainPtr policy = adoptCF(SecPolicyCreateBasicX509()); | |
| SecTrustRef trust; | |
| SecTrustCreateWithCertificates((__bridge CFTypeRef) certArray, policy.get(), &trust); | |
| RetainPtr secTrustKey = adoptCF(CFSTR("secTrustKey")); | |
| RetainPtr secTrustValue = adoptCF(trust); | |
| CFDictionaryAddValue(cfDictionary.get(), secTrustKey.get(), secTrustValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 11); | |
| // CGColorSpaceRef | |
| RetainPtr colorSpaceKey = adoptCF(CFSTR("colorSpaceKey")); | |
| RetainPtr colorSpaceValue = adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceSRGB)); | |
| CFDictionaryAddValue(cfDictionary.get(), colorSpaceKey.get(), colorSpaceValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 12); | |
| // CGColorRef | |
| RetainPtr colorKey = adoptCF(CFSTR("colorKey")); | |
| RetainPtr colorValue = adoptCF(CGColorCreateSRGB(1.0, 0.0, 0.0, 1.0)); | |
| CFDictionaryAddValue(cfDictionary.get(), colorKey.get(), colorValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 13); | |
| // SecAccessControlRef | |
| RetainPtr secAccessControlKey = adoptCF(CFSTR("secAccessControlKey")); | |
| SecAccessControlCreateFlags flags = (kSecAccessControlDevicePasscode | kSecAccessControlBiometryAny | kSecAccessControlOr); | |
| NSDictionary *protection = @{ | |
| (id)kSecUseDataProtectionKeychain : @(YES), | |
| (id)kSecAttrSynchronizable : @(NO), | |
| (id)kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly : @(YES), | |
| (id)kSecAttrAccessibleWhenUnlocked: @(YES) }; | |
| RetainPtr secAccessControlValue = adoptCF(SecAccessControlCreateWithFlags(kCFAllocatorDefault, (CFTypeRef)protection, flags, NULL)); | |
| CFDictionaryAddValue(cfDictionary.get(), secAccessControlKey.get(), secAccessControlValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 14); | |
| // CFSocketRef (should not be accepted by CoreIPCCFDictionary) | |
| RetainPtr socketKey = adoptCF(CFSTR("socketKey")); | |
| RetainPtr socketValue = adoptCF(CFSocketCreate(kCFAllocatorDefault, 0, 0, 0, 0, NULL, NULL)); | |
| CFDictionaryAddValue(cfDictionary.get(), socketKey.get(), socketValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 15); | |
| WebKit::CoreIPCCFDictionary coreIpcCfDict1(cfDictionary.get()); | |
| auto cfDictionary2 = coreIpcCfDict1.createCFDictionary(); | |
| EXPECT_NE(CFDictionaryGetCount(cfDictionary.get()), CFDictionaryGetCount(cfDictionary2.get())); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary2.get()), 14); | |
| runTestCFWithExpectedResult({ cfDictionary.get() }, { cfDictionary2.get() }); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), booleanKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), booleanKey.get())), CFBooleanGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), charSetKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), charSetKey.get())), CFCharacterSetGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), dataKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), dataKey.get())), CFDataGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), dateKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), dateKey.get())), CFDateGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), dictKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), dictKey.get())), CFDictionaryGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), nullKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), nullKey.get())), CFNullGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), numberKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), numberKey.get())), CFNumberGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), stringKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), stringKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), urlKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), urlKey.get())), CFURLGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), secCertificateKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), secCertificateKey.get())), SecCertificateGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), secTrustKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), secTrustKey.get())), SecTrustGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), colorSpaceKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), colorSpaceKey.get())), CGColorSpaceGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), colorKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), colorKey.get())), CGColorGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), secAccessControlKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), secAccessControlKey.get())), SecAccessControlGetTypeID()); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), socketKey.get())); | |
| } | |
| TEST(CoreIPCCFDictionary, InsertDifferentKeyTypes) | |
| { | |
| // Test that a CoreIPCCFDictionary can be created, encoded, and decoded with valid key-value pairs. | |
| // Keys will be all possible variants from CoreIPCCFDictionary::KeyType | |
| // Values will be string type (CFStringRef). | |
| RetainPtr cfDictionary = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); | |
| // CFBooleanRef | |
| RetainPtr booleanKey = adoptCF(kCFBooleanFalse); | |
| RetainPtr booleanValue = adoptCF(CFSTR("booleanValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), booleanKey.get(), booleanValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 1); | |
| // CFCharacterSetRef | |
| RetainPtr charSetKey = adoptCF(CFCharacterSetCreateWithCharactersInString(kCFAllocatorDefault, CFSTR("ABC"))); | |
| RetainPtr charSetValue = adoptCF(CFSTR("charSetValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), charSetKey.get(), charSetValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 2); | |
| // CFDataRef | |
| RetainPtr dataKey = adoptCF(CFDataCreate(kCFAllocatorDefault, (const UInt8 *)"Data test", strlen("Data test"))); | |
| RetainPtr dataValue = adoptCF(CFSTR("dataValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), dataKey.get(), dataValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 3); | |
| // CFDateRef | |
| RetainPtr dateKey = adoptCF(CFDateCreate(kCFAllocatorDefault, 1.23)); | |
| RetainPtr dateValue = adoptCF(CFSTR("dateValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), dateKey.get(), dateValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 4); | |
| // CFDictionaryRef | |
| RetainPtr dictKey = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); | |
| RetainPtr dictValue = adoptCF(CFSTR("dictValue")); | |
| RetainPtr key1 = adoptCF(CFSTR("key1")); | |
| RetainPtr value1 = adoptCF(CFSTR("value1")); | |
| CFDictionaryAddValue(dictKey.get(), key1.get(), value1.get()); | |
| CFDictionaryAddValue(cfDictionary.get(), dictKey.get(), dictValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 5); | |
| // CFNullRef | |
| RetainPtr nullKey = adoptCF(kCFNull); | |
| RetainPtr nullValue = adoptCF(CFSTR("nullValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), nullKey.get(), nullValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 6); | |
| // CFNumberRef | |
| int32_t num = 123; | |
| RetainPtr numberKey = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, (const void*)&num)); | |
| RetainPtr numberValue = adoptCF(CFSTR("numberValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), numberKey.get(), numberValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 7); | |
| // CFStringRef | |
| RetainPtr stringKey = adoptCF(CFSTR("stringKey")); | |
| RetainPtr stringValue = adoptCF(CFSTR("stringValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), stringKey.get(), stringValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 8); | |
| // CFURLRef | |
| RetainPtr url = adoptCF(CFSTR("localhost.com")); | |
| RetainPtr urlKey = adoptCF(CFURLCreateWithString(kCFAllocatorDefault, url.get(), NULL)); | |
| RetainPtr urlValue = adoptCF(CFSTR("urlValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), urlKey.get(), urlValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 9); | |
| // SecCertificateRef | |
| auto secCertificateKey = createCertificate(); | |
| RetainPtr secCertificateValue = adoptCF(CFSTR("secCertificateValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), secCertificateKey.get(), secCertificateValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 10); | |
| // SecTrustRef | |
| auto certificate = createCertificate(); | |
| NSArray* certArray = @[(__bridge id) certificate.get()]; | |
| RetainPtr policy = adoptCF(SecPolicyCreateBasicX509()); | |
| SecTrustRef trust; | |
| SecTrustCreateWithCertificates((__bridge CFTypeRef) certArray, policy.get(), &trust); | |
| RetainPtr secTrustKey = adoptCF(trust); | |
| RetainPtr secTrustValue = adoptCF(CFSTR("secTrustValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), secTrustKey.get(), secTrustValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 11); | |
| // CGColorSpaceRef | |
| RetainPtr colorSpaceKey = adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceSRGB)); | |
| RetainPtr colorSpaceValue = adoptCF(CFSTR("colorSpaceValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), colorSpaceKey.get(), colorSpaceValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 12); | |
| // CGColorRef | |
| RetainPtr colorKey = adoptCF(CGColorCreateSRGB(1.0, 0.0, 0.0, 1.0)); | |
| RetainPtr colorValue = adoptCF(CFSTR("colorValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), colorKey.get(), colorValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 13); | |
| // SecAccessControlRef | |
| SecAccessControlCreateFlags flags = (kSecAccessControlDevicePasscode | kSecAccessControlBiometryAny | kSecAccessControlOr); | |
| NSDictionary *protection = @{ | |
| (id)kSecUseDataProtectionKeychain : @(YES), | |
| (id)kSecAttrSynchronizable : @(NO), | |
| (id)kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly : @(YES), | |
| (id)kSecAttrAccessibleWhenUnlocked: @(YES) }; | |
| RetainPtr secAccessControlKey = adoptCF(SecAccessControlCreateWithFlags(kCFAllocatorDefault, (CFTypeRef)protection, flags, NULL)); | |
| RetainPtr secAccessControlValue = adoptCF(CFSTR("secAccessControlValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), secAccessControlKey.get(), secAccessControlValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 14); | |
| // CFSocketRef (should not be accepted by CoreIPCCFDictionary) | |
| RetainPtr socketKey = adoptCF(CFSocketCreate(kCFAllocatorDefault, 0, 0, 0, 0, NULL, NULL)); | |
| RetainPtr socketValue = adoptCF(CFSTR("socketValue")); | |
| CFDictionaryAddValue(cfDictionary.get(), socketKey.get(), socketValue.get()); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary.get()), 15); | |
| WebKit::CoreIPCCFDictionary coreIpcCfDict1(cfDictionary.get()); | |
| auto cfDictionary2 = coreIpcCfDict1.createCFDictionary(); | |
| EXPECT_NE(CFDictionaryGetCount(cfDictionary.get()), CFDictionaryGetCount(cfDictionary2.get())); | |
| EXPECT_EQ(CFDictionaryGetCount(cfDictionary2.get()), 9); | |
| runTestCFWithExpectedResult({ cfDictionary.get() }, { cfDictionary2.get() }); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), booleanKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), booleanKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), charSetKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), charSetKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), dataKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), dataKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), dateKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), dateKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), dictKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), dictKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), nullKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), nullKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), numberKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), numberKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), stringKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), stringKey.get())), CFStringGetTypeID()); | |
| EXPECT_TRUE(CFDictionaryContainsKey(cfDictionary2.get(), urlKey.get())); | |
| EXPECT_EQ(CFGetTypeID(CFDictionaryGetValue(cfDictionary2.get(), urlKey.get())), CFStringGetTypeID()); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), secCertificateKey.get())); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), secTrustKey.get())); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), colorSpaceKey.get())); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), colorKey.get())); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), secAccessControlKey.get())); | |
| EXPECT_FALSE(CFDictionaryContainsKey(cfDictionary2.get(), socketKey.get())); | |
| } | |
| #if USE(PASSKIT) && HAVE(WK_SECURE_CODING_PKPAYMENTMETHOD) | |
| TEST(IPCSerialization, PKPaymentMethod) | |
| { | |
| RetainPtr<CNPostalAddress> address = postalAddressForTesting(); | |
| RetainPtr<CNLabeledValue> labeledPostalAddress = adoptNS([[PAL::getCNLabeledValueClassSingleton() alloc] initWithLabel:@"Work" value:address.get()]); | |
| RetainPtr<CNLabeledValue> labeledEmailAddress = adoptNS([[PAL::getCNLabeledValueClassSingleton() alloc] initWithLabel:@"WorkSPAM" value:@"spam@webkit.org"]); | |
| RetainPtr<CNMutableContact> billingContact = adoptNS([PAL::getCNMutableContactClassSingleton() new]); | |
| billingContact.get().contactType = CNContactTypePerson; | |
| billingContact.get().namePrefix = @"Mrs"; | |
| billingContact.get().givenName = @"WebKit"; | |
| billingContact.get().middleName = @"von"; | |
| billingContact.get().familyName = @"WebKittington"; | |
| billingContact.get().nameSuffix = @"The Third"; | |
| billingContact.get().organizationName = @"WebKit"; | |
| billingContact.get().jobTitle = @"Web Kitten"; | |
| billingContact.get().note = @"The Coolest Kitten out there"; | |
| billingContact.get().postalAddresses = @[ labeledPostalAddress.get() ]; | |
| billingContact.get().emailAddresses = @[ labeledEmailAddress.get() ]; | |
| // Test with all members set via CoreIPCPKPaymentMethodData | |
| WebKit::CoreIPCPKPaymentMethodData data1; | |
| data1.type = WebKit::PKPaymentMethodType::Credit; | |
| data1.displayName = @"WebKitPay"; | |
| data1.network = @"WebKitCard"; | |
| data1.issuingRegionCode = @"GB"; | |
| data1.billingAddress = billingContact.get(); | |
| data1.installmentBindToken = @"TestBindToken123"; | |
| data1.usePeerPaymentBalance = true; | |
| data1.peerPaymentQuoteIdentifier = @"TestQuoteID456"; | |
| WebKit::CoreIPCPKPaymentMethod wrapper1(std::optional<WebKit::CoreIPCPKPaymentMethodData>(WTF::move(data1))); | |
| RetainPtr<id> reconstructed1 = wrapper1.toID(); | |
| EXPECT_TRUE([reconstructed1 isKindOfClass:PAL::getPKPaymentMethodClassSingleton()]); | |
| PKPaymentMethod *reconstructedMethod1 = (PKPaymentMethod *)reconstructed1.get(); | |
| EXPECT_TRUE([reconstructedMethod1.displayName isEqualToString:@"WebKitPay"]); | |
| EXPECT_TRUE([reconstructedMethod1.network isEqualToString:@"WebKitCard"]); | |
| EXPECT_EQ(reconstructedMethod1.type, PKPaymentMethodTypeCredit); | |
| #if HAVE(PASSKIT_ISSUING_REGION_CODE) | |
| if ([reconstructedMethod1 respondsToSelector:@selector(issuingRegionCode)]) | |
| EXPECT_TRUE([reconstructedMethod1.issuingRegionCode isEqualToString:@"GB"]); | |
| #endif | |
| runTestNS({ reconstructedMethod1 }); | |
| // Test with different types set | |
| for (auto type : { WebKit::PKPaymentMethodType::Debit, WebKit::PKPaymentMethodType::Prepaid, WebKit::PKPaymentMethodType::Store, WebKit::PKPaymentMethodType::EMoney, WebKit::PKPaymentMethodType::Unknown }) { | |
| WebKit::CoreIPCPKPaymentMethodData data; | |
| data.type = type; | |
| data.displayName = @"WebKitPay"; | |
| data.network = @"WebKitCard"; | |
| data.billingAddress = billingContact.get(); | |
| data.installmentBindToken = @"TestBindToken123"; | |
| data.usePeerPaymentBalance = true; | |
| data.peerPaymentQuoteIdentifier = @"TestQuoteID456"; | |
| WebKit::CoreIPCPKPaymentMethod wrapper(std::optional<WebKit::CoreIPCPKPaymentMethodData>(WTF::move(data))); | |
| RetainPtr<id> reconstructed = wrapper.toID(); | |
| EXPECT_TRUE([reconstructed isKindOfClass:PAL::getPKPaymentMethodClassSingleton()]); | |
| runTestNS({ (PKPaymentMethod *)reconstructed.get() }); | |
| } | |
| // Test with usePeerPaymentBalance set to false | |
| WebKit::CoreIPCPKPaymentMethodData data2; | |
| data2.type = WebKit::PKPaymentMethodType::Credit; | |
| data2.displayName = @"WebKitPay"; | |
| data2.network = @"WebKitCard"; | |
| data2.billingAddress = billingContact.get(); | |
| data2.installmentBindToken = @"TestBindToken123"; | |
| data2.usePeerPaymentBalance = false; | |
| data2.peerPaymentQuoteIdentifier = @"TestQuoteID456"; | |
| WebKit::CoreIPCPKPaymentMethod wrapper2(std::optional<WebKit::CoreIPCPKPaymentMethodData>(WTF::move(data2))); | |
| RetainPtr<id> reconstructed2 = wrapper2.toID(); | |
| EXPECT_TRUE([reconstructed2 isKindOfClass:PAL::getPKPaymentMethodClassSingleton()]); | |
| runTestNS({ (PKPaymentMethod *)reconstructed2.get() }); | |
| // Test with nil optional fields | |
| WebKit::CoreIPCPKPaymentMethodData data3; | |
| data3.type = WebKit::PKPaymentMethodType::Credit; | |
| data3.displayName = @"WebKitPay"; | |
| data3.network = @"WebKitCard"; | |
| WebKit::CoreIPCPKPaymentMethod wrapper3(std::optional<WebKit::CoreIPCPKPaymentMethodData>(WTF::move(data3))); | |
| RetainPtr<id> reconstructed3 = wrapper3.toID(); | |
| EXPECT_TRUE([reconstructed3 isKindOfClass:PAL::getPKPaymentMethodClassSingleton()]); | |
| runTestNS({ (PKPaymentMethod *)reconstructed3.get() }); | |
| // Test with nil paymentMethod | |
| WebKit::CoreIPCPKPaymentMethod wrapper4(nil); | |
| RetainPtr<id> reconstructed4 = wrapper4.toID(); | |
| EXPECT_TRUE(reconstructed4.get() == nil); | |
| // Test with empty data | |
| WebKit::CoreIPCPKPaymentMethod wrapper5(std::optional<WebKit::CoreIPCPKPaymentMethodData>(WebKit::CoreIPCPKPaymentMethodData { })); | |
| RetainPtr<id> reconstructed5 = wrapper5.toID(); | |
| EXPECT_TRUE([reconstructed5 isKindOfClass:PAL::getPKPaymentMethodClassSingleton()]); | |
| runTestNS({ (PKPaymentMethod *)reconstructed5.get() }); | |
| } | |
| #endif // USE(PASSKIT) && HAVE(WK_SECURE_CODING_PKPAYMENTMETHOD) | |