mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-23 02:30:12 +01:00
adding test for cloudmailin and fixing some bugs found with it
This commit is contained in:
parent
c0956a7e76
commit
17bb939e9e
2 changed files with 34 additions and 25 deletions
|
|
@ -2,7 +2,6 @@ class IntegrationsController < ApplicationController
|
|||
require 'mail'
|
||||
|
||||
skip_before_filter :login_required, :only => [:cloudmailin, :search_plugin, :google_gadget]
|
||||
before_filter :verify_cloudmailin_signature, :only => [:cloudmailin]
|
||||
|
||||
def index
|
||||
@page_title = 'TRACKS::Integrations'
|
||||
|
|
@ -39,22 +38,31 @@ class IntegrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def cloudmailin
|
||||
# verify cloudmailin signature
|
||||
provided = request.request_parameters.delete(:signature)
|
||||
signature = Digest::MD5.hexdigest(request.request_parameters.sort{|a,b| a[0].to_s <=> b[0].to_s}.map{|k,v| v}.join + SITE_CONFIG['cloudmailin'])
|
||||
|
||||
# if signature does not match, return 403
|
||||
if provided != signature
|
||||
render :text => "Message signature fail #{provided} != #{signature}", :status => 403
|
||||
return false
|
||||
end
|
||||
|
||||
# parse message
|
||||
message = Mail.new(params[:message])
|
||||
|
||||
# debug
|
||||
#puts message.from.addresses.first
|
||||
|
||||
|
||||
# find user
|
||||
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", message.from.addresses.first])
|
||||
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", message.from])
|
||||
if user.nil?
|
||||
render :text => "No user found", :status => 404
|
||||
return false
|
||||
end
|
||||
|
||||
# load user settings
|
||||
context = user.prefs.sms_context
|
||||
|
||||
# prepare body
|
||||
if message.body.multipart?
|
||||
#body = message.body.parts[0].to_s
|
||||
body = message.body.preamble
|
||||
else
|
||||
body = message.body.to_s
|
||||
|
|
@ -65,24 +73,13 @@ class IntegrationsController < ApplicationController
|
|||
description = body
|
||||
notes = nil
|
||||
else
|
||||
description = message.subject.decoded.to_s
|
||||
description = message.subject.to_s
|
||||
notes = body
|
||||
end
|
||||
|
||||
# create todo
|
||||
todo = Todo.from_rich_message(user, context.id, description, notes)
|
||||
todo.save!
|
||||
render :text => 'success', :status => 200
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def verify_cloudmailin_signature
|
||||
provided = request.request_parameters.delete(:signature)
|
||||
signature = Digest::MD5.hexdigest(request.request_parameters.sort.map{|k,v| v}.join + SITE_CONFIG['cloudmailin'])
|
||||
|
||||
if provided != signature
|
||||
render :text => "Message signature fail #{provided} != #{signature}", :status => 403
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@ class IntegrationsControllerTest < ActionController::TestCase
|
|||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
# Replace this with your real tests.
|
||||
def test_truth
|
||||
assert true
|
||||
end
|
||||
|
||||
def test_page_load
|
||||
login_as(:admin_user)
|
||||
|
|
@ -24,4 +19,21 @@ class IntegrationsControllerTest < ActionController::TestCase
|
|||
assert_response :success
|
||||
end
|
||||
|
||||
def test_cloudmailin_integration
|
||||
SITE_CONFIG['cloudmailin'] = "123456789"
|
||||
post :cloudmailin, {
|
||||
"html"=>"",
|
||||
"plain"=>"asdasd",
|
||||
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
||||
"disposable"=>"",
|
||||
"from"=>"5555555555@tmomail.net",
|
||||
"signature"=>"e85e908fb893394762047c21e54ce248",
|
||||
"to"=>"<123123@cloudmailin.net>",
|
||||
"subject"=>"asd",
|
||||
"x_cc_header"=>"",
|
||||
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
||||
}
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue