From: Guillaume Pannatier Date: Thu, 5 May 2016 14:42:18 +0000 (+0200) Subject: rlm_python tests X-Git-Tag: release_3_0_12~139^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1601%2Fhead;p=thirdparty%2Ffreeradius-server.git rlm_python tests --- diff --git a/src/tests/modules/python/.gitignore b/src/tests/modules/python/.gitignore new file mode 100644 index 00000000000..0d20b6487c6 --- /dev/null +++ b/src/tests/modules/python/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/src/tests/modules/python/all.mk b/src/tests/modules/python/all.mk new file mode 100644 index 00000000000..c4451aae80c --- /dev/null +++ b/src/tests/modules/python/all.mk @@ -0,0 +1,9 @@ +# +# Test the "files" module +# + +PYTHONPATH := $(top_builddir)/src/tests/modules/python/ +export PYTHONPATH + +# MODULE.test is the main target for this module. +python.test: \ No newline at end of file diff --git a/src/tests/modules/python/auth_cext_compat.attrs b/src/tests/modules/python/auth_cext_compat.attrs new file mode 100644 index 00000000000..b2b037f71b6 --- /dev/null +++ b/src/tests/modules/python/auth_cext_compat.attrs @@ -0,0 +1,10 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept \ No newline at end of file diff --git a/src/tests/modules/python/auth_cext_compat.unlang b/src/tests/modules/python/auth_cext_compat.unlang new file mode 100644 index 00000000000..d8ed43cf829 --- /dev/null +++ b/src/tests/modules/python/auth_cext_compat.unlang @@ -0,0 +1,31 @@ +# This module is cext_compat and should work +pmod4_cextcompat +if (!noop) { + test_fail +} else { + test_pass +} + +# This module share the main interpreter with pmod4_cextcompat. shared_attribute should be defined +pmod5_cextcompat +if (!ok) { + test_fail +} else { + test_pass +} + +# This module has it's own SubInterpreter. shared_attribute shouldn't be defined +pmod4_not_cextcompat +if (!noop) { + test_fail +} else { + test_pass +} + +# This module has it's own SubInterpreter. shared_attribute shouldn't be defined +pmod5_not_cextcompat +if (!noop) { + test_fail +} else { + test_pass +} \ No newline at end of file diff --git a/src/tests/modules/python/auth_configured_module.attrs b/src/tests/modules/python/auth_configured_module.attrs new file mode 100644 index 00000000000..b2b037f71b6 --- /dev/null +++ b/src/tests/modules/python/auth_configured_module.attrs @@ -0,0 +1,10 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept \ No newline at end of file diff --git a/src/tests/modules/python/auth_configured_module.unlang b/src/tests/modules/python/auth_configured_module.unlang new file mode 100644 index 00000000000..848bf795fea --- /dev/null +++ b/src/tests/modules/python/auth_configured_module.unlang @@ -0,0 +1,6 @@ +pmod6_configured +if (!ok) { + test_fail +} else { + test_pass +} \ No newline at end of file diff --git a/src/tests/modules/python/auth_multi_inst.attrs b/src/tests/modules/python/auth_multi_inst.attrs new file mode 100644 index 00000000000..b2b037f71b6 --- /dev/null +++ b/src/tests/modules/python/auth_multi_inst.attrs @@ -0,0 +1,10 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept \ No newline at end of file diff --git a/src/tests/modules/python/auth_multi_inst.unlang b/src/tests/modules/python/auth_multi_inst.unlang new file mode 100644 index 00000000000..56669269e0e --- /dev/null +++ b/src/tests/modules/python/auth_multi_inst.unlang @@ -0,0 +1,15 @@ +# Call the second configured module firstly should work +pmod2 +if (!ok) { + test_fail +} else { + test_pass +} + +# Call the first configured module secondly +pmod1 +if (!noop) { + test_fail +} else { + test_pass +} \ No newline at end of file diff --git a/src/tests/modules/python/auth_with_tls.attrs b/src/tests/modules/python/auth_with_tls.attrs new file mode 100644 index 00000000000..b2b037f71b6 --- /dev/null +++ b/src/tests/modules/python/auth_with_tls.attrs @@ -0,0 +1,10 @@ +# +# Input packet +# +User-Name = "bob" +User-Password = "hello" + +# +# Expected answer +# +Response-Packet-Type == Access-Accept \ No newline at end of file diff --git a/src/tests/modules/python/auth_with_tls.unlang b/src/tests/modules/python/auth_with_tls.unlang new file mode 100644 index 00000000000..8baaac399d2 --- /dev/null +++ b/src/tests/modules/python/auth_with_tls.unlang @@ -0,0 +1,46 @@ +# The first call on pmod1 should store var "tls" in a thread local storage and return noop +pmod1 +if (!noop) { + test_fail +} else { + test_pass +} + +# Simply call another second module +pmod2 +if (!ok) { + test_fail +} else { + test_pass +} + +# The second call on pmod1 should return OK because "tls" is set +pmod1 +if (!ok) { + test_fail +} else { + test_pass +} + +# Calling another python module configured with mod1.py should be in it's own context and return NOOP on first call +pmod3_withmod1 +if (!noop) { + test_fail +} else { + test_pass +} + +# Should return "OK" on subsequent calls +pmod3_withmod1 +if (!ok) { + test_fail +} else { + test_pass +} + +pmod3_withmod1 +if (!ok) { + test_fail +} else { + test_pass +} \ No newline at end of file diff --git a/src/tests/modules/python/mod1.py b/src/tests/modules/python/mod1.py new file mode 100644 index 00000000000..f2b2a5faa01 --- /dev/null +++ b/src/tests/modules/python/mod1.py @@ -0,0 +1,12 @@ +import radiusd +import threading + +local = threading.local() + +def authorize(p): + global local + if hasattr(local, 'tls'): + return radiusd.RLM_MODULE_OK + else: + local.tls = True + return radiusd.RLM_MODULE_NOOP \ No newline at end of file diff --git a/src/tests/modules/python/mod1.pyc b/src/tests/modules/python/mod1.pyc deleted file mode 100644 index b95c1a0975c..00000000000 Binary files a/src/tests/modules/python/mod1.pyc and /dev/null differ diff --git a/src/tests/modules/python/mod2.py b/src/tests/modules/python/mod2.py new file mode 100644 index 00000000000..9089d1aa7fb --- /dev/null +++ b/src/tests/modules/python/mod2.py @@ -0,0 +1,4 @@ +import radiusd + +def authorize(p): + return radiusd.RLM_MODULE_OK \ No newline at end of file diff --git a/src/tests/modules/python/mod2.pyc b/src/tests/modules/python/mod2.pyc deleted file mode 100644 index c1d055d789c..00000000000 Binary files a/src/tests/modules/python/mod2.pyc and /dev/null differ diff --git a/src/tests/modules/python/mod3.py b/src/tests/modules/python/mod3.py new file mode 100644 index 00000000000..f84cec21fe5 --- /dev/null +++ b/src/tests/modules/python/mod3.py @@ -0,0 +1,10 @@ +import radiusd +import shared + +def authorize(p): + if not hasattr(shared, 'shared_attribute'): + setattr(shared, 'shared_attribute', True) + return radiusd.RLM_MODULE_NOOP + + return radiusd.RLM_MODULE_OK + diff --git a/src/tests/modules/python/mod4.py b/src/tests/modules/python/mod4.py new file mode 100644 index 00000000000..e95e6cfa34a --- /dev/null +++ b/src/tests/modules/python/mod4.py @@ -0,0 +1,7 @@ +import radiusd + +def authorize(p): + if radiusd.config.get('a_param'): + return radiusd.RLM_MODULE_OK + + return radiusd.RLM_MODULE_NOOP \ No newline at end of file diff --git a/src/tests/modules/python/module.conf b/src/tests/modules/python/module.conf new file mode 100644 index 00000000000..ed422dc56ff --- /dev/null +++ b/src/tests/modules/python/module.conf @@ -0,0 +1,75 @@ +python pmod1 { + module = 'mod1' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = false +} + +python pmod2 { + module = 'mod2' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = false +} + +python pmod3_withmod1 { + module = 'mod1' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = false +} + +python pmod4_cextcompat { + module = 'mod3' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = true +} + +python pmod5_cextcompat { + module = 'mod3' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = true +} + +python pmod4_not_cextcompat { + module = 'mod3' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = false +} + +python pmod5_not_cextcompat { + module = 'mod3' + + mod_authorize = ${.module} + func_authorize = authorize + + cext_compat = false +} + +python pmod6_configured { + module = 'mod4' + + mod_authorize = ${.module} + func_authorize = authorize + + config { + a_param = "a_value" + } + + cext_compat = false +} \ No newline at end of file diff --git a/src/tests/modules/python/shared.py b/src/tests/modules/python/shared.py new file mode 100644 index 00000000000..2ff281c87c8 --- /dev/null +++ b/src/tests/modules/python/shared.py @@ -0,0 +1 @@ +dummy_attribute = 0 \ No newline at end of file