-
Jordan Wright committed 6 years ago1 parent 0c5925ae
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
-
-
skipped 33 lines 34 34 case t.Text == "" && t.HTML == "": 35 35 return ErrTemplateMissingParameter 36 36 } 37 - // Test that the variables used in the template 38 - // validate with no issues 39 - vc := ValidationContext{ 40 - FromAddress: "[email protected]", 41 - BaseURL: "http://example.com", 42 - } 43 - td := Result{ 44 - BaseRecipient: BaseRecipient{ 45 - Email: "[email protected]", 46 - FirstName: "Foo", 47 - LastName: "Bar", 48 - Position: "Test", 49 - }, 50 - RId: "123456", 51 - } 52 - ptx, err := NewPhishingTemplateContext(vc, td.BaseRecipient, td.RId) 53 - if err != nil { 37 + if err = ValidateTemplate(t.HTML); err != nil { 54 38 return err 55 39 } 56 - _, err = ExecuteTemplate(t.HTML, ptx) 57 - if err != nil { 58 - return err 59 - } 60 - _, err = ExecuteTemplate(t.Text, ptx) 61 - if err != nil { 40 + if err = ValidateTemplate(t.Text); err != nil { 62 41 return err 63 42 } 64 43 return nil skipped 142 lines -
skipped 14 lines 15 15 getBaseURL() string 16 16 } 17 17 18 - // ValidationContext is used for validating templates and pages 19 - type ValidationContext struct { 20 - FromAddress string 21 - BaseURL string 22 - } 23 - 24 - func (vc ValidationContext) getFromAddress() string { 25 - return vc.FromAddress 26 - } 27 - 28 - func (vc ValidationContext) getBaseURL() string { 29 - return vc.BaseURL 30 - } 31 - 32 18 // PhishingTemplateContext is the context that is sent to any template, such 33 19 // as the email or landing page content. 34 20 type PhishingTemplateContext struct { skipped 60 lines 95 81 return buff.String(), err 96 82 } 97 83 84 + // ValidationContext is used for validating templates and pages 85 + type ValidationContext struct { 86 + FromAddress string 87 + BaseURL string 88 + } 89 + 90 + func (vc ValidationContext) getFromAddress() string { 91 + return vc.FromAddress 92 + } 93 + 94 + func (vc ValidationContext) getBaseURL() string { 95 + return vc.BaseURL 96 + } 97 + 98 + // ValidateTemplate ensures that the provided text in the page or template 99 + // uses the supported template variables correctly. 100 + func ValidateTemplate(text string) error { 101 + vc := ValidationContext{ 102 + FromAddress: "[email protected]", 103 + BaseURL: "http://example.com", 104 + } 105 + td := Result{ 106 + BaseRecipient: BaseRecipient{ 107 + Email: "[email protected]", 108 + FirstName: "Foo", 109 + LastName: "Bar", 110 + Position: "Test", 111 + }, 112 + RId: "123456", 113 + } 114 + ptx, err := NewPhishingTemplateContext(vc, td.BaseRecipient, td.RId) 115 + if err != nil { 116 + return err 117 + } 118 + _, err = ExecuteTemplate(text, ptx) 119 + if err != nil { 120 + return err 121 + } 122 + return nil 123 + } 124 +