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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
%global _empty_manifest_terminate_build 0
Name: python-smtpdfix
Version: 0.5.0
Release: 1
Summary: A SMTP server for use as a pytest fixture that implements encryption and authentication for testing.
License: MIT
URL: https://github.com/bebleo/smtpdfix
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/5d/53/ae0e6f30af8d8d6beb196e6d5a2234eb48804be2b8afbc4c2670025fb6c4/smtpdfix-0.5.0.tar.gz
BuildArch: noarch
Requires: python3-aiosmtpd
Requires: python3-portpicker
Requires: python3-pytest
Requires: python3-cryptography
Requires: python3-cryptography
Requires: python3-flake8
Requires: python3-isort
Requires: python3-pytest-asyncio
Requires: python3-pytest-cov
Requires: python3-pytest-timeout
Requires: python3-tox
Requires: python3-mypy
%description
`host` | `SMTPD_HOST` | `127.0.0.1` or `::1` | The hostname that the fixture will listen on.
`port` | `SMTPD_PORT` | `a random free port` | The port that the fixture will listen on.
`ready_timeout` | `SMTPD_READY_TIMEOUT` | `10.0` | The seconds the server will wait to start before raising a `TimeoutError`.
`login_username` | `SMTPD_LOGIN_NAME` | `user` | Username for default authentication.
`login_password` | `SMTPD_LOGIN_PASSWORD` | `password` | Password for default authentication.
`use_ssl` | `SMTPD_USE_SSL` | `False` | Whether the fixture should use fixed TLS/SSL for transactions. If using smtplib requires that `SMTP_SSL` be used instead of `SMTP`.
`use_starttls` | `SMTPD_USE_STARTTLS` | `False` | Whether the fixture should use StartTLS to encrypt the connections. If using `smtplib` requires that `SMTP.starttls()` is called before other commands are issued. Overrides `use_tls` as the preferred method for securing communications with the client.
`enforce_auth` | `SMTPD_ENFORCE_AUTH` | `False` | If set to true then the fixture refuses MAIL, RCPT, DATA commands until authentication is completed.
`ssl_cert_path` | `SMTPD_SSL_CERTS_PATH` | `./certs/` | The path to the key and certificate in PEM format for encryption with SSL/TLS or StartTLS.
`ssl_cert_files` | `SMTPD_SSL_CERT_FILE` and `SMTPD_SSL_KEY_FILE` | `("cert.pem", None)` | A tuple of the path for the certificate file and key file in PEM format. See [Resolving certificate and key paths](#resolving-certificate-and-key-paths) for more details.
### Resolving certificate and key paths
In order to resolve the certificate and key paths for the SSL/TLS context SMTPDFix does the following:
1. On initialization of a `smtpdfix.Config` the `ssl_cert_path` is set by the `SMTPD_SSL_CERTS_PATH` environment variable and the `ssl_cert_files` is set to a tuple of `(SMTPD_SSL_CERT_FILE and SMTPD_SSL_KEY_FILE)`. If the environment variables are not set the deafults are used.
2. If an SSL Context is needed, when the `smptdfix.AuthController` is initialized it will attempt to find the files in the following sequence for both the certificate file and the key file:
1. If the value in `ssl_cert_files` is `None` then `None` is returned. Setting the key file to be none assumes that it has been included in the certificate file.
2. If the value in `ssl_cert_files` is a valid path to a file then this is returned.
3. `ssl_cert_path` and the value from `ssl_cert_files` are joined and returned if it a valid path to a file.
4. A `FileNotFoundError` is raised.
An example, assuming that the certificate and key are written in a single PEM file located at `./certificates/localhost.cert.pem` would be:
```python
from smtplib import STMP_SSL
def test_custom_certificate(smtpd):
smtpd.config.ssl_cert_files = "./certificates/localhost.cert.pem"
smtpd.config.use_ssl = True
from_ = "from.addr@example.org"
to_ = "to.addr@example.org"
msg = (f"From: {from_}\r\n"
f"To: {to_}\r\n"
f"Subject: Foo\r\n\r\n"
f"Foo bar")
with SMTP_SSL(smtpd.hostname, smtpd.port) as client:
client.sendmail(from_addr, to_addrs, msg)
assert len(smtpd.messages) == 1
```
## Alternatives
Many libraries for sending email have built-in methods for testing and using these methods should generally be prefered over SMTPDFix. Some known solutions:
+ **fastapi-mail**: has a `record_messsages()` method to intercept the mail. Instructions on how to suppress the sending of mail and implement it can be seen at [https://sabuhish.github.io/fastapi-mail/example/#unittests-using-fastapimail](https://sabuhish.github.io/fastapi-mail/example/#unittests-using-fastapimail)
+ **flask-mail**: has a method to suppress sending and capture the email for testing purposes. [Instructions](https://pythonhosted.org/Flask-Mail/#unit-tests-and-suppressing-emails)
## Developing
To develop and test smtpdfix you will need to install [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) to run asynchronous tests, [isort](https://pycqa.github.io/isort/) to sort imports and [flake8](https://flake8.pycqa.org/en/latest/) to lint. To install in a virtual environment for development:
```bash
$ python -m venv venv
$ ./venv/scripts/activate
$ pip install -e .[dev]
```
Code is tested using tox:
```bash
$ tox
```
Quick tests can be handled by running pytest directly:
```bash
$ pytest -p no:smtpd --cov
```
Before submitting a pull request with your changes you should ensure that all imports are sorted and that the code passes linting with flake8.
```bash
$ isort .
$ flake8 .
```
We include a [pre-commit](https://pre-commit.com/) configuration file to automate checks and clean up imports before pushing code. In order to install pre-commit git hooks:
```bash
$ pip install pre-commit
$ pre-commit install
```
## Known Issues
+ Firewalls may interfere with the operation of the smtp server.
+ Authenticating with LOGIN and PLAIN mechanisms fails over TLS/SSL, but works with STARTTLS. [Issue #10](https://github.com/bebleo/smtpdfix/issues/10)
+ Currently no support for termination through signals. [Issue #4](https://github.com/bebleo/smtpdfix/issues/4)
+ If the fixture start exceeds the `ready_timeout` and aborts the host and port are not consistently released and subsequent uses may result in an error. [Issue #80](https://github.com/bebleo/smtpdfix/issues/80)
Written with ☕ and ❤ in Montreal, QC
%package -n python3-smtpdfix
Summary: A SMTP server for use as a pytest fixture that implements encryption and authentication for testing.
Provides: python-smtpdfix
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-smtpdfix
`host` | `SMTPD_HOST` | `127.0.0.1` or `::1` | The hostname that the fixture will listen on.
`port` | `SMTPD_PORT` | `a random free port` | The port that the fixture will listen on.
`ready_timeout` | `SMTPD_READY_TIMEOUT` | `10.0` | The seconds the server will wait to start before raising a `TimeoutError`.
`login_username` | `SMTPD_LOGIN_NAME` | `user` | Username for default authentication.
`login_password` | `SMTPD_LOGIN_PASSWORD` | `password` | Password for default authentication.
`use_ssl` | `SMTPD_USE_SSL` | `False` | Whether the fixture should use fixed TLS/SSL for transactions. If using smtplib requires that `SMTP_SSL` be used instead of `SMTP`.
`use_starttls` | `SMTPD_USE_STARTTLS` | `False` | Whether the fixture should use StartTLS to encrypt the connections. If using `smtplib` requires that `SMTP.starttls()` is called before other commands are issued. Overrides `use_tls` as the preferred method for securing communications with the client.
`enforce_auth` | `SMTPD_ENFORCE_AUTH` | `False` | If set to true then the fixture refuses MAIL, RCPT, DATA commands until authentication is completed.
`ssl_cert_path` | `SMTPD_SSL_CERTS_PATH` | `./certs/` | The path to the key and certificate in PEM format for encryption with SSL/TLS or StartTLS.
`ssl_cert_files` | `SMTPD_SSL_CERT_FILE` and `SMTPD_SSL_KEY_FILE` | `("cert.pem", None)` | A tuple of the path for the certificate file and key file in PEM format. See [Resolving certificate and key paths](#resolving-certificate-and-key-paths) for more details.
### Resolving certificate and key paths
In order to resolve the certificate and key paths for the SSL/TLS context SMTPDFix does the following:
1. On initialization of a `smtpdfix.Config` the `ssl_cert_path` is set by the `SMTPD_SSL_CERTS_PATH` environment variable and the `ssl_cert_files` is set to a tuple of `(SMTPD_SSL_CERT_FILE and SMTPD_SSL_KEY_FILE)`. If the environment variables are not set the deafults are used.
2. If an SSL Context is needed, when the `smptdfix.AuthController` is initialized it will attempt to find the files in the following sequence for both the certificate file and the key file:
1. If the value in `ssl_cert_files` is `None` then `None` is returned. Setting the key file to be none assumes that it has been included in the certificate file.
2. If the value in `ssl_cert_files` is a valid path to a file then this is returned.
3. `ssl_cert_path` and the value from `ssl_cert_files` are joined and returned if it a valid path to a file.
4. A `FileNotFoundError` is raised.
An example, assuming that the certificate and key are written in a single PEM file located at `./certificates/localhost.cert.pem` would be:
```python
from smtplib import STMP_SSL
def test_custom_certificate(smtpd):
smtpd.config.ssl_cert_files = "./certificates/localhost.cert.pem"
smtpd.config.use_ssl = True
from_ = "from.addr@example.org"
to_ = "to.addr@example.org"
msg = (f"From: {from_}\r\n"
f"To: {to_}\r\n"
f"Subject: Foo\r\n\r\n"
f"Foo bar")
with SMTP_SSL(smtpd.hostname, smtpd.port) as client:
client.sendmail(from_addr, to_addrs, msg)
assert len(smtpd.messages) == 1
```
## Alternatives
Many libraries for sending email have built-in methods for testing and using these methods should generally be prefered over SMTPDFix. Some known solutions:
+ **fastapi-mail**: has a `record_messsages()` method to intercept the mail. Instructions on how to suppress the sending of mail and implement it can be seen at [https://sabuhish.github.io/fastapi-mail/example/#unittests-using-fastapimail](https://sabuhish.github.io/fastapi-mail/example/#unittests-using-fastapimail)
+ **flask-mail**: has a method to suppress sending and capture the email for testing purposes. [Instructions](https://pythonhosted.org/Flask-Mail/#unit-tests-and-suppressing-emails)
## Developing
To develop and test smtpdfix you will need to install [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) to run asynchronous tests, [isort](https://pycqa.github.io/isort/) to sort imports and [flake8](https://flake8.pycqa.org/en/latest/) to lint. To install in a virtual environment for development:
```bash
$ python -m venv venv
$ ./venv/scripts/activate
$ pip install -e .[dev]
```
Code is tested using tox:
```bash
$ tox
```
Quick tests can be handled by running pytest directly:
```bash
$ pytest -p no:smtpd --cov
```
Before submitting a pull request with your changes you should ensure that all imports are sorted and that the code passes linting with flake8.
```bash
$ isort .
$ flake8 .
```
We include a [pre-commit](https://pre-commit.com/) configuration file to automate checks and clean up imports before pushing code. In order to install pre-commit git hooks:
```bash
$ pip install pre-commit
$ pre-commit install
```
## Known Issues
+ Firewalls may interfere with the operation of the smtp server.
+ Authenticating with LOGIN and PLAIN mechanisms fails over TLS/SSL, but works with STARTTLS. [Issue #10](https://github.com/bebleo/smtpdfix/issues/10)
+ Currently no support for termination through signals. [Issue #4](https://github.com/bebleo/smtpdfix/issues/4)
+ If the fixture start exceeds the `ready_timeout` and aborts the host and port are not consistently released and subsequent uses may result in an error. [Issue #80](https://github.com/bebleo/smtpdfix/issues/80)
Written with ☕ and ❤ in Montreal, QC
%package help
Summary: Development documents and examples for smtpdfix
Provides: python3-smtpdfix-doc
%description help
`host` | `SMTPD_HOST` | `127.0.0.1` or `::1` | The hostname that the fixture will listen on.
`port` | `SMTPD_PORT` | `a random free port` | The port that the fixture will listen on.
`ready_timeout` | `SMTPD_READY_TIMEOUT` | `10.0` | The seconds the server will wait to start before raising a `TimeoutError`.
`login_username` | `SMTPD_LOGIN_NAME` | `user` | Username for default authentication.
`login_password` | `SMTPD_LOGIN_PASSWORD` | `password` | Password for default authentication.
`use_ssl` | `SMTPD_USE_SSL` | `False` | Whether the fixture should use fixed TLS/SSL for transactions. If using smtplib requires that `SMTP_SSL` be used instead of `SMTP`.
`use_starttls` | `SMTPD_USE_STARTTLS` | `False` | Whether the fixture should use StartTLS to encrypt the connections. If using `smtplib` requires that `SMTP.starttls()` is called before other commands are issued. Overrides `use_tls` as the preferred method for securing communications with the client.
`enforce_auth` | `SMTPD_ENFORCE_AUTH` | `False` | If set to true then the fixture refuses MAIL, RCPT, DATA commands until authentication is completed.
`ssl_cert_path` | `SMTPD_SSL_CERTS_PATH` | `./certs/` | The path to the key and certificate in PEM format for encryption with SSL/TLS or StartTLS.
`ssl_cert_files` | `SMTPD_SSL_CERT_FILE` and `SMTPD_SSL_KEY_FILE` | `("cert.pem", None)` | A tuple of the path for the certificate file and key file in PEM format. See [Resolving certificate and key paths](#resolving-certificate-and-key-paths) for more details.
### Resolving certificate and key paths
In order to resolve the certificate and key paths for the SSL/TLS context SMTPDFix does the following:
1. On initialization of a `smtpdfix.Config` the `ssl_cert_path` is set by the `SMTPD_SSL_CERTS_PATH` environment variable and the `ssl_cert_files` is set to a tuple of `(SMTPD_SSL_CERT_FILE and SMTPD_SSL_KEY_FILE)`. If the environment variables are not set the deafults are used.
2. If an SSL Context is needed, when the `smptdfix.AuthController` is initialized it will attempt to find the files in the following sequence for both the certificate file and the key file:
1. If the value in `ssl_cert_files` is `None` then `None` is returned. Setting the key file to be none assumes that it has been included in the certificate file.
2. If the value in `ssl_cert_files` is a valid path to a file then this is returned.
3. `ssl_cert_path` and the value from `ssl_cert_files` are joined and returned if it a valid path to a file.
4. A `FileNotFoundError` is raised.
An example, assuming that the certificate and key are written in a single PEM file located at `./certificates/localhost.cert.pem` would be:
```python
from smtplib import STMP_SSL
def test_custom_certificate(smtpd):
smtpd.config.ssl_cert_files = "./certificates/localhost.cert.pem"
smtpd.config.use_ssl = True
from_ = "from.addr@example.org"
to_ = "to.addr@example.org"
msg = (f"From: {from_}\r\n"
f"To: {to_}\r\n"
f"Subject: Foo\r\n\r\n"
f"Foo bar")
with SMTP_SSL(smtpd.hostname, smtpd.port) as client:
client.sendmail(from_addr, to_addrs, msg)
assert len(smtpd.messages) == 1
```
## Alternatives
Many libraries for sending email have built-in methods for testing and using these methods should generally be prefered over SMTPDFix. Some known solutions:
+ **fastapi-mail**: has a `record_messsages()` method to intercept the mail. Instructions on how to suppress the sending of mail and implement it can be seen at [https://sabuhish.github.io/fastapi-mail/example/#unittests-using-fastapimail](https://sabuhish.github.io/fastapi-mail/example/#unittests-using-fastapimail)
+ **flask-mail**: has a method to suppress sending and capture the email for testing purposes. [Instructions](https://pythonhosted.org/Flask-Mail/#unit-tests-and-suppressing-emails)
## Developing
To develop and test smtpdfix you will need to install [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) to run asynchronous tests, [isort](https://pycqa.github.io/isort/) to sort imports and [flake8](https://flake8.pycqa.org/en/latest/) to lint. To install in a virtual environment for development:
```bash
$ python -m venv venv
$ ./venv/scripts/activate
$ pip install -e .[dev]
```
Code is tested using tox:
```bash
$ tox
```
Quick tests can be handled by running pytest directly:
```bash
$ pytest -p no:smtpd --cov
```
Before submitting a pull request with your changes you should ensure that all imports are sorted and that the code passes linting with flake8.
```bash
$ isort .
$ flake8 .
```
We include a [pre-commit](https://pre-commit.com/) configuration file to automate checks and clean up imports before pushing code. In order to install pre-commit git hooks:
```bash
$ pip install pre-commit
$ pre-commit install
```
## Known Issues
+ Firewalls may interfere with the operation of the smtp server.
+ Authenticating with LOGIN and PLAIN mechanisms fails over TLS/SSL, but works with STARTTLS. [Issue #10](https://github.com/bebleo/smtpdfix/issues/10)
+ Currently no support for termination through signals. [Issue #4](https://github.com/bebleo/smtpdfix/issues/4)
+ If the fixture start exceeds the `ready_timeout` and aborts the host and port are not consistently released and subsequent uses may result in an error. [Issue #80](https://github.com/bebleo/smtpdfix/issues/80)
Written with ☕ and ❤ in Montreal, QC
%prep
%autosetup -n smtpdfix-0.5.0
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-smtpdfix -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Thu Jun 08 2023 Python_Bot <Python_Bot@openeuler.org> - 0.5.0-1
- Package Spec generated
|