コード例 #1
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def setUp(self):
		self.rpc_test_double = "{0}".format(random_string(40))
		self.rpc_test_datetime = "{0}".format(random_string(40))
		self.rpc_test_throw_exception = "{0}".format(random_string(40))
		AdvancedHTTPServerRegisterPath("/{0}".format(self.rpc_test_double), self.handler_class.__name__, is_rpc=True)(self._rpc_test_double_handler)
		AdvancedHTTPServerRegisterPath("/{0}".format(self.rpc_test_datetime), self.handler_class.__name__, is_rpc=True)(self._rpc_test_datetime_handler)
		AdvancedHTTPServerRegisterPath("/{0}".format(self.rpc_test_throw_exception), self.handler_class.__name__, is_rpc=True)(self._rpc_test_throw_exception)
		super(AdvancedHTTPServerTests, self).setUp()
コード例 #2
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def test_authentication_hash(self):
		username = random_string(8)
		password = random_string(12)
		password_hash = hashlib.new('md5', password.encode('utf-8')).hexdigest()
		self.server.auth_add_creds(username, password_hash, 'md5')
		self._test_authentication(username, password)
		password_hash = hashlib.new('md5', password.encode('utf-8')).digest()
		self.server.auth_add_creds(username, password_hash, 'md5')
		self._test_authentication(username, password)
コード例 #3
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def test_rpc_hmac(self):
		hmac = random_string(16)
		self.server.rpc_hmac_key = hmac
		rpc = self.build_rpc_client()
		self.assertRaisesRegex(AdvancedHTTPServerRPCError, r'the server responded with 401 \'Unauthorized\'', self.run_rpc_tests, rpc)
		rpc = self.build_rpc_client(hmac_key=random_string(16))
		self.assertRaisesRegex(AdvancedHTTPServerRPCError, r'the server responded with 401 \'Unauthorized\'', self.run_rpc_tests, rpc)
		rpc = self.build_rpc_client(hmac_key=hmac)
		self.run_rpc_tests(rpc)
コード例 #4
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def test_rpc_authentication(self):
		username = random_string(8)
		password = random_string(12)
		self.server.auth_add_creds(username, password)
		rpc = self.build_rpc_client()
		self.assertRaisesRegex(AdvancedHTTPServerRPCError, r'the server responded with 401 \'Unauthorized\'', self.run_rpc_tests, rpc)
		rpc = self.build_rpc_client(username=username, password=random_string(12))
		self.assertRaisesRegex(AdvancedHTTPServerRPCError, r'the server responded with 401 \'Unauthorized\'', self.run_rpc_tests, rpc)
		rpc = self.build_rpc_client(username=username, password=password)
		self.run_rpc_tests(rpc)
コード例 #5
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def test_authentication_hash(self):
     username = random_string(8)
     password = random_string(12)
     password_hash = hashlib.new('md5',
                                 password.encode('utf-8')).hexdigest()
     self.server.auth_add_creds(username, password_hash, 'md5')
     self._test_authentication(username, password)
     password_hash = hashlib.new('md5', password.encode('utf-8')).digest()
     self.server.auth_add_creds(username, password_hash, 'md5')
     self._test_authentication(username, password)
コード例 #6
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def test_authentication_bad_credentials(self):
     self.server.auth_add_creds(random_string(8), random_string(12))
     auth_headers = {
         'Authorization':
         'Basic ' + base64.b64encode("{0}:{1}".format(
             random_string(8),
             random_string(12)).encode('utf-8')).decode('utf-8')
     }
     response = self.http_request(self.test_resource,
                                  'GET',
                                  headers=auth_headers)
     self.assertHTTPStatus(response, 401)
コード例 #7
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def test_rpc_hmac(self):
     hmac = random_string(16)
     self.server.rpc_hmac_key = hmac
     rpc = self.build_rpc_client()
     self.assertRaisesRegex(
         AdvancedHTTPServerRPCError,
         r'the server responded with 401 \'Unauthorized\'',
         self.run_rpc_tests, rpc)
     rpc = self.build_rpc_client(hmac_key=random_string(16))
     self.assertRaisesRegex(
         AdvancedHTTPServerRPCError,
         r'the server responded with 401 \'Unauthorized\'',
         self.run_rpc_tests, rpc)
     rpc = self.build_rpc_client(hmac_key=hmac)
     self.run_rpc_tests(rpc)
コード例 #8
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def test_rpc_authentication(self):
     username = random_string(8)
     password = random_string(12)
     self.server.auth_add_creds(username, password)
     rpc = self.build_rpc_client()
     self.assertRaisesRegex(
         AdvancedHTTPServerRPCError,
         r'the server responded with 401 \'Unauthorized\'',
         self.run_rpc_tests, rpc)
     rpc = self.build_rpc_client(username=username,
                                 password=random_string(12))
     self.assertRaisesRegex(
         AdvancedHTTPServerRPCError,
         r'the server responded with 401 \'Unauthorized\'',
         self.run_rpc_tests, rpc)
     rpc = self.build_rpc_client(username=username, password=password)
     self.run_rpc_tests(rpc)
コード例 #9
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def setUp(self):
     self.rpc_test_double = "{0}".format(random_string(40))
     self.rpc_test_datetime = "{0}".format(random_string(40))
     self.rpc_test_throw_exception = "{0}".format(random_string(40))
     AdvancedHTTPServerRegisterPath("/{0}".format(self.rpc_test_double),
                                    self.handler_class.__name__,
                                    is_rpc=True)(
                                        self._rpc_test_double_handler)
     AdvancedHTTPServerRegisterPath("/{0}".format(self.rpc_test_datetime),
                                    self.handler_class.__name__,
                                    is_rpc=True)(
                                        self._rpc_test_datetime_handler)
     AdvancedHTTPServerRegisterPath(
         "/{0}".format(self.rpc_test_throw_exception),
         self.handler_class.__name__,
         is_rpc=True)(self._rpc_test_throw_exception)
     super(AdvancedHTTPServerTests, self).setUp()
コード例 #10
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def test_fake_resource(self):
		response = self.http_request('/' + random_string(30), 'GET')
		self.assertHTTPStatus(response, 404)
		response = self.http_request('/' + random_string(30), 'POST')
		self.assertHTTPStatus(response, 404)
コード例 #11
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def test_authentication_bad_credentials(self):
		self.server.auth_add_creds(random_string(8), random_string(12))
		auth_headers = {'Authorization': 'Basic ' + base64.b64encode("{0}:{1}".format(random_string(8), random_string(12)).encode('utf-8')).decode('utf-8')}
		response = self.http_request(self.test_resource, 'GET', headers=auth_headers)
		self.assertHTTPStatus(response, 401)
コード例 #12
0
ファイル: tests.py プロジェクト: 0x90shell/AdvancedHTTPServer
	def test_authentication_plain(self):
		username = random_string(8)
		password = random_string(12)
		self.server.auth_add_creds(username, password)
		self._test_authentication(username, password)
コード例 #13
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def test_fake_resource(self):
     response = self.http_request('/' + random_string(30), 'GET')
     self.assertHTTPStatus(response, 404)
     response = self.http_request('/' + random_string(30), 'POST')
     self.assertHTTPStatus(response, 404)
コード例 #14
0
ファイル: tests.py プロジェクト: kuzmeech/AdvancedHTTPServer
 def test_authentication_plain(self):
     username = random_string(8)
     password = random_string(12)
     self.server.auth_add_creds(username, password)
     self._test_authentication(username, password)