@@ -55,7 +55,91 @@ TEST test_libfetch_base64_encoder(void) {
5555 PASS ();
5656}
5757
58+ /* === FILE.C TESTS === */
59+ TEST test_file_c_get (void ) {
60+ struct url * u = fetchParseURL ("file://" GREATEST_FILE );
61+ struct url_stat st ;
62+ FILE * f ;
63+ ASSERT (u );
64+ f = fetchXGetFile (u , & st , "" );
65+ ASSERT (f );
66+ ASSERT (st .size > 0 );
67+ fclose (f );
68+ fetchFreeURL (u );
69+ PASS ();
70+ }
71+
72+ TEST test_file_c_put (void ) {
73+ char test_path [PATH_MAX ];
74+ struct url * u ;
75+ FILE * f ;
76+ snprintf (test_path , sizeof (test_path ), "%s%sput_test.txt" , DOWNLOAD_DIR ,
77+ PATH_SEP );
78+
79+ u = fetchMakeURL ("file" , NULL , 0 , test_path , NULL , NULL );
80+ ASSERT (u );
81+ f = fetchPutFile (u , "" );
82+ ASSERT (f );
83+ fprintf (f , "hello" );
84+ fclose (f );
85+ ASSERT (is_file (test_path ));
86+ remove (test_path );
87+ fetchFreeURL (u );
88+ PASS ();
89+ }
90+
91+ SUITE (libfetch_file_suite ) {
92+ RUN_TEST (test_file_c_get );
93+ RUN_TEST (test_file_c_put );
94+ }
95+
96+ /* === COMMON.C TESTS === */
97+ #if !defined(_WIN32 )
98+ TEST test_common_no_proxy_match (void ) {
99+ setenv ("no_proxy" , "*.example.com, .google.com, other.org" , 1 );
100+ ASSERT (fetch_no_proxy_match ("host.example.com" ));
101+ ASSERT (fetch_no_proxy_match ("sub.host.example.com" ));
102+ ASSERT_FALSE (fetch_no_proxy_match ("host.example.org" ));
103+ ASSERT (fetch_no_proxy_match ("www.google.com" ));
104+ ASSERT_FALSE (fetch_no_proxy_match ("google.com.bad" ));
105+ ASSERT (fetch_no_proxy_match ("other.org" ));
106+
107+ setenv ("no_proxy" , "*" , 1 );
108+ ASSERT (fetch_no_proxy_match ("anything.com" ));
109+
110+ unsetenv ("no_proxy" );
111+ PASS ();
112+ }
113+
114+ TEST test_common_netrc_auth (void ) {
115+ char netrc_path [PATH_MAX ];
116+ FILE * f ;
117+ struct url * u ;
118+
119+ snprintf (netrc_path , sizeof (netrc_path ), "%s%s_test.netrc" , DOWNLOAD_DIR ,
120+ PATH_SEP );
121+ f = fopen (netrc_path , "w" );
122+ ASSERT (f );
123+ fprintf (f , "machine test-host.com login myuser password mypass\n" );
124+ fclose (f );
125+ setenv ("NETRC" , netrc_path , 1 );
126+ u = fetchParseURL ("ftp://test-host.com/file" );
127+ ASSERT (u );
128+ ASSERT_EQ (0 , fetch_netrc_auth (u ));
129+ ASSERT_STR_EQ ("myuser" , u -> user );
130+ ASSERT_STR_EQ ("mypass" , u -> pwd );
131+ fetchFreeURL (u );
132+ unsetenv ("NETRC" );
133+ remove (netrc_path );
134+ PASS ();
135+ }
136+ #endif
137+
58138SUITE (libfetch_suite ) {
139+ #if !defined(_WIN32 )
140+ RUN_TEST (test_common_no_proxy_match );
141+ RUN_TEST (test_common_netrc_auth );
142+ #endif
59143 RUN_TEST (test_libfetch_url_parser );
60144 RUN_TEST (test_libfetch_base64_encoder );
61145}
0 commit comments