|
| 1 | +require 'rex/proto/http/response' |
| 2 | + |
| 3 | +get_cookies_test_1 = ' |
| 4 | +HTTP/1.1 200 OK |
| 5 | +Date: Fri, 26 Apr 2013 12:43:12 GMT |
| 6 | +Server: Apache/2.2.22 (Ubuntu) |
| 7 | +X-Powered-By: PHP/5.4.6-1ubuntu1.2 |
| 8 | +Expires: Thu, 19 Nov 1981 08:52:00 GMT |
| 9 | +Cache-Control: private, max-age=10800, pre-check=10800 |
| 10 | +Last-Modified: Fri, 26 Apr 2013 12:01:52 GMT |
| 11 | +Vary: Accept-Encoding |
| 12 | +Content-Length: 63951 |
| 13 | +Keep-Alive: timeout=5, max=100 |
| 14 | +Connection: Keep-Alive |
| 15 | +Content-Type: text/html |
| 16 | +
|
| 17 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">' |
| 18 | + |
| 19 | +get_cookies_test_2 = ' |
| 20 | +HTTP/1.1 200 OK |
| 21 | +Date: Fri, 26 Apr 2013 08:44:54 GMT |
| 22 | +Server: Apache/2.2.22 (Ubuntu) |
| 23 | +X-Powered-By: PHP/5.4.6-1ubuntu1.2 |
| 24 | +Set-Cookie: phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue; path=/phpmyadmin/; HttpOnly |
| 25 | +Expires: Thu, 19 Nov 1981 08:52:00 GMT |
| 26 | +Cache-Control: private, max-age=10800, pre-check=10800 |
| 27 | +Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT |
| 28 | +Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 29 | +Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 30 | +Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 31 | +Set-Cookie: phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954; path=/phpmyadmin/; HttpOnly |
| 32 | +Vary: Accept-Encoding |
| 33 | +Content-Length: 7356 |
| 34 | +Keep-Alive: timeout=5, max=100 |
| 35 | +Connection: Keep-Alive |
| 36 | +Content-Type: text/html; charset=utf-8 |
| 37 | +
|
| 38 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 39 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' |
| 40 | + |
| 41 | +get_cookies_test_3 = ' |
| 42 | +HTTP/1.1 200 OK |
| 43 | +Date: Fri, 26 Apr 2013 08:44:54 GMT |
| 44 | +Server: Apache/2.2.22 (Ubuntu) |
| 45 | +X-Powered-By: PHP/5.4.6-1ubuntu1.2 |
| 46 | +Expires: Thu, 19 Nov 1981 08:52:00 GMT |
| 47 | +Cache-Control: private, max-age=10800, pre-check=10800 |
| 48 | +Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT |
| 49 | +Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 50 | +Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 51 | +Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 52 | +Set-Cookie: phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954; path=/phpmyadmin/; HttpOnly |
| 53 | +Set-Cookie: superC00kie!=stupidcookie; Path=/parp/; domain=.foo.com; HttpOnly; Expires=Wed, 13-Jan-2012 22:23:01 GMT; Secure |
| 54 | +Vary: Accept-Encoding |
| 55 | +Content-Length: 7356 |
| 56 | +Keep-Alive: timeout=5, max=100 |
| 57 | +Connection: Keep-Alive |
| 58 | +Content-Type: text/html; charset=utf-8 |
| 59 | +
|
| 60 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 61 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' |
| 62 | + |
| 63 | +get_cookies_test_4 =' |
| 64 | +HTTP/1.1 200 OK |
| 65 | +Date: Fri, 26 Apr 2013 08:44:54 GMT |
| 66 | +Server: Apache/2.2.22 (Ubuntu) |
| 67 | +X-Powered-By: PHP/5.4.6-1ubuntu1.2 |
| 68 | +Set-Cookie: phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue; path=/phpmyadmin/; HttpOnly |
| 69 | +Expires: Thu, 19 Nov 1981 08:52:00 GMT |
| 70 | +Cache-Control: private, max-age=10800, pre-check=10800 |
| 71 | +Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT |
| 72 | +Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 73 | +Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 74 | +Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly |
| 75 | +Set-Cookie: phpMyAdmin=; path=/phpmyadmin/; HttpOnly |
| 76 | +Vary: Accept-Encoding |
| 77 | +Content-Length: 7356 |
| 78 | +Keep-Alive: timeout=5, max=100 |
| 79 | +Connection: Keep-Alive |
| 80 | +Content-Type: text/html; charset=utf-8 |
| 81 | +
|
| 82 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 83 | +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' |
| 84 | + |
| 85 | +describe Rex::Proto::Http::Response do |
| 86 | + R = Rex::Proto::Http::Response |
| 87 | + it "get_cookies returns empty string for no Set-Cookies" do |
| 88 | + resp = R.new() |
| 89 | + resp.parse(get_cookies_test_1) |
| 90 | + resp.get_cookies.should eq("") |
| 91 | + end |
| 92 | + |
| 93 | + it "get_cookies returns 5 cookies for test 2" do |
| 94 | + resp = R.new() |
| 95 | + resp.parse(get_cookies_test_2) |
| 96 | + resp.get_cookies.split(';').count.should eq(5) |
| 97 | + end |
| 98 | + |
| 99 | + it "get_cookies returns 5 cookies for test 3 and parses full cookie" do |
| 100 | + resp = R.new() |
| 101 | + resp.parse(get_cookies_test_3) |
| 102 | + resp.get_cookies.split(';').count.should eq(5) |
| 103 | + resp.get_cookies.include?("superC00kie!=stupidcookie;").should be_true |
| 104 | + end |
| 105 | + |
| 106 | + it "get_cookies returns 5 cookies for test 4 and parses empty value" do |
| 107 | + resp = R.new() |
| 108 | + resp.parse(get_cookies_test_4) |
| 109 | + resp.get_cookies.split(';').count.should eq(5) |
| 110 | + resp.get_cookies.include?("phpMyAdmin=;").should be_true |
| 111 | + end |
| 112 | +end |
0 commit comments