From 0aa2556dfc07bded74852043a0e316d425e80dfb Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 27 Sep 2013 09:32:15 -0500 Subject: [PATCH 1/6] Use described_class, not a new constant --- spec/lib/rex/proto/http/response_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/lib/rex/proto/http/response_spec.rb b/spec/lib/rex/proto/http/response_spec.rb index e8fa73980f88..255a34820e56 100644 --- a/spec/lib/rex/proto/http/response_spec.rb +++ b/spec/lib/rex/proto/http/response_spec.rb @@ -100,15 +100,14 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' describe Rex::Proto::Http::Response do - R = Rex::Proto::Http::Response it 'get_cookies returns empty string for no Set-Cookies' do - resp = R.new() + resp = described_class.new() resp.parse(get_cookies_test_1) resp.get_cookies.should eq('') end it 'get_cookies returns 5 cookies for test 2' do - resp = R.new() + resp = described_class.new() resp.parse(get_cookies_test_2) cookies = resp.get_cookies cookies.should_not be_nil @@ -125,7 +124,7 @@ end it 'get_cookies returns 5 cookies for test 3 and parses full cookie' do - resp = R.new() + resp = described_class.new() resp.parse(get_cookies_test_3) cookies = resp.get_cookies cookies.should_not be_nil @@ -142,7 +141,7 @@ end it 'get_cookies returns 5 cookies for test 4 and parses empty value' do - resp = R.new() + resp = described_class.new() resp.parse(get_cookies_test_4) cookies = resp.get_cookies cookies.should_not be_nil @@ -159,7 +158,7 @@ end it 'parses multiple cookies in one Set-Cookie header correctly' do - resp = R.new() + resp = described_class.new() resp.parse(get_cookies_test_5) cookies = resp.get_cookies cookies.should_not be_nil From 57862125b9d993f395e48fda5f5991fd313e8e03 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 27 Sep 2013 09:53:04 -0500 Subject: [PATCH 2/6] Use shuffle and *splat operator to test arrays Also, move the local variables to inside the describe block to avoid any future scope issues. --- spec/lib/rex/proto/http/response_spec.rb | 50 ++++++++++++++---------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/spec/lib/rex/proto/http/response_spec.rb b/spec/lib/rex/proto/http/response_spec.rb index 255a34820e56..fd8e40bd3d5a 100644 --- a/spec/lib/rex/proto/http/response_spec.rb +++ b/spec/lib/rex/proto/http/response_spec.rb @@ -1,6 +1,8 @@ require 'rex/proto/http/response' -get_cookies_test_1 = ' +describe Rex::Proto::Http::Response do + + get_cookies_test_no_cookies = ' HTTP/1.1 200 OK Date: Fri, 26 Apr 2013 12:43:12 GMT Server: Apache/2.2.22 (Ubuntu) @@ -16,7 +18,7 @@ ' -get_cookies_test_2 = ' + get_cookies_test_five_cookies = ' HTTP/1.1 200 OK Date: Fri, 26 Apr 2013 08:44:54 GMT Server: Apache/2.2.22 (Ubuntu) @@ -38,7 +40,7 @@ ' -get_cookies_test_3 = ' + get_cookies_test_five_ordered_cookies = ' HTTP/1.1 200 OK Date: Fri, 26 Apr 2013 08:44:54 GMT Server: Apache/2.2.22 (Ubuntu) @@ -60,7 +62,7 @@ ' -get_cookies_test_4 =' + get_cookies_test_with_empty_cookie =' HTTP/1.1 200 OK Date: Fri, 26 Apr 2013 08:44:54 GMT Server: Apache/2.2.22 (Ubuntu) @@ -82,7 +84,7 @@ ' -get_cookies_test_5 =' + get_cookies_test_one_set_cookie_header =' HTTP/1.1 200 OK Date: Wed, 25 Sep 2013 20:29:23 GMT Server: Apache/2.2.22 (Ubuntu) @@ -99,16 +101,15 @@ ' -describe Rex::Proto::Http::Response do it 'get_cookies returns empty string for no Set-Cookies' do resp = described_class.new() - resp.parse(get_cookies_test_1) + resp.parse(get_cookies_test_no_cookies) resp.get_cookies.should eq('') end - it 'get_cookies returns 5 cookies for test 2' do + it 'get_cookies returns 5 cookies when given 5 cookies non-sequentially' do resp = described_class.new() - resp.parse(get_cookies_test_2) + resp.parse(get_cookies_test_five_cookies) cookies = resp.get_cookies cookies.should_not be_nil cookies.should_not be '' @@ -123,51 +124,58 @@ ) end - it 'get_cookies returns 5 cookies for test 3 and parses full cookie' do + it 'get_cookies returns and parses 5 cookies when given 5 ordered cookies' do resp = described_class.new() - resp.parse(get_cookies_test_3) + resp.parse(get_cookies_test_five_ordered_cookies) cookies = resp.get_cookies cookies.should_not be_nil cookies.should_not be '' cookies_array = cookies.split(';').map(&:strip) cookies_array.count.should eq(5) - cookies_array.should =~ %w( + expected_cookies = %w{ pma_lang=en pma_collation_connection=utf8_general_ci pma_mcrypt_iv=mF1NmTE64IY%3D phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954 superC00kie!=stupidcookie - ) + } + expected_cookies.shuffle! + cookies_array.should include(*expected_cookies) end - it 'get_cookies returns 5 cookies for test 4 and parses empty value' do + it 'get_cookies correctly parses an empty cookie value' do resp = described_class.new() - resp.parse(get_cookies_test_4) + resp.parse(get_cookies_test_with_empty_cookie) cookies = resp.get_cookies cookies.should_not be_nil cookies.should_not be '' cookies_array = cookies.split(';').map(&:strip) cookies_array.count.should eq(5) - cookies_array.should =~ %w( + expected_cookies = %w{ pma_lang=en pma_collation_connection=utf8_general_ci pma_mcrypt_iv=mF1NmTE64IY%3D phpMyAdmin= phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue - ) + } + expected_cookies.shuffle! + cookies_array.should include(*expected_cookies) + end - it 'parses multiple cookies in one Set-Cookie header correctly' do + it 'parses multiple cookies in one Set-Cookie header' do resp = described_class.new() - resp.parse(get_cookies_test_5) + resp.parse(get_cookies_test_one_set_cookie_header) cookies = resp.get_cookies cookies.should_not be_nil cookies.should_not be '' cookies_array = cookies.split(';').map(&:strip) cookies_array.count.should eq(2) - cookies_array.should =~ %w( + expected_cookies = %w{ wordpressuser_a97c5267613d6de70e821ff82dd1ab94=admin wordpresspass_a97c5267613d6de70e821ff82dd1ab94=c3284d0f94606de1fd2af172aba15bf3 - ) + } + expected_cookies.shuffle! + cookies_array.should include(*expected_cookies) end end From 5e95df13704ba378294ee1da51d95e490f412dc9 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 27 Sep 2013 10:02:22 -0500 Subject: [PATCH 3/6] Convert local variables to HEREDOC methods --- spec/lib/rex/proto/http/response_spec.rb | 211 ++++++++++++----------- 1 file changed, 113 insertions(+), 98 deletions(-) diff --git a/spec/lib/rex/proto/http/response_spec.rb b/spec/lib/rex/proto/http/response_spec.rb index fd8e40bd3d5a..3d5b05e68e3c 100644 --- a/spec/lib/rex/proto/http/response_spec.rb +++ b/spec/lib/rex/proto/http/response_spec.rb @@ -2,104 +2,119 @@ describe Rex::Proto::Http::Response do - get_cookies_test_no_cookies = ' -HTTP/1.1 200 OK -Date: Fri, 26 Apr 2013 12:43:12 GMT -Server: Apache/2.2.22 (Ubuntu) -X-Powered-By: PHP/5.4.6-1ubuntu1.2 -Expires: Thu, 19 Nov 1981 08:52:00 GMT -Cache-Control: private, max-age=10800, pre-check=10800 -Last-Modified: Fri, 26 Apr 2013 12:01:52 GMT -Vary: Accept-Encoding -Content-Length: 63951 -Keep-Alive: timeout=5, max=100 -Connection: Keep-Alive -Content-Type: text/html - -' - - get_cookies_test_five_cookies = ' -HTTP/1.1 200 OK -Date: Fri, 26 Apr 2013 08:44:54 GMT -Server: Apache/2.2.22 (Ubuntu) -X-Powered-By: PHP/5.4.6-1ubuntu1.2 -Set-Cookie: phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue; path=/phpmyadmin/; HttpOnly -Expires: Thu, 19 Nov 1981 08:52:00 GMT -Cache-Control: private, max-age=10800, pre-check=10800 -Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT -Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954; path=/phpmyadmin/; HttpOnly -Vary: Accept-Encoding -Content-Length: 7356 -Keep-Alive: timeout=5, max=100 -Connection: Keep-Alive -Content-Type: text/html; charset=utf-8 - -' - - get_cookies_test_five_ordered_cookies = ' -HTTP/1.1 200 OK -Date: Fri, 26 Apr 2013 08:44:54 GMT -Server: Apache/2.2.22 (Ubuntu) -X-Powered-By: PHP/5.4.6-1ubuntu1.2 -Expires: Thu, 19 Nov 1981 08:52:00 GMT -Cache-Control: private, max-age=10800, pre-check=10800 -Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT -Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954; path=/phpmyadmin/; HttpOnly -Set-Cookie: superC00kie!=stupidcookie; Path=/parp/; domain=.foo.com; HttpOnly; Expires=Wed, 13-Jan-2012 22:23:01 GMT; Secure -Vary: Accept-Encoding -Content-Length: 7356 -Keep-Alive: timeout=5, max=100 -Connection: Keep-Alive -Content-Type: text/html; charset=utf-8 - -' - - get_cookies_test_with_empty_cookie =' -HTTP/1.1 200 OK -Date: Fri, 26 Apr 2013 08:44:54 GMT -Server: Apache/2.2.22 (Ubuntu) -X-Powered-By: PHP/5.4.6-1ubuntu1.2 -Set-Cookie: phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue; path=/phpmyadmin/; HttpOnly -Expires: Thu, 19 Nov 1981 08:52:00 GMT -Cache-Control: private, max-age=10800, pre-check=10800 -Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT -Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly -Set-Cookie: phpMyAdmin=; path=/phpmyadmin/; HttpOnly -Vary: Accept-Encoding -Content-Length: 7356 -Keep-Alive: timeout=5, max=100 -Connection: Keep-Alive -Content-Type: text/html; charset=utf-8 - -' - - get_cookies_test_one_set_cookie_header =' -HTTP/1.1 200 OK -Date: Wed, 25 Sep 2013 20:29:23 GMT -Server: Apache/2.2.22 (Ubuntu) -X-Powered-By: PHP/5.4.9-4ubuntu2.2 -Expires: Wed, 11 Jan 1984 05:00:00 GMT -Last-Modified: Wed, 25 Sep 2013 20:29:23 GMT -Cache-Control: no-cache, must-revalidate, max-age=0 -Pragma: no-cache -Set-Cookie: wordpressuser_a97c5267613d6de70e821ff82dd1ab94=admin; path=/wordpress-2.0/, wordpresspass_a97c5267613d6de70e821ff82dd1ab94=c3284d0f94606de1fd2af172aba15bf3; path=/wordpress-2.0/ -Vary: Accept-Encoding -Content-Length: 0 -Content-Type: text/html; charset=UTF-8 - -' + def get_cookies_test_no_cookies + <<-HEREDOC.gsub(/^ {6}/, '') + HTTP/1.1 200 OK + Date: Fri, 26 Apr 2013 12:43:12 GMT + Server: Apache/2.2.22 (Ubuntu) + X-Powered-By: PHP/5.4.6-1ubuntu1.2 + Expires: Thu, 19 Nov 1981 08:52:00 GMT + Cache-Control: private, max-age=10800, pre-check=10800 + Last-Modified: Fri, 26 Apr 2013 12:01:52 GMT + Vary: Accept-Encoding + Content-Length: 63951 + Keep-Alive: timeout=5, max=100 + Connection: Keep-Alive + Content-Type: text/html + + ' + HEREDOC + end + + def get_cookies_test_five_cookies + <<-HEREDOC.gsub(/^ {6}/, '') + HTTP/1.1 200 OK + Date: Fri, 26 Apr 2013 08:44:54 GMT + Server: Apache/2.2.22 (Ubuntu) + X-Powered-By: PHP/5.4.6-1ubuntu1.2 + Set-Cookie: phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue; path=/phpmyadmin/; HttpOnly + Expires: Thu, 19 Nov 1981 08:52:00 GMT + Cache-Control: private, max-age=10800, pre-check=10800 + Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT + Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954; path=/phpmyadmin/; HttpOnly + Vary: Accept-Encoding + Content-Length: 7356 + Keep-Alive: timeout=5, max=100 + Connection: Keep-Alive + Content-Type: text/html; charset=utf-8 + + + HEREDOC + end + + def get_cookies_test_five_ordered_cookies + <<-HEREDOC.gsub(/^ {6}/, '') + HTTP/1.1 200 OK + Date: Fri, 26 Apr 2013 08:44:54 GMT + Server: Apache/2.2.22 (Ubuntu) + X-Powered-By: PHP/5.4.6-1ubuntu1.2 + Expires: Thu, 19 Nov 1981 08:52:00 GMT + Cache-Control: private, max-age=10800, pre-check=10800 + Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT + Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954; path=/phpmyadmin/; HttpOnly + Set-Cookie: superC00kie!=stupidcookie; Path=/parp/; domain=.foo.com; HttpOnly; Expires=Wed, 13-Jan-2012 22:23:01 GMT; Secure + Vary: Accept-Encoding + Content-Length: 7356 + Keep-Alive: timeout=5, max=100 + Connection: Keep-Alive + Content-Type: text/html; charset=utf-8 + + + HEREDOC + end + + def get_cookies_test_with_empty_cookie + <<-HEREDOC.gsub(/^ {6}/, '') + HTTP/1.1 200 OK + Date: Fri, 26 Apr 2013 08:44:54 GMT + Server: Apache/2.2.22 (Ubuntu) + X-Powered-By: PHP/5.4.6-1ubuntu1.2 + Set-Cookie: phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue; path=/phpmyadmin/; HttpOnly + Expires: Thu, 19 Nov 1981 08:52:00 GMT + Cache-Control: private, max-age=10800, pre-check=10800 + Last-Modified: Sun, 12 Aug 2012 13:38:18 GMT + Set-Cookie: pma_lang=en; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: pma_collation_connection=utf8_general_ci; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: pma_mcrypt_iv=mF1NmTE64IY%3D; expires=Sun, 26-May-2013 08:44:54 GMT; path=/phpmyadmin/; httponly + Set-Cookie: phpMyAdmin=; path=/phpmyadmin/; HttpOnly + Vary: Accept-Encoding + Content-Length: 7356 + Keep-Alive: timeout=5, max=100 + Connection: Keep-Alive + Content-Type: text/html; charset=utf-8 + + + HEREDOC + end + + def get_cookies_test_one_set_cookie_header + <<-HEREDOC.gsub(/^ {6}/, '') + HTTP/1.1 200 OK + Date: Wed, 25 Sep 2013 20:29:23 GMT + Server: Apache/2.2.22 (Ubuntu) + X-Powered-By: PHP/5.4.9-4ubuntu2.2 + Expires: Wed, 11 Jan 1984 05:00:00 GMT + Last-Modified: Wed, 25 Sep 2013 20:29:23 GMT + Cache-Control: no-cache, must-revalidate, max-age=0 + Pragma: no-cache + Set-Cookie: wordpressuser_a97c5267613d6de70e821ff82dd1ab94=admin; path=/wordpress-2.0/, wordpresspass_a97c5267613d6de70e821ff82dd1ab94=c3284d0f94606de1fd2af172aba15bf3; path=/wordpress-2.0/ + Vary: Accept-Encoding + Content-Length: 0 + Content-Type: text/html; charset=UTF-8 + + + HEREDOC +end it 'get_cookies returns empty string for no Set-Cookies' do resp = described_class.new() From 467c503fb9f894a91381491813eab1922160d7df Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 27 Sep 2013 10:07:28 -0500 Subject: [PATCH 4/6] DRY with a cookie_sanity_check method --- spec/lib/rex/proto/http/response_spec.rb | 39 +++++++++--------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/spec/lib/rex/proto/http/response_spec.rb b/spec/lib/rex/proto/http/response_spec.rb index 3d5b05e68e3c..1f2191ba0ee0 100644 --- a/spec/lib/rex/proto/http/response_spec.rb +++ b/spec/lib/rex/proto/http/response_spec.rb @@ -114,7 +114,16 @@ def get_cookies_test_one_set_cookie_header HEREDOC -end + end + + def cookie_sanity_check(meth) + resp = described_class.new() + resp.parse(self.send meth) + cookies = resp.get_cookies + cookies.should_not be_nil + cookies.should_not be '' + cookies.split(';').map(&:strip) + end it 'get_cookies returns empty string for no Set-Cookies' do resp = described_class.new() @@ -123,12 +132,7 @@ def get_cookies_test_one_set_cookie_header end it 'get_cookies returns 5 cookies when given 5 cookies non-sequentially' do - resp = described_class.new() - resp.parse(get_cookies_test_five_cookies) - cookies = resp.get_cookies - cookies.should_not be_nil - cookies.should_not be '' - cookies_array = cookies.split(';').map(&:strip) + cookies_array = cookie_sanity_check(:get_cookies_test_five_cookies) cookies_array.count.should eq(5) cookies_array.should =~ %w( pma_lang=en @@ -140,12 +144,7 @@ def get_cookies_test_one_set_cookie_header end it 'get_cookies returns and parses 5 cookies when given 5 ordered cookies' do - resp = described_class.new() - resp.parse(get_cookies_test_five_ordered_cookies) - cookies = resp.get_cookies - cookies.should_not be_nil - cookies.should_not be '' - cookies_array = cookies.split(';').map(&:strip) + cookies_array = cookie_sanity_check(:get_cookies_test_five_ordered_cookies) cookies_array.count.should eq(5) expected_cookies = %w{ pma_lang=en @@ -159,12 +158,7 @@ def get_cookies_test_one_set_cookie_header end it 'get_cookies correctly parses an empty cookie value' do - resp = described_class.new() - resp.parse(get_cookies_test_with_empty_cookie) - cookies = resp.get_cookies - cookies.should_not be_nil - cookies.should_not be '' - cookies_array = cookies.split(';').map(&:strip) + cookies_array = cookie_sanity_check(:get_cookies_test_with_empty_cookie) cookies_array.count.should eq(5) expected_cookies = %w{ pma_lang=en @@ -179,12 +173,7 @@ def get_cookies_test_one_set_cookie_header end it 'parses multiple cookies in one Set-Cookie header' do - resp = described_class.new() - resp.parse(get_cookies_test_one_set_cookie_header) - cookies = resp.get_cookies - cookies.should_not be_nil - cookies.should_not be '' - cookies_array = cookies.split(';').map(&:strip) + cookies_array = cookie_sanity_check(:get_cookies_test_one_set_cookie_header) cookies_array.count.should eq(2) expected_cookies = %w{ wordpressuser_a97c5267613d6de70e821ff82dd1ab94=admin From 623aeb367f9d364f65528d839d714db7688dcc39 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 27 Sep 2013 10:12:11 -0500 Subject: [PATCH 5/6] Set a context for #get_cookies --- spec/lib/rex/proto/http/response_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/lib/rex/proto/http/response_spec.rb b/spec/lib/rex/proto/http/response_spec.rb index 1f2191ba0ee0..ffdeabc92995 100644 --- a/spec/lib/rex/proto/http/response_spec.rb +++ b/spec/lib/rex/proto/http/response_spec.rb @@ -125,13 +125,15 @@ def cookie_sanity_check(meth) cookies.split(';').map(&:strip) end - it 'get_cookies returns empty string for no Set-Cookies' do + context "#get_cookies" do + + it 'returns empty string for no Set-Cookies' do resp = described_class.new() resp.parse(get_cookies_test_no_cookies) resp.get_cookies.should eq('') end - it 'get_cookies returns 5 cookies when given 5 cookies non-sequentially' do + it 'returns 5 cookies when given 5 cookies non-sequentially' do cookies_array = cookie_sanity_check(:get_cookies_test_five_cookies) cookies_array.count.should eq(5) cookies_array.should =~ %w( @@ -143,7 +145,7 @@ def cookie_sanity_check(meth) ) end - it 'get_cookies returns and parses 5 cookies when given 5 ordered cookies' do + it 'returns and parses 5 cookies when given 5 ordered cookies' do cookies_array = cookie_sanity_check(:get_cookies_test_five_ordered_cookies) cookies_array.count.should eq(5) expected_cookies = %w{ @@ -157,7 +159,7 @@ def cookie_sanity_check(meth) cookies_array.should include(*expected_cookies) end - it 'get_cookies correctly parses an empty cookie value' do + it 'parses an empty cookie value' do cookies_array = cookie_sanity_check(:get_cookies_test_with_empty_cookie) cookies_array.count.should eq(5) expected_cookies = %w{ @@ -183,3 +185,4 @@ def cookie_sanity_check(meth) cookies_array.should include(*expected_cookies) end end +end From 103a64a32a9854cad4ac3e0ec538d2d7424c2341 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Fri, 27 Sep 2013 10:22:46 -0500 Subject: [PATCH 6/6] Indent like a sane person. --- spec/lib/rex/proto/http/response_spec.rb | 77 ++++++++++++------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/spec/lib/rex/proto/http/response_spec.rb b/spec/lib/rex/proto/http/response_spec.rb index ffdeabc92995..dc474a087766 100644 --- a/spec/lib/rex/proto/http/response_spec.rb +++ b/spec/lib/rex/proto/http/response_spec.rb @@ -115,7 +115,7 @@ def get_cookies_test_one_set_cookie_header "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> HEREDOC end - + def cookie_sanity_check(meth) resp = described_class.new() resp.parse(self.send meth) @@ -127,62 +127,65 @@ def cookie_sanity_check(meth) context "#get_cookies" do - it 'returns empty string for no Set-Cookies' do - resp = described_class.new() - resp.parse(get_cookies_test_no_cookies) - resp.get_cookies.should eq('') - end + it 'returns empty string for no Set-Cookies' do + resp = described_class.new() + resp.parse(get_cookies_test_no_cookies) + resp.get_cookies.should eq('') + end - it 'returns 5 cookies when given 5 cookies non-sequentially' do - cookies_array = cookie_sanity_check(:get_cookies_test_five_cookies) - cookies_array.count.should eq(5) - cookies_array.should =~ %w( + it 'returns 5 cookies when given 5 cookies non-sequentially' do + cookies_array = cookie_sanity_check(:get_cookies_test_five_cookies) + cookies_array.count.should eq(5) + cookies_array.should =~ %w( pma_lang=en pma_collation_connection=utf8_general_ci pma_mcrypt_iv=mF1NmTE64IY%3D phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954 phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue - ) - end + ) + end - it 'returns and parses 5 cookies when given 5 ordered cookies' do - cookies_array = cookie_sanity_check(:get_cookies_test_five_ordered_cookies) - cookies_array.count.should eq(5) - expected_cookies = %w{ + it 'returns and parses 5 cookies when given 5 ordered cookies' do + cookies_array = cookie_sanity_check(:get_cookies_test_five_ordered_cookies) + cookies_array.count.should eq(5) + expected_cookies = %w{ pma_lang=en pma_collation_connection=utf8_general_ci pma_mcrypt_iv=mF1NmTE64IY%3D phpMyAdmin=fmilioji5cn4m8bo5vjrrr6q9cada954 superC00kie!=stupidcookie - } - expected_cookies.shuffle! - cookies_array.should include(*expected_cookies) - end - - it 'parses an empty cookie value' do - cookies_array = cookie_sanity_check(:get_cookies_test_with_empty_cookie) - cookies_array.count.should eq(5) - expected_cookies = %w{ + } + expected_cookies.shuffle! + cookies_array.should include(*expected_cookies) + end + + it 'parses an empty cookie value' do + cookies_array = cookie_sanity_check(:get_cookies_test_with_empty_cookie) + cookies_array.count.should eq(5) + expected_cookies = %w{ pma_lang=en pma_collation_connection=utf8_general_ci pma_mcrypt_iv=mF1NmTE64IY%3D phpMyAdmin= phpMyAdmin=gpjif0gtpqbvfion91ddtrq8p8vgjtue - } - expected_cookies.shuffle! - cookies_array.should include(*expected_cookies) + } + expected_cookies.shuffle! + cookies_array.should include(*expected_cookies) - end + end - it 'parses multiple cookies in one Set-Cookie header' do - cookies_array = cookie_sanity_check(:get_cookies_test_one_set_cookie_header) - cookies_array.count.should eq(2) - expected_cookies = %w{ + it 'parses multiple cookies in one Set-Cookie header' do + cookies_array = cookie_sanity_check(:get_cookies_test_one_set_cookie_header) + cookies_array.count.should eq(2) + expected_cookies = %w{ wordpressuser_a97c5267613d6de70e821ff82dd1ab94=admin wordpresspass_a97c5267613d6de70e821ff82dd1ab94=c3284d0f94606de1fd2af172aba15bf3 - } - expected_cookies.shuffle! - cookies_array.should include(*expected_cookies) + } + expected_cookies.shuffle! + cookies_array.should include(*expected_cookies) + end + end + end -end +