xref: /aosp_15_r20/external/cronet/net/proxy_resolution/proxy_chain_util_apple_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/proxy_resolution/proxy_chain_util_apple.h"
6 
7 #include <CFNetwork/CFProxySupport.h>
8 #include <CoreFoundation/CoreFoundation.h>
9 #include <SystemConfiguration/SystemConfiguration.h>
10 
11 #include "base/apple/scoped_cftyperef.h"
12 #include "net/base/proxy_server.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 
15 namespace net {
16 
17 // Test convert ProxyDictionary To ProxyChain with invalid inputs.
18 // https://crbug.com/1478580
TEST(ProxyChainUtilAppleTest,InvalidProxyDictionaryToProxyChain)19 TEST(ProxyChainUtilAppleTest, InvalidProxyDictionaryToProxyChain) {
20   CFStringRef host_key = CFSTR("HttpHost");
21   CFStringRef port_key = CFSTR("HttpPort");
22   CFStringRef value = CFSTR("127.1110.0.1");
23   const void* keys[] = {host_key};
24   const void* values[] = {value};
25   base::apple::ScopedCFTypeRef<CFDictionaryRef> invalid_ip_dict(
26       CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1,
27                          &kCFTypeDictionaryKeyCallBacks,
28                          &kCFTypeDictionaryValueCallBacks));
29   ProxyChain proxy_chain = ProxyDictionaryToProxyChain(
30       kCFProxyTypeHTTP, invalid_ip_dict.get(), host_key, port_key);
31   EXPECT_FALSE(proxy_chain.IsValid());
32 }
33 
34 }  // namespace net
35