From dc4b76ab631550e883df5cba2c45141a7825c186 Mon Sep 17 00:00:00 2001 From: Guillaume Pannatier Date: Thu, 5 May 2016 16:42:18 +0200 Subject: [PATCH] rlm_python tests --- src/tests/modules/python/.gitignore | 1 + src/tests/modules/python/all.mk | 9 +++ .../modules/python/auth_cext_compat.attrs | 10 +++ .../modules/python/auth_cext_compat.unlang | 31 ++++++++ .../python/auth_configured_module.attrs | 10 +++ .../python/auth_configured_module.unlang | 6 ++ .../modules/python/auth_multi_inst.attrs | 10 +++ .../modules/python/auth_multi_inst.unlang | 15 ++++ src/tests/modules/python/auth_with_tls.attrs | 10 +++ src/tests/modules/python/auth_with_tls.unlang | 46 +++++++++++ src/tests/modules/python/mod1.py | 12 +++ src/tests/modules/python/mod1.pyc | Bin 519 -> 0 bytes src/tests/modules/python/mod2.py | 4 + src/tests/modules/python/mod2.pyc | Bin 380 -> 0 bytes src/tests/modules/python/mod3.py | 10 +++ src/tests/modules/python/mod4.py | 7 ++ src/tests/modules/python/module.conf | 75 ++++++++++++++++++ src/tests/modules/python/shared.py | 1 + 18 files changed, 257 insertions(+) create mode 100644 src/tests/modules/python/.gitignore create mode 100644 src/tests/modules/python/all.mk create mode 100644 src/tests/modules/python/auth_cext_compat.attrs create mode 100644 src/tests/modules/python/auth_cext_compat.unlang create mode 100644 src/tests/modules/python/auth_configured_module.attrs create mode 100644 src/tests/modules/python/auth_configured_module.unlang create mode 100644 src/tests/modules/python/auth_multi_inst.attrs create mode 100644 src/tests/modules/python/auth_multi_inst.unlang create mode 100644 src/tests/modules/python/auth_with_tls.attrs create mode 100644 src/tests/modules/python/auth_with_tls.unlang create mode 100644 src/tests/modules/python/mod1.py delete mode 100644 src/tests/modules/python/mod1.pyc create mode 100644 src/tests/modules/python/mod2.py delete mode 100644 src/tests/modules/python/mod2.pyc create mode 100644 src/tests/modules/python/mod3.py create mode 100644 src/tests/modules/python/mod4.py create mode 100644 src/tests/modules/python/module.conf create mode 100644 src/tests/modules/python/shared.py 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 b95c1a0975ca9aa5b2fd5e047dac304e7af0d67a..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc-jL100001 literal 519 zc-p;CO-lnY5S?UOv{LclKM;kz)c66OL#vp!y2Q%zr z*qLiR`@Pp=uuWC-JjR?seWpyQyHYzYJhcvdo}^x*5iCU4RzK_52nTW~5QP&eKfMs` zne>JLNhgTWXgtwNn^rj#j`RvjOU79=K>C0Hm}I7+kmVP^@L=(z2~+KWSe@IfI2S`&u&&{65lsQL0oPC 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 -- 2.47.3