Updated validation function

pull/1972/head
Glenn Wilkinson 2020-08-28 21:53:27 +01:00
parent ad20017981
commit b02670d207
2 changed files with 15 additions and 12 deletions

View File

@ -22,23 +22,26 @@ type Attachment struct {
} }
// ValidateAttachment ensures that the provided attachment uses the supported template variables correctly. // ValidateAttachment ensures that the provided attachment uses the supported template variables correctly.
func (a Attachment) ValidateAttachment() error { func (a Attachment) Validate() error {
ptx := PhishingTemplateContext{ vc := ValidationContext{
FromAddress: "foo@bar.com",
BaseURL: "http://example.com",
}
td := Result{
BaseRecipient: BaseRecipient{ BaseRecipient: BaseRecipient{
Email: "foo@bar.com",
FirstName: "Foo", FirstName: "Foo",
LastName: "Bar", LastName: "Bar",
Email: "foo@bar.com", Position: "Test",
}, },
BaseURL: "http://testurl.com", RId: "123456",
URL: "http://testurl.com/?rid=1234567",
TrackingURL: "http://testurl.local/track?rid=1234567",
Tracker: "<img alt='' style='display: none' src='http://testurl.local/track?rid=1234567'/>",
From: "Foobus Barbus",
RId: "1234567",
} }
ptx, err := NewPhishingTemplateContext(vc, td.BaseRecipient, td.RId)
_, err := a.ApplyTemplate(ptx) if err != nil {
return err
}
_, err = a.ApplyTemplate(ptx)
return err return err
} }

View File

@ -41,7 +41,7 @@ func (t *Template) Validate() error {
return err return err
} }
for _, a := range t.Attachments { for _, a := range t.Attachments {
if err := a.ValidateAttachment(); err != nil { if err := a.Validate(); err != nil {
return err return err
} }
} }