diff --git a/src/bin/shell/kea-shell.py b/src/bin/shell/kea-shell.py index ebc1833d6913199e9adc77cdfbdece36b77b58a4..7eba7ea201f0b32d0bf84a15ecc509185749d515 100644 --- a/src/bin/shell/kea-shell.py +++ b/src/bin/shell/kea-shell.py @@ -55,6 +55,7 @@ params.command = cmd_args.command params.http_host = cmd_args.host params.http_port = cmd_args.port params.timeout = cmd_args.timeout +params.version = VERSION params.generateBody() params.generateHeaders() diff --git a/src/bin/shell/kea_conn.py b/src/bin/shell/kea_conn.py index c41e739a63873b37ba11d31243236d9e4f1d8e52..e00abd2ffbcbf87b6ec3cd52689e7316d339745e 100644 --- a/src/bin/shell/kea_conn.py +++ b/src/bin/shell/kea_conn.py @@ -10,6 +10,7 @@ # - command - specifies the command to send (e.g. list-commands) # - timeout - timeout (in ms) # - headers - extra HTTP headers may be added here +# - version - version to be reported in HTTP header class CARequest: path = '/' http_host = '' @@ -18,6 +19,7 @@ class CARequest: timeout = 0 params = '' headers = {} + version = "" # Generates the content, out of specified command line # and optional content. @@ -34,7 +36,7 @@ class CARequest: # In particular, this method generates Content-Length and its value. def generateHeaders(self): self.headers['Content-Type'] = 'application/json' - self.headers['User-Agent'] = 'Kea-shell/0.1' + self.headers['User-Agent'] = "Kea-shell/%s"%(self.version) self.headers['Accept'] = '*/*' self.headers['Content-Length'] = "%d"%(len(self.content)) diff --git a/src/bin/shell/tests/Makefile.am b/src/bin/shell/tests/Makefile.am index 89c9984c9fad45b528767dfcbf858ad00c5c7834..20299d065386b194d6f5010bef26d353870b2e84 100644 --- a/src/bin/shell/tests/Makefile.am +++ b/src/bin/shell/tests/Makefile.am @@ -1,4 +1,4 @@ -PYTESTS = kea-shell_unittest.py +PYTESTS = shell_unittest.py SHTESTS = shell_process_tests.sh @@ -6,16 +6,16 @@ noinst_SCRIPTS = $(PYTESTS) shell_process_tests.sh EXTRA_DIST = testdata/plugins/testplugin.py # test using command-line arguments, so use check-local target instead of TESTS -check-local: check-local-shell check-local-python +check-local: check-shell check-python -check-local-python: +check-python: @for pytest in $(PYTESTS) ; do \ echo Running python test: $$pytest ; \ chmod +x $(abs_builddir)/$$pytest ; \ PYTHONPATH=$(PYTHONPATH):$(abs_top_builddir)/src/bin/shell python $(abs_builddir)/$$pytest || exit ; \ done -check-local-shell: +check-shell: @for shtest in $(SHTESTS) ; do \ echo Running shell test: $$shtest ; \ export KEA_LOCKFILE_DIR=$(abs_top_builddir); \ diff --git a/src/bin/shell/tests/kea-shell_unittest.py b/src/bin/shell/tests/shell_unittest.py similarity index 90% rename from src/bin/shell/tests/kea-shell_unittest.py rename to src/bin/shell/tests/shell_unittest.py index 77a6333124632b45a02df15b3a4b6b947a40662f..c1ddc2759abedddb197354bcbcf0ebd09033ce70 100755 --- a/src/bin/shell/tests/kea-shell_unittest.py +++ b/src/bin/shell/tests/shell_unittest.py @@ -84,6 +84,15 @@ class CARequestUnitTest(unittest.TestCase): self.assertTrue(self.checkHeader(x.headers, 'Content-Length', str(len(x.content)))) + def test_headerVersion(self): + """ + This test checks if the version reported in HTTP headers is generated properly. + """ + x = CARequest() + x.version = "1.2.3" + x.generateHeaders() + self.assertTrue(self.checkHeader(x.headers, 'User-Agent', 'Kea-shell/1.2.3')) + def tearDown(self): """ This method is called after each test. Currently it does nothing.