File: exim_spec.rb

package info (click to toggle)
ruby-mail 2.8.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,704 kB
  • sloc: ruby: 73,709; makefile: 3
file content (101 lines) | stat: -rw-r--r-- 2,910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'

describe "exim delivery agent" do
  let :mail do
    Mail.new do
      from    'roger@test.lindsaar.net'
      to      'marcel@test.lindsaar.net, bob@test.lindsaar.net'
      subject 'some subject'
    end
  end

  before do
    Mail.defaults do
      delivery_method :exim
    end
  end

  it "should send an email using exim" do
    expect(mail.delivery_method).to receive(:popen).with(%w[ /usr/sbin/exim -i -t -f roger@test.lindsaar.net ])

    mail.deliver!
  end

  describe "return path" do
    it "should send an email with a return-path using exim" do
      expect(mail.delivery_method).to receive(:popen).with(%w[ /usr/sbin/exim -i -t -f return@test.lindsaar.net ])

      mail.return_path = "return@test.lindsaar.net"
      mail.sender = "sender@test.lindsaar.net"
      mail.deliver
    end

    it "should use the sender address is no return path is specified" do
      expect(mail.delivery_method).to receive(:popen).with(%w[ /usr/sbin/exim -i -t -f sender@test.lindsaar.net ])

      mail.sender = "sender@test.lindsaar.net"
      mail.deliver
    end

    it "should use the from address is no return path or sender are specified" do
      expect(mail.delivery_method).to receive(:popen).with(%w[ /usr/sbin/exim -i -t -f from@test.lindsaar.net ])

      mail.from = "from@test.lindsaar.net"
      mail.deliver
    end

    it "should escape the return path address" do
      expect(mail.delivery_method).to receive(:popen).with([ '/usr/sbin/exim', '-i', '-t', '-f', '"from+suffix test"@test.lindsaar.net' ])

      mail.from = '"from+suffix test"@test.lindsaar.net'
      mail.deliver
    end

    it 'should not escape ~ in return path address' do
      expect(mail.delivery_method).to receive(:popen).
        with(%w[ /usr/sbin/exim -i -t -f tilde~@test.lindsaar.net ])

      mail.from = 'tilde~@test.lindsaar.net'
      mail.deliver
    end
  end

  it "should still send an email if the settings have been set to nil" do
    expect(mail.delivery_method).to receive(:popen).with(%w[ /usr/sbin/exim -f roger@test.lindsaar.net ])

    mail.delivery_method.settings[:arguments] = nil
    mail.deliver!
  end

  it "should escape evil haxxor attemptes" do
    evil = '"foo\";touch /tmp/PWNED;\""@blah.com'

    expect(mail.delivery_method).to receive(:popen).with(
      [ '/usr/sbin/exim', '-i', '-t', '-f', evil ])

    mail.from = evil
    mail.deliver!
  end

  it "should raise an error if no sender is defined" do
    mail.from = nil

    expect(mail.smtp_envelope_from).to be_nil

    expect do
      mail.deliver
    end.to raise_error('SMTP From address may not be blank: nil')
  end

  it "should raise an error if no recipient if defined" do
    mail.to = nil

    expect(mail.smtp_envelope_to).to eq([])

    expect do
      mail.deliver
    end.to raise_error('SMTP To address may not be blank: []')
  end
end