2018-01-17 12:52:01 +00:00
|
|
|
import unittest
|
|
|
|
import unit
|
|
|
|
|
|
|
|
class TestUnitConfiguration(unit.TestUnitControl):
|
|
|
|
|
|
|
|
def setUpClass():
|
2018-02-14 14:14:16 +00:00
|
|
|
unit.TestUnit().check_modules('python')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-07-11 16:35:23 +00:00
|
|
|
def test_json_empty(self):
|
|
|
|
self.assertIn('error', self.conf(''), 'empty')
|
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_json_leading_zero(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf('00'), 'leading zero')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_json_unicode(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('success', self.conf(b"""
|
2018-01-24 12:43:04 +00:00
|
|
|
{
|
|
|
|
"ap\u0070": {
|
|
|
|
"type": "\u0070ython",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-24 12:43:04 +00:00
|
|
|
"path": "\u002Fapp",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
""", 'applications'), 'unicode')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-09-06 17:18:33 +00:00
|
|
|
self.assertDictEqual(self.conf_get('applications'), {
|
2018-02-26 17:18:24 +00:00
|
|
|
"app": {
|
|
|
|
"type": "python",
|
|
|
|
"processes": { "spare": 0 },
|
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}, 'unicode get')
|
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_json_unicode_2(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('success', self.conf({
|
|
|
|
"приложение": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-30 13:16:52 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
2018-01-24 12:43:04 +00:00
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
}, 'applications'), 'unicode 2')
|
2018-01-24 12:43:04 +00:00
|
|
|
|
2018-09-06 17:18:33 +00:00
|
|
|
self.assertIn('приложение', self.conf_get('applications'),
|
2018-02-26 17:18:24 +00:00
|
|
|
'unicode 2 get')
|
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_json_unicode_number(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf(b"""
|
2018-01-24 12:43:04 +00:00
|
|
|
{
|
|
|
|
"app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": \u0030 },
|
2018-01-24 12:43:04 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
""", 'applications'), 'unicode number')
|
2018-01-24 12:43:04 +00:00
|
|
|
|
|
|
|
def test_applications_open_brace(self):
|
2018-09-06 17:18:33 +00:00
|
|
|
self.assertIn('error', self.conf('{', 'applications'), 'open brace')
|
2018-01-24 12:43:04 +00:00
|
|
|
|
|
|
|
def test_applications_string(self):
|
2018-09-06 17:18:33 +00:00
|
|
|
self.assertIn('error', self.conf('"{}"', 'applications'), 'string')
|
2018-01-24 12:43:04 +00:00
|
|
|
|
|
|
|
def test_applications_type_only(self):
|
2018-03-06 13:58:47 +00:00
|
|
|
self.skip_alerts.extend([
|
|
|
|
r'python module is empty',
|
|
|
|
r'failed to apply new conf',
|
|
|
|
r'process \d+ exited on signal'
|
|
|
|
])
|
|
|
|
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf({
|
|
|
|
"app": {
|
|
|
|
"type": "python"
|
2018-01-17 12:52:01 +00:00
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
}, 'applications'), 'type only')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_applications_miss_quote(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf("""
|
2018-01-17 12:52:01 +00:00
|
|
|
{
|
|
|
|
app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-17 12:52:01 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
""", 'applications'), 'miss quote')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_applications_miss_colon(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf("""
|
2018-01-17 12:52:01 +00:00
|
|
|
{
|
|
|
|
"app" {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-17 12:52:01 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
""", 'applications'), 'miss colon')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_applications_miss_comma(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf("""
|
2018-01-17 12:52:01 +00:00
|
|
|
{
|
|
|
|
"app": {
|
|
|
|
"type": "python"
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-17 12:52:01 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
""", 'applications'), 'miss comma')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_applications_skip_spaces(self):
|
2018-09-06 17:18:33 +00:00
|
|
|
self.assertIn('success', self.conf(b'{ \n\r\t}', 'applications'),
|
2018-01-24 12:43:04 +00:00
|
|
|
'skip spaces')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_applications_relative_path(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('success', self.conf({
|
|
|
|
"app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-30 13:16:52 +00:00
|
|
|
"path": "../app",
|
|
|
|
"module": "wsgi"
|
2018-01-17 12:52:01 +00:00
|
|
|
}
|
2018-09-06 17:18:33 +00:00
|
|
|
}, 'applications'), 'relative path')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
@unittest.expectedFailure
|
|
|
|
def test_listeners_empty(self):
|
2018-03-06 13:58:47 +00:00
|
|
|
self.skip_sanitizer = True
|
|
|
|
self.skip_alerts.extend([
|
2018-04-02 15:37:45 +00:00
|
|
|
r'failed to apply previous configuration',
|
2018-03-06 13:58:47 +00:00
|
|
|
r'process \d+ exited on signal'
|
|
|
|
])
|
|
|
|
|
2018-09-06 17:18:33 +00:00
|
|
|
self.assertIn('error', self.conf({"*:7080":{}}, 'listeners'),
|
2018-01-24 12:43:04 +00:00
|
|
|
'listener empty')
|
|
|
|
|
|
|
|
def test_listeners_no_app(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf({"*:7080":{"application":"app"}},
|
2018-09-06 17:18:33 +00:00
|
|
|
'listeners'), 'listeners no app')
|
2018-01-24 12:43:04 +00:00
|
|
|
|
|
|
|
def test_listeners_wildcard(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('success', self.conf({
|
|
|
|
"listeners": {
|
|
|
|
"*:7080": {
|
|
|
|
"application":"app"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"applications": {
|
|
|
|
"app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-30 13:16:52 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
2018-01-17 12:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-30 13:16:52 +00:00
|
|
|
}), 'listeners wildcard')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_listeners_explicit(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('success', self.conf({
|
|
|
|
"listeners": {
|
|
|
|
"127.0.0.1:7080": {
|
|
|
|
"application":"app"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"applications": {
|
|
|
|
"app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-30 13:16:52 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
2018-01-17 12:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-30 13:16:52 +00:00
|
|
|
}), 'explicit')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_listeners_explicit_ipv6(self):
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('success', self.conf({
|
|
|
|
"listeners": {
|
|
|
|
"[::1]:7080": {
|
|
|
|
"application":"app"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"applications": {
|
|
|
|
"app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-30 13:16:52 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
2018-01-17 12:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-30 13:16:52 +00:00
|
|
|
}), 'explicit ipv6')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2018-01-24 12:43:04 +00:00
|
|
|
def test_listeners_no_port(self):
|
2018-03-06 13:58:47 +00:00
|
|
|
self.skip_alerts.extend([
|
|
|
|
r'invalid listener "127\.0\.0\.1"',
|
|
|
|
r'failed to apply new conf',
|
|
|
|
r'process \d+ exited on signal'
|
|
|
|
])
|
|
|
|
|
2018-01-30 13:16:52 +00:00
|
|
|
self.assertIn('error', self.conf({
|
|
|
|
"listeners": {
|
|
|
|
"127.0.0.1": {
|
|
|
|
"application":"app"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"applications": {
|
|
|
|
"app": {
|
|
|
|
"type": "python",
|
2018-01-29 13:17:36 +00:00
|
|
|
"processes": { "spare": 0 },
|
2018-01-30 13:16:52 +00:00
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
2018-01-17 12:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-30 13:16:52 +00:00
|
|
|
}), 'no port')
|
2018-01-17 12:52:01 +00:00
|
|
|
|
2019-01-28 14:17:23 +00:00
|
|
|
@unittest.expectedFailure
|
|
|
|
def test_json_application_name_large(self):
|
|
|
|
self.skip_alerts.append(r'epoll_ctl.+failed')
|
|
|
|
name = "X" * 1024 * 1024
|
|
|
|
|
|
|
|
self.assertIn('success', self.conf({
|
|
|
|
"listeners": {
|
|
|
|
"*:7080": {
|
|
|
|
"application": name
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"applications": {
|
|
|
|
name: {
|
|
|
|
"type": "python",
|
|
|
|
"processes": { "spare": 0 },
|
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
@unittest.expectedFailure
|
|
|
|
def test_json_application_many(self):
|
|
|
|
self.skip_alerts.extend([
|
|
|
|
r'eventfd.+failed',
|
|
|
|
r'failed to apply new conf'
|
|
|
|
])
|
2019-02-20 17:19:55 +00:00
|
|
|
apps = 999
|
2019-01-28 14:17:23 +00:00
|
|
|
|
|
|
|
conf = {
|
|
|
|
"applications":
|
|
|
|
{"app-" + str(a): {
|
|
|
|
"type": "python",
|
|
|
|
"processes": { "spare": 0 },
|
|
|
|
"path": "/app",
|
|
|
|
"module": "wsgi"
|
|
|
|
} for a in range(apps)
|
|
|
|
},
|
|
|
|
"listeners": {
|
2019-02-20 17:19:55 +00:00
|
|
|
"*:" + str(7000 + a): {
|
2019-01-28 14:17:23 +00:00
|
|
|
"application": "app-" + str(a)
|
|
|
|
} for a in range(apps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.assertIn('success', self.conf(conf))
|
|
|
|
|
2018-01-17 12:52:01 +00:00
|
|
|
if __name__ == '__main__':
|
2018-11-15 18:26:15 +00:00
|
|
|
TestUnitConfiguration.main()
|