maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

  1//go:build integration
  2// +build integration
  3
  4/*
  5Maddy Mail Server - Composable all-in-one email server.
  6Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
  7
  8This program is free software: you can redistribute it and/or modify
  9it under the terms of the GNU General Public License as published by
 10the Free Software Foundation, either version 3 of the License, or
 11(at your option) any later version.
 12
 13This program is distributed in the hope that it will be useful,
 14but WITHOUT ANY WARRANTY; without even the implied warranty of
 15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16GNU General Public License for more details.
 17
 18You should have received a copy of the GNU General Public License
 19along with this program.  If not, see <https://www.gnu.org/licenses/>.
 20*/
 21
 22package tests_test
 23
 24import (
 25	"testing"
 26
 27	"github.com/foxcpp/maddy/tests"
 28)
 29
 30func TestConcurrencyLimit(tt *testing.T) {
 31	tt.Parallel()
 32	t := tests.NewT(tt)
 33	t.DNS(nil)
 34	t.Port("smtp")
 35	t.Config(`
 36		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
 37			hostname mx.maddy.test
 38			tls off
 39
 40			defer_sender_reject no
 41			limits {
 42				all concurrency 1
 43			}
 44
 45			deliver_to dummy
 46		}
 47	`)
 48	t.Run(1)
 49	defer t.Close()
 50
 51	c1 := t.Conn("smtp")
 52	defer c1.Close()
 53	c1.SMTPNegotation("localhost", nil, nil)
 54	c1.Writeln("MAIL FROM:<testing@maddy.test>")
 55	c1.ExpectPattern("250 *")
 56	// Down on semaphore.
 57
 58	c2 := t.Conn("smtp")
 59	defer c2.Close()
 60	c2.SMTPNegotation("localhost", nil, nil)
 61	c1.Writeln("MAIL FROM:<testing@maddy.test>")
 62	// Temporary error due to lock timeout.
 63	c1.ExpectPattern("451 *")
 64}
 65
 66func TestPerIPConcurrency(tt *testing.T) {
 67	tt.Parallel()
 68	t := tests.NewT(tt)
 69	t.DNS(nil)
 70	t.Port("smtp")
 71	t.Config(`
 72		smtp tcp://127.0.0.1:{env:TEST_PORT_smtp} {
 73			hostname mx.maddy.test
 74			tls off
 75
 76			defer_sender_reject no
 77			limits {
 78				ip concurrency 1
 79			}
 80
 81			deliver_to dummy
 82		}
 83	`)
 84	t.Run(1)
 85	defer t.Close()
 86
 87	c1 := t.Conn("smtp")
 88	defer c1.Close()
 89	c1.SMTPNegotation("localhost", nil, nil)
 90	c1.Writeln("MAIL FROM:<testing@maddy.test>")
 91	c1.ExpectPattern("250 *")
 92	// Down on semaphore.
 93
 94	c3 := t.Conn4("127.0.0.2", "smtp")
 95	defer c3.Close()
 96	c3.SMTPNegotation("localhost", nil, nil)
 97	c3.Writeln("MAIL FROM:<testing@maddy.test>")
 98	c3.ExpectPattern("250 *")
 99	// Down on semaphore (different IP).
100
101	c2 := t.Conn("smtp")
102	defer c2.Close()
103	c2.SMTPNegotation("localhost", nil, nil)
104	c1.Writeln("MAIL FROM:<testing@maddy.test>")
105	// Temporary error due to lock timeout.
106	c1.ExpectPattern("451 *")
107}