2018-09-04 01:28:32 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-24 20:39:33 +00:00
|
|
|
"github.com/dmarushkin/go-qrcode/v2"
|
|
|
|
|
2018-09-04 01:28:32 +00:00
|
|
|
check "gopkg.in/check.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mockTemplateContext struct {
|
|
|
|
URL string
|
|
|
|
FromAddress string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockTemplateContext) getFromAddress() string {
|
|
|
|
return m.FromAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m mockTemplateContext) getBaseURL() string {
|
|
|
|
return m.URL
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ModelsSuite) TestNewTemplateContext(c *check.C) {
|
|
|
|
r := Result{
|
|
|
|
BaseRecipient: BaseRecipient{
|
|
|
|
FirstName: "Foo",
|
|
|
|
LastName: "Bar",
|
|
|
|
Email: "foo@bar.com",
|
|
|
|
},
|
|
|
|
RId: "1234567",
|
|
|
|
}
|
|
|
|
ctx := mockTemplateContext{
|
|
|
|
URL: "http://example.com",
|
|
|
|
FromAddress: "From Address <from@example.com>",
|
|
|
|
}
|
2023-03-24 20:39:33 +00:00
|
|
|
|
|
|
|
qrc, _ := qrcode.New(fmt.Sprintf("%s?rid=%s", ctx.URL, r.RId))
|
2023-06-16 07:39:05 +00:00
|
|
|
url_qr := qrc.GetHtmlStr()
|
2023-03-24 20:39:33 +00:00
|
|
|
|
2018-09-04 01:28:32 +00:00
|
|
|
expected := PhishingTemplateContext{
|
|
|
|
URL: fmt.Sprintf("%s?rid=%s", ctx.URL, r.RId),
|
2023-03-24 20:39:33 +00:00
|
|
|
URL_QR: url_qr,
|
2018-09-04 01:28:32 +00:00
|
|
|
BaseURL: ctx.URL,
|
|
|
|
BaseRecipient: r.BaseRecipient,
|
|
|
|
TrackingURL: fmt.Sprintf("%s/track?rid=%s", ctx.URL, r.RId),
|
|
|
|
From: "From Address",
|
|
|
|
RId: r.RId,
|
|
|
|
}
|
2023-03-24 20:39:33 +00:00
|
|
|
|
2018-09-04 01:28:32 +00:00
|
|
|
expected.Tracker = "<img alt='' style='display: none' src='" + expected.TrackingURL + "'/>"
|
|
|
|
got, err := NewPhishingTemplateContext(ctx, r.BaseRecipient, r.RId)
|
|
|
|
c.Assert(err, check.Equals, nil)
|
|
|
|
c.Assert(got, check.DeepEquals, expected)
|
|
|
|
}
|