|
| 1 | +package smtp |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/zmap/zgrab2" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestVerifySMTPContents(t *testing.T) { |
| 9 | + type Test struct { |
| 10 | + Banner string |
| 11 | + ExpectedStatus zgrab2.ScanStatus |
| 12 | + ExpectedCode int |
| 13 | + } |
| 14 | + testTable := map[string]Test{ |
| 15 | + "success with code": { |
| 16 | + Banner: `220-some.host.com ESMTP Exim 4.93 #2 Thu, 04 Feb 2021 13:34:12 -0500 |
| 17 | +220-We do not authorize the use of this system to transport unsolicited, |
| 18 | +220 and/or bulk e-mail.`, |
| 19 | + ExpectedStatus: zgrab2.SCAN_SUCCESS, |
| 20 | + ExpectedCode: 0, |
| 21 | + }, |
| 22 | + "success without code": { |
| 23 | + Banner: `ESMTP Exim 4.93 #2 Thu, 04 Feb 2021 13:34:12 -0500 |
| 24 | +220-We do not authorize the use of this system to transport unsolicited, |
| 25 | +220 and/or bulk e-mail.`, |
| 26 | + ExpectedStatus: zgrab2.SCAN_SUCCESS, |
| 27 | + ExpectedCode: 0, |
| 28 | + }, |
| 29 | + "invalid protocol": { |
| 30 | + Banner: "gibberish that doesnt match expected response", |
| 31 | + ExpectedStatus: zgrab2.SCAN_PROTOCOL_ERROR, |
| 32 | + ExpectedCode: 0, |
| 33 | + }, |
| 34 | + "error response": { |
| 35 | + Banner: "500-some.host.com ESMTP something went horribly wrong.", |
| 36 | + ExpectedStatus: zgrab2.SCAN_APPLICATION_ERROR, |
| 37 | + ExpectedCode: 500, |
| 38 | + }, |
| 39 | + } |
| 40 | + |
| 41 | + for name, test := range testTable { |
| 42 | + t.Run(name, func(t *testing.T) { |
| 43 | + status, code := VerifySMTPContents(test.Banner) |
| 44 | + if status != test.ExpectedStatus { |
| 45 | + t.Errorf("recieved unexpected status: %s, wanted: %s", status, test.ExpectedStatus) |
| 46 | + } |
| 47 | + if code != test.ExpectedCode { |
| 48 | + t.Errorf("recieved unexpected code: %d, wanted: %d", code, test.ExpectedCode) |
| 49 | + } |
| 50 | + }) |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments