Fixed template validation to better support the all the possible template tags. Fixes #1189

1205-drop-campaigns
Jordan Wright 2018-09-08 18:04:21 -05:00
parent 159ea126a0
commit 0c5925aeec
2 changed files with 32 additions and 21 deletions

View File

@ -36,31 +36,28 @@ func (t *Template) Validate() error {
}
// Test that the variables used in the template
// validate with no issues
td := struct {
Result
URL string
TrackingURL string
Tracker string
From string
}{
Result{
BaseRecipient: BaseRecipient{
Email: "foo@bar.com",
FirstName: "Foo",
LastName: "Bar",
Position: "Test",
},
},
"http://foo.bar",
"http://foo.bar/track",
"<img src='http://foo.bar/track",
"John Doe <foo@bar.com>",
vc := ValidationContext{
FromAddress: "foo@bar.com",
BaseURL: "http://example.com",
}
_, err := ExecuteTemplate(t.HTML, td)
td := Result{
BaseRecipient: BaseRecipient{
Email: "foo@bar.com",
FirstName: "Foo",
LastName: "Bar",
Position: "Test",
},
RId: "123456",
}
ptx, err := NewPhishingTemplateContext(vc, td.BaseRecipient, td.RId)
if err != nil {
return err
}
_, err = ExecuteTemplate(t.Text, td)
_, err = ExecuteTemplate(t.HTML, ptx)
if err != nil {
return err
}
_, err = ExecuteTemplate(t.Text, ptx)
if err != nil {
return err
}

View File

@ -15,6 +15,20 @@ type TemplateContext interface {
getBaseURL() string
}
// ValidationContext is used for validating templates and pages
type ValidationContext struct {
FromAddress string
BaseURL string
}
func (vc ValidationContext) getFromAddress() string {
return vc.FromAddress
}
func (vc ValidationContext) getBaseURL() string {
return vc.BaseURL
}
// PhishingTemplateContext is the context that is sent to any template, such
// as the email or landing page content.
type PhishingTemplateContext struct {