diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin_request_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 6 | ||||
-rw-r--r-- | spec/fixtures/files/track-response-exim-bounce.email | 67 | ||||
-rw-r--r-- | spec/fixtures/files/track-response-multipart-report.email | 113 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 15 | ||||
-rwxr-xr-x | spec/lib/external_command_scripts/output.sh | 22 | ||||
-rw-r--r-- | spec/lib/external_command_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/outgoing_mailer_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 23 | ||||
-rw-r--r-- | spec/script/handle-mail-replies_spec.rb | 33 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
13 files changed, 288 insertions, 71 deletions
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index 423c2fb49..6f9af0525 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -71,7 +71,7 @@ describe AdminRequestController, "when administering the holding pen" do post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title ir = InfoRequest.find_by_url_title(ir.url_title) ir.incoming_messages.length.should == 2 - response.should redirect_to('http://test.host/admin/request/show/101') + response.should redirect_to(:controller=>'admin_request', :action=>'show', :id=>101) InfoRequest.holding_pen_request.incoming_messages.length.should == 0 end diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 8c2e19c58..435d9a0d3 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -36,7 +36,7 @@ end describe TrackController, "when sending alerts for a track" do integrate_views - fixtures :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :track_things_sent_emails, :public_bodies, :public_body_translations + fixtures :comments, :info_requests, :outgoing_messages, :incoming_messages, :raw_emails, :info_request_events, :users, :track_things, :track_things_sent_emails, :public_bodies, :public_body_translations include LinkToHelper # for main_url before(:each) do diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 0ba542630..b4cc0d6e3 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -111,7 +111,7 @@ describe UserController, "when signing in" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect - post :signin, { :user_signin => { :email => 'silly@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_redirect.token } response.should render_template('confirm') @@ -123,7 +123,7 @@ describe UserController, "when signing in" do get :signin, :r => "/list" post_redirect = get_last_postredirect - post :signin, { :user_signin => { :email => 'silly@localhost', :password => 'jonespassword' }, + post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_redirect.token } response.should send_email @@ -143,7 +143,7 @@ describe UserController, "when signing in" do # check confirmation URL works session[:user_id].should be_nil get :confirm, :email_token => post_redirect.email_token - session[:user_id].should == users(:silly_name_user).id + session[:user_id].should == users(:unconfirmed_user).id response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) end diff --git a/spec/fixtures/files/track-response-exim-bounce.email b/spec/fixtures/files/track-response-exim-bounce.email new file mode 100644 index 000000000..8d40380b1 --- /dev/null +++ b/spec/fixtures/files/track-response-exim-bounce.email @@ -0,0 +1,67 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs98510wem; + Tue, 6 Sep 2011 14:22:44 -0700 (PDT) +Received: by 10.216.203.79 with SMTP id e57mr78207weo.42.1315344164092; + Tue, 06 Sep 2011 14:22:44 -0700 (PDT) +Return-Path: <> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id n64si9483505weq.102.2011.09.06.14.22.42 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 06 Sep 2011 14:22:43 -0700 (PDT) +Received-SPF: pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) smtp.mail= +Received: from Debian-exim by wildfire.ukcod.org.uk with local (Exim 4.69) + id 1R136L-0003xr-1Q + for team@whatdotheyknow.com; Tue, 06 Sep 2011 22:22:37 +0100 +X-Failed-Recipients: user@example.com +Auto-Submitted: auto-replied +From: Mail Delivery System <Mailer-Daemon@wildfire.ukcod.org.uk> +To: team@whatdotheyknow.com +Subject: Mail delivery failed: returning message to sender +Message-Id: <E1R136L-0003xr-1Q@wildfire.ukcod.org.uk> +Date: Tue, 06 Sep 2011 22:22:37 +0100 +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + +This message was created automatically by mail delivery software. + +A message that you sent could not be delivered to one or more of its +recipients. This is a permanent error. The following address(es) failed: + + user@example.com + Unrouteable address + +------ This is a copy of the message, including all the headers. ------ + +Return-path: <team@whatdotheyknow.com> +Received: from foi by wildfire.ukcod.org.uk with local (Exim 4.69) + (envelope-from <team@whatdotheyknow.com>) + id 1R136J-0003xp-Td + for user@example.com; Tue, 06 Sep 2011 22:22:36 +0100 +Date: Tue, 6 Sep 2011 22:22:35 +0100 +From: WhatDoTheyKnow <team@whatdotheyknow.com> +To: Nonexistent User <user@example.com> +Subject: Your WhatDoTheyKnow email alert +Mime-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Precedence: bulk +Auto-Submitted: auto-generated +Message-Id: <E1R136J-0003xp-Td@wildfire.ukcod.org.uk> + +FOI requests to 'Maritime and Coastguard Agency' +================================================ + +-- MCA & HM Coastguard Official Vehicles -- +Maritime and Coastguard Agency sent a response to Peter Smith (12 August 2011) + "Peter In response (reference F0000881) to your FOI questions the + MCA answer is:- 1. All MCA vehicles are purchased outright. 2. Yes + there is a volu..." +http://www.whatdotheyknow.com/request/mca_hm_coastguard_official_vehic#incoming-201529 + + +Alter your subscription +======================= + +Please click on the link below to cancel or alter these emails. +http://www.whatdotheyknow.com/c/ie4pkpy70dl4b8flsig + +-- the WhatDoTheyKnow team diff --git a/spec/fixtures/files/track-response-multipart-report.email b/spec/fixtures/files/track-response-multipart-report.email new file mode 100644 index 000000000..4f8e6d86b --- /dev/null +++ b/spec/fixtures/files/track-response-multipart-report.email @@ -0,0 +1,113 @@ +Delivered-To: mysociety.robin@gmail.com +Received: by 10.216.187.197 with SMTP id y47cs96752wem; + Tue, 6 Sep 2011 13:37:26 -0700 (PDT) +Received: by 10.216.212.37 with SMTP id x37mr3361871weo.35.1315341445852; + Tue, 06 Sep 2011 13:37:25 -0700 (PDT) +Return-Path: <> +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by mx.google.com with ESMTPS id h49si1800318wed.40.2011.09.06.13.37.25 + (version=TLSv1/SSLv3 cipher=OTHER); + Tue, 06 Sep 2011 13:37:25 -0700 (PDT) +Received-SPF: pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) client-ip=89.238.145.74; +Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of wildfire.ukcod.org.uk designates 89.238.145.74 as permitted sender) smtp.mail= +Received: from cluster-a.mailcontrol.com ([85.115.52.190]:43258) + by wildfire.ukcod.org.uk with esmtp (Exim 4.69) + id 1R12OV-0003KQ-9c + for team@whatdotheyknow.com; Tue, 06 Sep 2011 21:37:19 +0100 +Received: from mail.example.com ([62.6.240.178]) + by rly22a.srv.mailcontrol.com (MailControl) with ESMTP id p86KbIZV025877 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) + for <team@whatdotheyknow.com>; Tue, 6 Sep 2011 21:37:18 +0100 +Received: from MX05.example.com (10.100.14.57) by GCEX534.PHSGROUP.local + (10.100.21.78) with Microsoft SMTP Server id 14.1.270.1; Tue, 6 Sep 2011 + 21:38:52 +0100 +From: <postmaster@xyz.local> +To: <team@whatdotheyknow.com> +Date: Tue, 6 Sep 2011 21:37:13 +0100 +MIME-Version: 1.0 +Content-Type: multipart/report; report-type=delivery-status; + boundary="9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com" +X-DSNContext: 7ce717b1 - 1148 - 00000002 - 00000000 +Message-ID: <DEU8FnRwh00000d1b@MX05.example.com> +Subject: Delivery Status Notification (Failure) +X-Scanned-By: MailControl A-12-01-02 (www.mailcontrol.com) on 10.65.0.132 +List-Id: Admin Team for What Do They Know <team@whatdotheyknow.com> + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com +Content-Type: text/plain; charset="unicode-1-1-utf-7" + +This is an automatically generated Delivery Status Notification. + +Delivery to the following recipients failed. + + FailedUser@example.com + + + + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com +Content-Type: message/delivery-status + +Reporting-MTA: dns;MX05.example.com +Received-From-MTA: dns;MX04.example.com +Arrival-Date: Tue, 6 Sep 2011 21:37:13 +0100 + +Final-Recipient: rfc822;FailedUser@example.com +Action: failed +Status: 5.2.2 +X-Display-Name: Failed User + + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com +Content-Type: message/rfc822 + +Received: from MX04.example.com ([10.100.14.56]) by MX05.example.com with + Microsoft SMTPSVC(5.0.2195.6713); Tue, 6 Sep 2011 21:37:13 +0100 +Received: from DCEX553.example.com ([10.211.10.27]) by MX04.example.com with + Microsoft SMTPSVC(5.0.2195.6713); Tue, 6 Sep 2011 21:37:13 +0100 +Received: from cluster-a.mailcontrol.com (85.115.52.190) by mail.example.com + (10.211.10.27) with Microsoft SMTP Server id 14.1.270.1; Tue, 6 Sep 2011 + 20:36:49 +0100 +Received: from wildfire.ukcod.org.uk (wildfire.ukcod.org.uk [89.238.145.74]) + by rly01a.srv.mailcontrol.com (MailControl) with ESMTP id p86KbAZN016792 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for + <faileduser@example.com>; Tue, 6 Sep 2011 21:37:11 +0100 +Received: from foi by wildfire.ukcod.org.uk with local (Exim 4.69) + (envelope-from <team@whatdotheyknow.com>) id 1R12OL-0003K9-UE for + faileduser@example.com; Tue, 06 Sep 2011 21:37:10 +0100 +Date: Tue, 6 Sep 2011 21:37:09 +0100 +From: WhatDoTheyKnow <team@whatdotheyknow.com> +To: Failed <faileduser@example.com> +Subject: Your WhatDoTheyKnow email alert +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Precedence: bulk +Auto-Submitted: auto-generated +Message-ID: <E1R12OL-0003K9-UE@wildfire.ukcod.org.uk> +X-Mailcontrol-Inbound: 7DN0MnCsYCrl5jj2!rZ4BuxxWQ2q0l7t3Lrex4V7ScCE2eoC2RNzHw== +X-Spam-Score: -0.857 +X-Scanned-By: MailControl A-12-01-02 (www.mailcontrol.com) on 10.65.0.111 +Return-Path: team@whatdotheyknow.com +X-OriginalArrivalTime: 06 Sep 2011 20:37:13.0070 (UTC) FILETIME=[C20250E0:01CC6CD4] + +Requests or responses matching 'bottled water cooler' +===================================================== + +-- HS2 meetings - Agendas and Minutes -- +Warwickshire County Council sent a response to Richard Jones (21 July 2011) + "Dear Mr Jones FREEDOM OF INFORMATION ACT 2000 - INFORMATION + REQUEST Your request for information has now been considered. The + information you have..." +http://www.whatdotheyknow.com/request/hs2_meetings_agendas_and_minutes_2#incoming-195748 + + +Alter your subscription +======================= + +Please click on the link below to cancel or alter these emails. +http://www.whatdotheyknow.com/c/f76ffwifzlo5sk4egr3 + +-- the WhatDoTheyKnow team + + +--9B095B5ADSN=_01CC68D9CD29F1E300015B60MX05.example.com--
\ No newline at end of file diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml index c54ac0985..16ffec034 100644 --- a/spec/fixtures/users.yml +++ b/spec/fixtures/users.yml @@ -21,7 +21,7 @@ silly_name_user: hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword updated_at: 2007-11-01 10:39:15.491593 created_at: 2007-11-01 10:39:15.491593 - email_confirmed: false + email_confirmed: true admin_level: 'none' ban_text: '' locale: 'en' @@ -40,3 +40,16 @@ admin_user: ban_text: '' locale: '' about_me: '' +unconfirmed_user: + id: "4" + name: "Unconfirmed" + url_name: unconfirmed + email: unconfirmed@localhost + salt: "-6116981980.392287733335677" + hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword + updated_at: 2007-11-01 10:39:15.491593 + created_at: 2007-11-01 10:39:15.491593 + email_confirmed: false + admin_level: 'none' + ban_text: '' + about_me: '' diff --git a/spec/lib/external_command_scripts/output.sh b/spec/lib/external_command_scripts/output.sh deleted file mode 100755 index 0472c89a3..000000000 --- a/spec/lib/external_command_scripts/output.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -out_msg=${1:-out} -err_msg=${2:-} -repeats=${3:-10} -exit_status=${4:-0} - -n=0 -while [ "$n" -lt "$repeats" ] -do - if [ -n "$out_msg" ] - then - echo "$out_msg $n" - fi - if [ -n "$err_msg" ] - then - echo >&2 "$err_msg $n" - fi - n=$[$n + 1] -done - -exit "$exit_status" diff --git a/spec/lib/external_command_spec.rb b/spec/lib/external_command_spec.rb deleted file mode 100644 index 0ff1a9c0a..000000000 --- a/spec/lib/external_command_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# This is a test of the external_command library - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -script_dir = File.join(File.dirname(__FILE__), 'external_command_scripts') -output_script = File.join(script_dir, "output.sh") - -require 'external_command' - -describe "when running ExternalCommand" do - - it "should get correct status code for /bin/true" do - t = ExternalCommand.new("/bin/true").run() - t.status.should == 0 - t.out.should == "" - t.err.should == "" - end - - it "should get correct status code for /bin/false" do - f = ExternalCommand.new("/bin/false").run() - f.status.should == 1 - f.out.should == "" - f.err.should == "" - end - - it "should get stdout and stderr" do - f = ExternalCommand.new(output_script, "out", "err", "10", "23").run() - f.status.should == 23 - f.out.should == (0..9).map {|i| "out #{i}\n"}.join("") - f.err.should == (0..9).map {|i| "err #{i}\n"}.join("") - end - - it "should work with large amounts of data" do - f = ExternalCommand.new(output_script, "a longer output line", "a longer error line", "10000", "5").run() - f.status.should == 5 - f.out.should == (0..9999).map {|i| "a longer output line #{i}\n"}.join("") - f.err.should == (0..9999).map {|i| "a longer error line #{i}\n"}.join("") - end - -end - diff --git a/spec/models/outgoing_mailer_spec.rb b/spec/models/outgoing_mailer_spec.rb index d7587cb41..c96a3fb74 100644 --- a/spec/models/outgoing_mailer_spec.rb +++ b/spec/models/outgoing_mailer_spec.rb @@ -112,7 +112,6 @@ describe OutgoingMailer, "when working out follow up subjects" do it "should not add Re: prefix if there already is a lower case re: prefix" do ir = info_requests(:fancy_dog_request) im = ir.incoming_messages[0] - puts im.raw_email.data om = outgoing_messages(:useless_outgoing_message) om.incoming_message_followup = im diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index b90ca7e52..6612641c1 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -22,7 +22,8 @@ describe TrackMailer do :last_daily_track_email= => true, :save! => true, :url_name => 'test-name', - :get_locale => 'en') + :get_locale => 'en', + :should_be_emailed? => true) User.stub!(:find).and_return([@user]) @user.stub!(:no_xapian_reindex=) end @@ -110,6 +111,36 @@ describe TrackMailer do end + describe 'when a user should not be emailed' do + before do + @user = mock_model(User, :no_xapian_reindex= => false, + :last_daily_track_email= => true, + :save! => true, + :url_name => 'test-name', + :should_be_emailed? => false) + User.stub!(:find).and_return([@user]) + @user.stub!(:no_xapian_reindex=) + end + + it 'should not ask for any daily track things for the user' do + expected_conditions = [ "tracking_user_id = ? and track_medium = ?", @user.id, 'email_daily' ] + TrackThing.should_not_receive(:find).with(:all, :conditions => expected_conditions).and_return([]) + TrackMailer.alert_tracks + end + + + it 'should not set the no_xapian_reindex flag on the user' do + @user.should_not_receive(:no_xapian_reindex=).with(true) + TrackMailer.alert_tracks + end + + it 'should not update the time of the user\'s last daily tracking email' do + @user.should_not_receive(:last_daily_track_email=).with(Time.now) + @user.should_not_receive(:save!) + TrackMailer.alert_tracks + end + end + end describe 'delivering the email' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ee6916ffc..751a61060 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -282,3 +282,26 @@ describe User, "when setting a profile photo" do # end end +describe User, "when unconfirmed" do + fixtures :users + + before do + @user = users(:unconfirmed_user) + end + + it "should not be emailed" do + @user.should_be_emailed?.should be_false + end +end + +describe User, "when emails have bounced" do + fixtures :users + + it "should record bounces" do + User.record_bounce_for_email("bob@localhost", "The reason we think the email bounced (e.g. a bounce message)") + + user = User.find_user_by_email("bob@localhost") + user.email_bounced_at.should_not be_nil + user.email_bounce_message.should == "The reason we think the email bounced (e.g. a bounce message)" + end +end diff --git a/spec/script/handle-mail-replies_spec.rb b/spec/script/handle-mail-replies_spec.rb new file mode 100644 index 000000000..856476c3f --- /dev/null +++ b/spec/script/handle-mail-replies_spec.rb @@ -0,0 +1,33 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require "external_command" + +def mail_reply_test(email_filename) + Dir.chdir RAILS_ROOT do + xc = ExternalCommand.new("script/handle-mail-replies", "--test") + xc.run(load_file_fixture(email_filename)) + + xc.err.should == "" + return xc + end +end + +describe "When filtering" do + it "should detect an Exim bounce" do + r = mail_reply_test("track-response-exim-bounce.email") + r.status.should == 1 + r.out.should == "user@example.com\n" + end + + it "should pass on a non-bounce message" do + r = mail_reply_test("incoming-request-bad-uuencoding.email") + r.status.should == 0 + r.out.should == "" + end + + it "should detect a multipart bounce" do + r = mail_reply_test("track-response-multipart-report.email") + r.status.should == 1 + r.out.should == "FailedUser@example.com\n" + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 42c5ff6bf..2ddf839da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -148,7 +148,7 @@ if $tempfilecount.nil? end def load_raw_emails_data(raw_emails) - raw_email = raw_emails(:useless_raw_email) + raw_email = raw_emails(:useless_raw_email) begin raw_email.destroy_file_representation! rescue Errno::ENOENT |