@@ -4,6 +4,10 @@ use lib 'inc';
44use lib ' lib' ;
55use Test ::Nginx::Socket ' no_plan' ;
66
7+ our $ main_conf = <<'_EOC_';
8+ thread_pool my_thread_pool threads=8 max_queue=8;
9+ _EOC_
10+
711no_long_string();
812
913run_tests();
@@ -77,6 +81,7 @@ qr/QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc
7781--- config
7882ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
7983location = /testCFUNCERRORRESP {
84+ error_log /dev/null;
8085 ngx_http_c_func_call "my_app_simple_get_no_resp";
8186}
8287--- request
@@ -119,22 +124,64 @@ qr/greeting=enjoy-http-c-function-testing$/
119124
120125=== TEST 8: Set C_FUNC_TEST_CACHE
121126--- config
122- ngx_http_c_func_link_lib " NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH /libcfuntest.so" ;
127+ ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t /libcfuntest.so";
123128location = /testCFunGetCache {
124129 ngx_http_c_func_call "my_app_simple_get_cache";
125130}
131+ location = /testCFunSetCache {
132+ ngx_http_c_func_call "my_app_simple_set_cache";
133+ }
134+ --- pipelined_requests eval
135+ ["POST /testCFunSetCache", "GET /testCFunGetCache"]
136+ --- response_body eval
137+ ["OK", "This is cache value"]
138+
139+
140+ === TEST 9: Test output headers
141+ --- config
142+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
143+ location = /ext_header_foo {
144+ ngx_http_c_func_call "my_simple_extra_foo_header_output";
145+ }
126146--- request
127- POST /testCFunGetCache
147+ GET /ext_header_foo
128148--- error_code: 200
129149--- response_headers
130- Content-Type: text/ plain
150+ foo: foovalue
151+
152+
153+
154+ === TEST 10: Authentication
155+ --- config
156+ ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
157+ location /backend {
158+ return 200 "Welcome ${arg_userName}";
159+ }
160+ location = /auth {
161+ internal;
162+ ngx_http_c_func_call "my_simple_authentication";
163+ }
164+ location = /my_simple_authentication {
165+ auth_request /auth;
166+ proxy_pass http://127.0.0.1:${server_port}/backend?userName=$http_userName;
167+ }
168+ --- request
169+ GET /my_simple_authentication
170+ --- more_headers
171+ userId:foo
172+ userPass:asdasds
173+ --- error_code: 200
131174--- response_body_like eval
132- qr/ This is cache value $/
175+ qr/Welcome foo$/
176+
177+
178+ # Test Suite below is aio threads
133179
134180
135- === TEST 9 : Set C_FUNC_AIO_THREADS_TEST
181+ === TEST 11: Set C_FUNC_TEST_1
182+ --- main_config eval: $::main_conf
136183--- config
137- aio threads;
184+ aio threads=my_thread_pool ;
138185ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
139186location = /testCFunGreeting {
140187 ngx_http_c_func_call "my_app_simple_get_greeting";
@@ -148,9 +195,130 @@ Content-Type: text/plain
148195qr/greeting from ngx_http_c_func testing$/
149196
150197
151- === TEST 10 : Test output headers
198+ === TEST 12: Set C_FUNC_TEST_ARGS
199+ --- main_config eval: $::main_conf
152200--- config
153- aio threads;
201+ aio threads=my_thread_pool;
202+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
203+ location = /testCFunARGS {
204+ ngx_http_c_func_call "my_app_simple_get_args";
205+ }
206+ --- request
207+ GET /testCFunARGS?greeting=hello_nginx?id=129310923
208+ --- error_code: 200
209+ --- response_headers
210+ Content-Type: text/plain
211+ --- response_body_like eval
212+ qr/greeting=hello_nginx\?id=129310923$/
213+
214+
215+ === TEST 13: Set C_FUNC_TEST_POST_NONE
216+ --- main_config eval: $::main_conf
217+ --- config
218+ aio threads=my_thread_pool;
219+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
220+ location = /testCFunPOSTBody {
221+ ngx_http_c_func_call "my_app_simple_post";
222+ }
223+ --- request
224+ POST /testCFunPOSTBody
225+ " "
226+ --- error_code: 202
227+ --- response_headers
228+ Content-Type: text/plain
229+ --- response_body_like eval
230+ qr/\s/
231+
232+
233+ === TEST 14: Set C_FUNC_TEST_GET_TOKEN
234+ --- main_config eval: $::main_conf
235+ --- config
236+ aio threads=my_thread_pool;
237+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
238+ location = /testCFunCVerifyToken {
239+ ngx_http_c_func_call "my_app_simple_get_token_args";
240+ }
241+ --- request
242+ GET /testCFunCVerifyToken?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==
243+ --- error_code: 401
244+ --- response_headers
245+ Content-Type: text/plain
246+ --- response_body_like eval
247+ qr/QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==$/
248+
249+
250+ === TEST 15: Set C_FUNC_TEST_GET_ERROR_RESP
251+ --- main_config eval: $::main_conf
252+ --- config
253+ aio threads=my_thread_pool;
254+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
255+ location = /testCFUNCERRORRESP {
256+ error_log /dev/null;
257+ ngx_http_c_func_call "my_app_simple_get_no_resp";
258+ }
259+ --- request
260+ GET /testCFUNCERRORRESP?token=QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc2Rhcw==
261+ --- error_code: 500
262+ --- response_headers
263+ Content-Type: text/html
264+
265+
266+ === TEST 16: Set C_FUNC_TEST_GET_CALLOC_FROM_POOL
267+ --- main_config eval: $::main_conf
268+ --- config
269+ aio threads=my_thread_pool;
270+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
271+ location = /testCFUNCCallocFromPool {
272+ ngx_http_c_func_call "my_app_simple_get_calloc_from_pool";
273+ }
274+ --- request
275+ GET /testCFUNCCallocFromPool
276+ --- error_code: 200
277+ --- response_headers
278+ Content-Type: text/plain
279+ --- response_body_like eval
280+ qr/This is the message calloc from pool$/
281+
282+
283+ === TEST 17: Set C_FUNC_TEST_POST_BODY
284+ --- main_config eval: $::main_conf
285+ --- config
286+ aio threads=my_thread_pool;
287+ ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
288+ location = /testCFunPOSTBody {
289+ ngx_http_c_func_call "my_app_simple_post";
290+ }
291+ --- request
292+ POST /testCFunPOSTBody
293+ greeting=enjoy-http-c-function-testing
294+ --- error_code: 202
295+ --- response_headers
296+ Content-Type: text/plain
297+ --- response_body_like eval
298+ qr/greeting=enjoy-http-c-function-testing$/
299+
300+
301+ === TEST 18: Set C_FUNC_TEST_CACHE
302+ --- main_config eval: $::main_conf
303+ --- config
304+ aio threads=my_thread_pool;
305+ ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
306+ location = /testCFunGetCache {
307+ ngx_http_c_func_call "my_app_simple_get_cache";
308+ }
309+ location = /testCFunSetCache {
310+ ngx_http_c_func_call "my_app_simple_set_cache";
311+ }
312+ --- pipelined_requests eval
313+ ["POST /testCFunSetCache", "GET /testCFunGetCache"]
314+ --- response_body eval
315+ ["OK", "This is cache value"]
316+
317+
318+ === TEST 19: output headers
319+ --- main_config eval: $::main_conf
320+ --- config
321+ aio threads=my_thread_pool;
154322ngx_http_c_func_link_lib "NGINX_HTTP_C_FUNCTION_TEST_LIB_PATH/libcfuntest.so";
155323location = /ext_header_foo {
156324 ngx_http_c_func_call "my_simple_extra_foo_header_output";
@@ -161,3 +329,30 @@ GET /ext_header_foo
161329--- response_headers
162330foo: foovalue
163331
332+
333+
334+ === TEST 20: Authentication
335+ --- main_config eval: $::main_conf
336+ --- config
337+ aio threads=my_thread_pool;
338+ ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
339+ location /backend {
340+ return 200 "Welcome ${arg_userName}";
341+ }
342+ location = /auth {
343+ internal;
344+ ngx_http_c_func_call "my_simple_authentication";
345+ }
346+ location = /my_simple_authentication {
347+ auth_request /auth;
348+ proxy_pass http://127.0.0.1:${server_port}/backend?userName=$http_userName;
349+ }
350+ --- request
351+ GET /my_simple_authentication
352+ --- more_headers
353+ userId:foo
354+ userPass:asdasds
355+ --- error_code: 200
356+ --- response_body_like eval
357+ qr/Welcome foo$/
358+
0 commit comments