[asterisk-commits] asanders: testsuite/asterisk/trunk r6357 - in /asterisk/trunk/tests: ./ http_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jan 30 11:21:10 CST 2015
Author: asanders
Date: Fri Jan 30 11:21:05 2015
New Revision: 6357
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=6357
Log:
HTTP: For httpd server, need option to define server name for security purposes
Added a new config property [servername] to the http.conf file; updated the http server to use the new property when sending responses, for showing http status through the CLI and when reporting status through the 'httpstatus' webpage.
ASTERISK-24316 #close
Reported By: Andrew Nagy
Review: https://reviewboard.asterisk.org/r/4374/
Added:
asterisk/trunk/tests/http_server/
asterisk/trunk/tests/http_server/servername/
asterisk/trunk/tests/http_server/servername/configs/
asterisk/trunk/tests/http_server/servername/configs/ast1/
asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf (with props)
asterisk/trunk/tests/http_server/servername/configs/ast2/
asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf (with props)
asterisk/trunk/tests/http_server/servername/configs/ast3/
asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf (with props)
asterisk/trunk/tests/http_server/servername/run-test (with props)
asterisk/trunk/tests/http_server/servername/test-config.yaml (with props)
asterisk/trunk/tests/http_server/tests.yaml (with props)
Modified:
asterisk/trunk/tests/tests.yaml
Added: asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf?view=auto&rev=6357
==============================================================================
--- asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf (added)
+++ asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf Fri Jan 30 11:21:05 2015
@@ -1,0 +1,6 @@
+[general]
+servername=Peabody
+enabled=yes
+bindaddr=127.0.0.1
+bindport=8088
+enablestatic=yes
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast1/http.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf?view=auto&rev=6357
==============================================================================
--- asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf (added)
+++ asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf Fri Jan 30 11:21:05 2015
@@ -1,0 +1,5 @@
+[general]
+enabled=yes
+bindaddr=127.0.0.2
+bindport=8088
+enablestatic=yes
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast2/http.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf?view=auto&rev=6357
==============================================================================
--- asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf (added)
+++ asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf Fri Jan 30 11:21:05 2015
@@ -1,0 +1,6 @@
+[general]
+servername=
+enabled=yes
+bindaddr=127.0.0.3
+bindport=8088
+enablestatic=yes
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/http_server/servername/configs/ast3/http.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/http_server/servername/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/http_server/servername/run-test?view=auto&rev=6357
==============================================================================
--- asterisk/trunk/tests/http_server/servername/run-test (added)
+++ asterisk/trunk/tests/http_server/servername/run-test Fri Jan 30 11:21:05 2015
@@ -1,0 +1,98 @@
+#!/usr/bin/env python
+"""
+Copyright (C) 2015, Digium, Inc.
+Ashley Sanders <asanders at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+
+import logging
+import requests
+import sys
+
+sys.path.append("lib/python")
+
+from twisted.internet import reactor
+from asterisk.asterisk import Asterisk
+from asterisk.version import AsteriskVersion
+from asterisk.test_case import TestCase
+
+LOGGER = logging.getLogger(__name__)
+
+EXPECTED_NAMES = ["Peabody", "Asterisk/<version>", None]
+
+BASE_URL = "http://127.0.0.%d:8088/httpstatus"
+
+class HttpClientTest(TestCase):
+ """Responsible for making a request to the http-server and then parsing
+ response headers to verify that the value returned for 'Server' matches
+ the expected value."""
+
+ def __init__(self):
+ """Constructor."""
+
+ TestCase.__init__(self)
+ self.create_asterisk(3)
+
+ def run(self):
+ """Runs the test."""
+
+ TestCase.run(self)
+
+ for i in range(0, 3):
+ name = EXPECTED_NAMES[i]
+ if name is not None:
+ name = name.replace("<version>",
+ str(AsteriskVersion()).rstrip('\n'))
+
+ url = BASE_URL % (i+1)
+
+ self.run_scenario(url, name)
+ if self.passed == False:
+ break
+
+ LOGGER.debug("Stopping reactor...")
+ self.stop_reactor()
+
+ def run_scenario(self, url, expected_name):
+ """Runs an individual test scenario.
+
+ Keyword Arguments:
+ url -- The url to use for making the server request
+ expected_name -- The name that the server is expected to return
+ in its response headers
+ """
+
+ LOGGER.debug("Running %s", self)
+
+ LOGGER.debug("[url]: [%s]", url)
+ LOGGER.debug("[expected_name]: [%s]", expected_name)
+
+ resp = requests.get(url)
+ LOGGER.debug("[resp]: [%r]", resp)
+
+ server = resp.headers.get('Server')
+ LOGGER.debug("[server]: [%s]", server)
+
+ if server != expected_name:
+ LOGGER.debug("[%s] != [%s]", server, expected_name)
+ self.set_passed(False)
+ return
+
+ self.set_passed(True)
+ return
+
+def main():
+ """Main entry-point for the test."""
+
+ test = HttpClientTest()
+ reactor.run()
+
+ if test.passed:
+ return 0
+ return 1
+
+if __name__ == "__main__":
+ sys.exit(main() or 0)
Propchange: asterisk/trunk/tests/http_server/servername/run-test
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/http_server/servername/run-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: asterisk/trunk/tests/http_server/servername/run-test
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/http_server/servername/run-test
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/http_server/servername/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/http_server/servername/test-config.yaml?view=auto&rev=6357
==============================================================================
--- asterisk/trunk/tests/http_server/servername/test-config.yaml (added)
+++ asterisk/trunk/tests/http_server/servername/test-config.yaml Fri Jan 30 11:21:05 2015
@@ -1,0 +1,20 @@
+testinfo:
+ summary: Tests the http-server 'servername' property.
+ description: |
+ This test connects as a client to a running instance of the asterisk
+ http-server. After making an arbitrary request, the test parses the
+ response headers to verify the value returned in the 'Server' header
+ matches the expected value. The expected values that are tested follow
+ the three possible logic paths: the default value when nothing is
+ provided through configuration, a configured value that is non-empty
+ and a configured value that is empty/null.
+
+properties:
+ minversion: '13.2.0'
+ dependencies:
+ - python : twisted
+ - python : starpy
+ - python : requests
+ tags:
+ - HTTP_SERVER
+ - configuration
Propchange: asterisk/trunk/tests/http_server/servername/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/http_server/servername/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/http_server/servername/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/http_server/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/http_server/tests.yaml?view=auto&rev=6357
==============================================================================
--- asterisk/trunk/tests/http_server/tests.yaml (added)
+++ asterisk/trunk/tests/http_server/tests.yaml Fri Jan 30 11:21:05 2015
@@ -1,0 +1,3 @@
+# Enter tests here in the order they should be considered for execution:
+tests:
+ - test: 'servername'
Propchange: asterisk/trunk/tests/http_server/tests.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/http_server/tests.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/http_server/tests.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/tests/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/tests.yaml?view=diff&rev=6357&r1=6356&r2=6357
==============================================================================
--- asterisk/trunk/tests/tests.yaml (original)
+++ asterisk/trunk/tests/tests.yaml Fri Jan 30 11:21:05 2015
@@ -31,3 +31,4 @@
- dir: 'rest_api'
- dir: 'hep'
- dir: 'realtime'
+ - dir: 'http_server'
More information about the asterisk-commits
mailing list