davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.01k stars 250 forks source link

Adding support of SameSite cookies #282

Closed IronBlood closed 3 years ago

IronBlood commented 3 years ago

Linked issue #281

IronBlood commented 3 years ago

Sorry to leave conflicts. I made this commit based on v0.8(46ed564), I thought git could handle the later changes automatically. Should I rebase to the master branch and create another PR?

IronBlood commented 3 years ago

Sorry for making troubles, I should have a second thought about picking flag numbers. I didn't know how to execute the tests back to that time, I remembered once there was a version that tests could be executed automatically after compilation.

After I rebased to the master branch and changed flags to 0x10 0x20 and 0x40, the tests looks good now (I also checked the returned value of onion_response_add_cookie) as shown below. I think it's better to close this PR and create a new one.

$ tests/01-internal/03-response                            
03-response.c:43 INFO Test t01_create_add_free
[DB7D2A00] [2021-01-08 12:53:58] [ERROR response.c:279] Bad formed response. Need a request at creation. Will not write headers.
03-response.c:57 INFO t01_create_add_free ends: 3 succeses / 0 failures

03-response.c:61 INFO Test t02_full_cycle_http10
[DB7D2A00] [2021-01-08 12:53:58] [INFO response.c:191] [(null)] "GET (null)" 200 30 (Close connection)
03-response.c:95 INFO t02_full_cycle_http10 ends: 8 succeses / 0 failures

03-response.c:99 INFO Test t03_full_cycle_http11
[DB7D2A00] [2021-01-08 12:53:58] [INFO response.c:191] [(null)] "GET /" 200 30 (Keep-Alive)
03-response.c:137 INFO t03_full_cycle_http11 ends: 8 succeses / 0 failures

03-response.c:141 INFO Test t04_cookies
03-response.c:229 ERROR FAIL IF NOT valid_expires
[DB7D2A00] [2021-01-08 12:53:58] [WARNING response.c:655] Cookie too long to be constructed. Not added to response.
[DB7D2A00] [2021-01-08 12:53:58] [ERROR response.c:279] Bad formed response. Need a request at creation. Will not write headers.
03-response.c:248 INFO t04_cookies ends: 27 succeses / 1 failures

03-response.c:252 INFO Test t05_printf
[DB7D2A00] [2021-01-08 12:53:58] [INFO response.c:191] [(null)] "GET (null)" 200 21 (Close connection)
03-response.c:275 INFO t05_printf ends: 1 succeses / 0 failures

03-response.c:279 INFO Test t06_empty
[DB7D2A00] [2021-01-08 12:53:58] [INFO response.c:191] [(null)] "GET (null)" 200 0 (Close connection)
03-response.c:306 INFO t06_empty ends: 2 succeses / 0 failures

03-response.c:310 INFO Test t07_large_printf
[DB7D2A00] [2021-01-08 12:53:58] [INFO response.c:191] [(null)] "GET (null)" 200 99999 (Close connection)
03-response.c:339 INFO t07_large_printf ends: 2 succeses / 0 failures

03-response.c:353 INFO TOTAL: 51 succeses / 1 failures

The warning and error of the t04_cookies part are caused by the test of "cookie too long" (I guess), I dumped the data after ONION_WARNING and find a lot of as shown below:

cookie dump
key5=aaaaaaaaaaaaaa....
davidmoreno commented 3 years ago

I think all this changes were also at PR #283, so I will close it now. If I'm wrong feel free to reopen the PR.