-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
configuration_test.go
220 lines (187 loc) · 13 KB
/
configuration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package smtpmock
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewConfiguration(t *testing.T) {
t.Run("creates new configuration with default settings", func(t *testing.T) {
buildedConfiguration := newConfiguration(ConfigurationAttr{})
assert.Equal(t, defaultHostAddress, buildedConfiguration.hostAddress)
assert.False(t, buildedConfiguration.logToStdout)
assert.False(t, buildedConfiguration.isCmdFailFast)
assert.False(t, buildedConfiguration.multipleRcptto)
assert.False(t, buildedConfiguration.multipleMessageReceiving)
assert.False(t, buildedConfiguration.logServerActivity)
assert.Equal(t, defaultGreetingMsg, buildedConfiguration.msgGreeting)
assert.Equal(t, defaultInvalidCmdMsg, buildedConfiguration.msgInvalidCmd)
assert.Equal(t, defaultQuitMsg, buildedConfiguration.msgQuitCmd)
assert.Equal(t, defaultSessionTimeout, buildedConfiguration.sessionTimeout)
assert.Equal(t, defaultShutdownTimeout, buildedConfiguration.shutdownTimeout)
assert.Equal(t, defaultInvalidCmdHeloSequenceMsg, buildedConfiguration.msgInvalidCmdHeloSequence)
assert.Equal(t, defaultInvalidCmdHeloArgMsg, buildedConfiguration.msgInvalidCmdHeloArg)
assert.Equal(t, defaultTransientNegativeMsg, buildedConfiguration.msgHeloBlacklistedDomain)
assert.Equal(t, defaultReceivedMsg, buildedConfiguration.msgHeloReceived)
assert.Equal(t, defaultInvalidCmdMailfromSequenceMsg, buildedConfiguration.msgInvalidCmdMailfromSequence)
assert.Equal(t, defaultInvalidCmdMailfromArgMsg, buildedConfiguration.msgInvalidCmdMailfromArg)
assert.Equal(t, defaultTransientNegativeMsg, buildedConfiguration.msgMailfromBlacklistedEmail)
assert.Equal(t, defaultReceivedMsg, buildedConfiguration.msgMailfromReceived)
assert.Equal(t, defaultInvalidCmdRcpttoSequenceMsg, buildedConfiguration.msgInvalidCmdRcpttoSequence)
assert.Equal(t, defaultInvalidCmdRcpttoArgMsg, buildedConfiguration.msgInvalidCmdRcpttoArg)
assert.Equal(t, defaultTransientNegativeMsg, buildedConfiguration.msgRcpttoBlacklistedEmail)
assert.Equal(t, defaultNotRegistredRcpttoEmailMsg, buildedConfiguration.msgRcpttoNotRegisteredEmail)
assert.Equal(t, defaultReceivedMsg, buildedConfiguration.msgRcpttoReceived)
assert.Equal(t, defaultInvalidCmdDataSequenceMsg, buildedConfiguration.msgInvalidCmdDataSequence)
assert.Equal(t, defaultReadyForReceiveMsg, buildedConfiguration.msgDataReceived)
assert.Equal(t, defaultInvalidCmdHeloSequenceMsg, buildedConfiguration.msgInvalidCmdRsetSequence)
assert.Equal(t, defaultInvalidCmdMsg, buildedConfiguration.msgInvalidCmdRsetArg)
assert.Equal(t, defaultOkMsg, buildedConfiguration.msgRsetReceived)
assert.Equal(t, defaultOkMsg, buildedConfiguration.msgNoopReceived)
assert.Equal(t, fmt.Sprintf(defaultMsgSizeIsTooBigMsg+" %d bytes", defaultMessageSizeLimit), buildedConfiguration.msgMsgSizeIsTooBig)
assert.Equal(t, defaultReceivedMsg, buildedConfiguration.msgMsgReceived)
assert.Equal(t, defaultMessageSizeLimit, buildedConfiguration.msgSizeLimit)
assert.Empty(t, buildedConfiguration.blacklistedHeloDomains)
assert.Empty(t, buildedConfiguration.blacklistedMailfromEmails)
assert.Empty(t, buildedConfiguration.blacklistedRcpttoEmails)
assert.Empty(t, buildedConfiguration.notRegisteredEmails)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayHelo)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayMailfrom)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayRcptto)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayData)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayMessage)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayRset)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayNoop)
assert.Equal(t, defaultSessionResponseDelay, buildedConfiguration.responseDelayQuit)
})
t.Run("creates new configuration with custom settings", func(t *testing.T) {
configAttr := ConfigurationAttr{
HostAddress: "hostAddress",
PortNumber: 25,
LogToStdout: true,
LogServerActivity: true,
IsCmdFailFast: true,
MultipleRcptto: true,
MultipleMessageReceiving: true,
MsgGreeting: "msgGreeting",
MsgInvalidCmd: "msgInvalidCmd",
MsgQuitCmd: "msgQuitCmd",
MsgInvalidCmdHeloSequence: "msgInvalidCmdHeloSequence",
MsgInvalidCmdHeloArg: "msgInvalidCmdHeloArg",
MsgHeloBlacklistedDomain: "msgHeloBlacklistedDomain",
MsgHeloReceived: "msgHeloReceived",
MsgInvalidCmdMailfromSequence: "msgInvalidCmdMailfromSequence",
MsgInvalidCmdMailfromArg: "msgInvalidCmdMailfromArg",
MsgMailfromBlacklistedEmail: "msgMailfromBlacklistedEmail",
MsgMailfromReceived: "msgMailfromReceived",
MsgInvalidCmdRcpttoSequence: "msgInvalidCmdRcpttoSequence",
MsgInvalidCmdRcpttoArg: "msgInvalidCmdRcpttoArg",
MsgRcpttoNotRegisteredEmail: "msgRcpttoNotRegisteredEmail",
MsgRcpttoBlacklistedEmail: "msgRcpttoBlacklistedEmail",
MsgRcpttoReceived: "msgRcpttoReceived",
MsgInvalidCmdDataSequence: "msgInvalidCmdDataSequence",
MsgDataReceived: "msgDataReceived",
MsgMsgSizeIsTooBig: emptyString,
MsgMsgReceived: "msgMsgReceived",
MsgInvalidCmdRsetSequence: "msgInvalidCmdRsetSequence",
MsgInvalidCmdRsetArg: "msgInvalidCmdRsetArg",
MsgRsetReceived: "msgRsetReceived",
MsgNoopReceived: "msgNoopReceived",
BlacklistedHeloDomains: []string{},
BlacklistedMailfromEmails: []string{},
NotRegisteredEmails: []string{},
BlacklistedRcpttoEmails: []string{},
ResponseDelayHelo: 2,
ResponseDelayMailfrom: 2,
ResponseDelayRcptto: 2,
ResponseDelayData: 2,
ResponseDelayMessage: 2,
ResponseDelayRset: 2,
ResponseDelayNoop: 2,
ResponseDelayQuit: 2,
MsgSizeLimit: 42,
SessionTimeout: 120,
ShutdownTimeout: 2,
}
buildedConfiguration := newConfiguration(configAttr)
assert.Equal(t, configAttr.HostAddress, buildedConfiguration.hostAddress)
assert.Equal(t, configAttr.PortNumber, buildedConfiguration.portNumber)
assert.Equal(t, configAttr.LogToStdout, buildedConfiguration.logToStdout)
assert.Equal(t, configAttr.IsCmdFailFast, buildedConfiguration.isCmdFailFast)
assert.Equal(t, configAttr.MultipleRcptto, buildedConfiguration.multipleRcptto)
assert.Equal(t, configAttr.MultipleMessageReceiving, buildedConfiguration.multipleMessageReceiving)
assert.Equal(t, configAttr.LogServerActivity, buildedConfiguration.logServerActivity)
assert.Equal(t, configAttr.MsgGreeting, buildedConfiguration.msgGreeting)
assert.Equal(t, configAttr.MsgInvalidCmd, buildedConfiguration.msgInvalidCmd)
assert.Equal(t, configAttr.MsgQuitCmd, buildedConfiguration.msgQuitCmd)
assert.Equal(t, configAttr.SessionTimeout, buildedConfiguration.sessionTimeout)
assert.Equal(t, configAttr.ShutdownTimeout, buildedConfiguration.shutdownTimeout)
assert.Equal(t, configAttr.MsgInvalidCmdHeloSequence, buildedConfiguration.msgInvalidCmdHeloSequence)
assert.Equal(t, configAttr.MsgInvalidCmdHeloArg, buildedConfiguration.msgInvalidCmdHeloArg)
assert.Equal(t, configAttr.MsgHeloBlacklistedDomain, buildedConfiguration.msgHeloBlacklistedDomain)
assert.Equal(t, configAttr.MsgHeloReceived, buildedConfiguration.msgHeloReceived)
assert.Equal(t, configAttr.MsgInvalidCmdMailfromSequence, buildedConfiguration.msgInvalidCmdMailfromSequence)
assert.Equal(t, configAttr.MsgInvalidCmdMailfromArg, buildedConfiguration.msgInvalidCmdMailfromArg)
assert.Equal(t, configAttr.MsgMailfromBlacklistedEmail, buildedConfiguration.msgMailfromBlacklistedEmail)
assert.Equal(t, configAttr.MsgMailfromReceived, buildedConfiguration.msgMailfromReceived)
assert.Equal(t, configAttr.MsgInvalidCmdRcpttoSequence, buildedConfiguration.msgInvalidCmdRcpttoSequence)
assert.Equal(t, configAttr.MsgInvalidCmdRcpttoArg, buildedConfiguration.msgInvalidCmdRcpttoArg)
assert.Equal(t, configAttr.MsgRcpttoBlacklistedEmail, buildedConfiguration.msgRcpttoBlacklistedEmail)
assert.Equal(t, configAttr.MsgRcpttoNotRegisteredEmail, buildedConfiguration.msgRcpttoNotRegisteredEmail)
assert.Equal(t, configAttr.MsgRcpttoReceived, buildedConfiguration.msgRcpttoReceived)
assert.Equal(t, configAttr.MsgInvalidCmdDataSequence, buildedConfiguration.msgInvalidCmdDataSequence)
assert.Equal(t, configAttr.MsgDataReceived, buildedConfiguration.msgDataReceived)
assert.Equal(t, configAttr.MsgInvalidCmdRsetSequence, buildedConfiguration.msgInvalidCmdRsetSequence)
assert.Equal(t, configAttr.MsgInvalidCmdRsetArg, buildedConfiguration.msgInvalidCmdRsetArg)
assert.Equal(t, configAttr.MsgRsetReceived, buildedConfiguration.msgRsetReceived)
assert.Equal(t, configAttr.MsgNoopReceived, buildedConfiguration.msgNoopReceived)
assert.Equal(t, fmt.Sprintf(defaultMsgSizeIsTooBigMsg+" %d bytes", configAttr.MsgSizeLimit), buildedConfiguration.msgMsgSizeIsTooBig)
assert.Equal(t, configAttr.MsgMsgReceived, buildedConfiguration.msgMsgReceived)
assert.Equal(t, configAttr.MsgSizeLimit, buildedConfiguration.msgSizeLimit)
assert.Equal(t, configAttr.BlacklistedHeloDomains, buildedConfiguration.blacklistedHeloDomains)
assert.Equal(t, configAttr.BlacklistedMailfromEmails, buildedConfiguration.blacklistedMailfromEmails)
assert.Equal(t, configAttr.BlacklistedRcpttoEmails, buildedConfiguration.blacklistedRcpttoEmails)
assert.Equal(t, configAttr.NotRegisteredEmails, buildedConfiguration.notRegisteredEmails)
assert.Equal(t, configAttr.ResponseDelayHelo, buildedConfiguration.responseDelayHelo)
assert.Equal(t, configAttr.ResponseDelayMailfrom, buildedConfiguration.responseDelayMailfrom)
assert.Equal(t, configAttr.ResponseDelayRcptto, buildedConfiguration.responseDelayRcptto)
assert.Equal(t, configAttr.ResponseDelayData, buildedConfiguration.responseDelayData)
assert.Equal(t, configAttr.ResponseDelayMessage, buildedConfiguration.responseDelayMessage)
assert.Equal(t, configAttr.ResponseDelayRset, buildedConfiguration.responseDelayRset)
assert.Equal(t, configAttr.ResponseDelayNoop, buildedConfiguration.responseDelayNoop)
assert.Equal(t, configAttr.ResponseDelayQuit, buildedConfiguration.responseDelayQuit)
})
}
func TestConfigurationAttrAssignDefaultValues(t *testing.T) {
t.Run("assignes default values", func(t *testing.T) {
configurationAttr := new(ConfigurationAttr)
configurationAttr.assignDefaultValues()
assert.Equal(t, defaultHostAddress, configurationAttr.HostAddress)
assert.Equal(t, defaultGreetingMsg, configurationAttr.MsgGreeting)
assert.Equal(t, defaultInvalidCmdMsg, configurationAttr.MsgInvalidCmd)
assert.Equal(t, defaultQuitMsg, configurationAttr.MsgQuitCmd)
assert.Equal(t, defaultSessionTimeout, configurationAttr.SessionTimeout)
assert.Equal(t, defaultShutdownTimeout, configurationAttr.ShutdownTimeout)
assert.Equal(t, defaultInvalidCmdHeloSequenceMsg, configurationAttr.MsgInvalidCmdHeloSequence)
assert.Equal(t, defaultInvalidCmdHeloArgMsg, configurationAttr.MsgInvalidCmdHeloArg)
assert.Equal(t, defaultTransientNegativeMsg, configurationAttr.MsgHeloBlacklistedDomain)
assert.Equal(t, defaultReceivedMsg, configurationAttr.MsgHeloReceived)
assert.Equal(t, defaultInvalidCmdMailfromSequenceMsg, configurationAttr.MsgInvalidCmdMailfromSequence)
assert.Equal(t, defaultInvalidCmdMailfromArgMsg, configurationAttr.MsgInvalidCmdMailfromArg)
assert.Equal(t, defaultTransientNegativeMsg, configurationAttr.MsgMailfromBlacklistedEmail)
assert.Equal(t, defaultReceivedMsg, configurationAttr.MsgMailfromReceived)
assert.Equal(t, defaultInvalidCmdRcpttoSequenceMsg, configurationAttr.MsgInvalidCmdRcpttoSequence)
assert.Equal(t, defaultInvalidCmdRcpttoArgMsg, configurationAttr.MsgInvalidCmdRcpttoArg)
assert.Equal(t, defaultTransientNegativeMsg, configurationAttr.MsgRcpttoBlacklistedEmail)
assert.Equal(t, defaultNotRegistredRcpttoEmailMsg, configurationAttr.MsgRcpttoNotRegisteredEmail)
assert.Equal(t, defaultReceivedMsg, configurationAttr.MsgRcpttoReceived)
assert.Equal(t, defaultInvalidCmdDataSequenceMsg, configurationAttr.MsgInvalidCmdDataSequence)
assert.Equal(t, defaultReadyForReceiveMsg, configurationAttr.MsgDataReceived)
assert.Equal(t, defaultInvalidCmdHeloSequenceMsg, configurationAttr.MsgInvalidCmdRsetSequence)
assert.Equal(t, defaultInvalidCmdMsg, configurationAttr.MsgInvalidCmdRsetArg)
assert.Equal(t, defaultOkMsg, configurationAttr.MsgRsetReceived)
assert.Equal(t, defaultOkMsg, configurationAttr.MsgNoopReceived)
assert.Equal(t, fmt.Sprintf(defaultMsgSizeIsTooBigMsg+" %d bytes", defaultMessageSizeLimit), configurationAttr.MsgMsgSizeIsTooBig)
assert.Equal(t, defaultReceivedMsg, configurationAttr.MsgMsgReceived)
assert.Equal(t, defaultMessageSizeLimit, configurationAttr.MsgSizeLimit)
})
}