4

Notifier_test.rb にテストがあります。ここで、Notifier はメーラー クラスです。

mail = Notifier.registered_client(client.firstname, client.emailaddress)

assert_match I18n.t('notifier.registered_client.email_body'), mail.body.encoded, 'Email contents should be correct'

Rails 3.2.8 より前はこのテストに合格していましたが、現在は次のように失敗しています。

NotifierTest
      FAIL (0:00:07.963) should create registration email in English
      Email contents should be correct.
      Expected /In\ order\ to\ activate\ your\ company's\ registration\ you\ must\ click\ on\ the\ following\ link:/ 
      to match 
      "\nDear First Name, thanks for registering.\n\nIn order to activate your company\'s registration you must click on the following link:\n\nhttp://localhost:3000/en/clients/activate?email=english%40email.com&key=7b6e6ed1-ac03-4d95-a0d5-6f2541092dd0\n".

私のメールのテキストにアポストロフィが含まれているため、エラーが発生しているようです。これは、次のパッチのためにmail.body.encoded返されます。\'

CVE-2012-3464 https://groups.google.com/forum/#!msg/rubyonrails-security/kKGNeMrnmiY/r2yM7xy-G48Jで説明されている Ruby on Rails の潜在的な XSS 脆弱性

I18n.t によって返された文字列を同じ方法でエンコードするか、メール オブジェクトからアポストロフィなしでテキストを取得する最もスマートな方法は何ですか?

4

1 に答える 1

1

最後に、これを使用して動作するようになりました

CGI.unescapeHTML(mail.body.encoded)

ラインが

assert_match I18n.t('notifier.registered_client.email_greeting', name: firstname), CGI.unescapeHTML(mail.body.encoded), '電子メールの挨拶が存在する必要があります'

テストに合格

于 2012-09-30T05:22:27.317 に答える