github.com/topsteplocal/gophish@v0.6.0/models/smtp_test.go (about)

     1  package models
     2  
     3  import (
     4  	"fmt"
     5  
     6  	check "gopkg.in/check.v1"
     7  )
     8  
     9  func (s *ModelsSuite) TestPostSMTP(c *check.C) {
    10  	smtp := SMTP{
    11  		Name:        "Test SMTP",
    12  		Host:        "1.1.1.1:25",
    13  		FromAddress: "Foo Bar <foo@example.com>",
    14  		UserId:      1,
    15  	}
    16  	err = PostSMTP(&smtp)
    17  	c.Assert(err, check.Equals, nil)
    18  	ss, err := GetSMTPs(1)
    19  	c.Assert(err, check.Equals, nil)
    20  	c.Assert(len(ss), check.Equals, 1)
    21  }
    22  
    23  func (s *ModelsSuite) TestPostSMTPNoHost(c *check.C) {
    24  	smtp := SMTP{
    25  		Name:        "Test SMTP",
    26  		FromAddress: "Foo Bar <foo@example.com>",
    27  		UserId:      1,
    28  	}
    29  	err = PostSMTP(&smtp)
    30  	c.Assert(err, check.Equals, ErrHostNotSpecified)
    31  }
    32  
    33  func (s *ModelsSuite) TestPostSMTPNoFrom(c *check.C) {
    34  	smtp := SMTP{
    35  		Name:   "Test SMTP",
    36  		UserId: 1,
    37  		Host:   "1.1.1.1:25",
    38  	}
    39  	err = PostSMTP(&smtp)
    40  	c.Assert(err, check.Equals, ErrFromAddressNotSpecified)
    41  }
    42  
    43  func (s *ModelsSuite) TestPostSMTPValidHeader(c *check.C) {
    44  	smtp := SMTP{
    45  		Name:        "Test SMTP",
    46  		Host:        "1.1.1.1:25",
    47  		FromAddress: "Foo Bar <foo@example.com>",
    48  		UserId:      1,
    49  		Headers: []Header{
    50  			Header{Key: "Reply-To", Value: "test@example.com"},
    51  			Header{Key: "X-Mailer", Value: "gophish"},
    52  		},
    53  	}
    54  	err = PostSMTP(&smtp)
    55  	c.Assert(err, check.Equals, nil)
    56  	ss, err := GetSMTPs(1)
    57  	c.Assert(err, check.Equals, nil)
    58  	c.Assert(len(ss), check.Equals, 1)
    59  }
    60  
    61  func (s *ModelsSuite) TestSMTPGetDialer(ch *check.C) {
    62  	host := "localhost"
    63  	port := 25
    64  	smtp := SMTP{
    65  		Host:             fmt.Sprintf("%s:%d", host, port),
    66  		IgnoreCertErrors: false,
    67  	}
    68  	d, err := smtp.GetDialer()
    69  	ch.Assert(err, check.Equals, nil)
    70  
    71  	dialer := d.(*Dialer).Dialer
    72  	ch.Assert(dialer.Host, check.Equals, host)
    73  	ch.Assert(dialer.Port, check.Equals, port)
    74  	ch.Assert(dialer.TLSConfig.ServerName, check.Equals, smtp.Host)
    75  	ch.Assert(dialer.TLSConfig.InsecureSkipVerify, check.Equals, smtp.IgnoreCertErrors)
    76  }