2013-08-21 10:44:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from base import *
|
|
|
|
from requests import *
|
|
|
|
import time
|
2019-08-24 19:45:16 +00:00
|
|
|
from hashlib import md5
|
2013-08-21 10:44:11 +00:00
|
|
|
|
|
|
|
def securl(prefix, path, secret, tstamp = None):
|
|
|
|
if tstamp == None: tstamp = time.time()
|
|
|
|
tstamp = '%x' % int(tstamp)
|
|
|
|
md5content = secret + path + tstamp
|
|
|
|
if prefix[-1] != '/': prefix += '/'
|
2019-08-24 19:45:16 +00:00
|
|
|
return prefix + md5(md5content.encode('utf-8')).hexdigest() + '/' + tstamp + path
|
2013-08-21 10:44:11 +00:00
|
|
|
|
|
|
|
class SecdownloadFail(CurlRequest):
|
|
|
|
URL = "/test.txt"
|
|
|
|
EXPECT_RESPONSE_CODE = 403
|
|
|
|
|
|
|
|
class SecdownloadSuccess(CurlRequest):
|
|
|
|
EXPECT_RESPONSE_BODY = TEST_TXT
|
|
|
|
EXPECT_RESPONSE_CODE = 200
|
|
|
|
|
|
|
|
def Run(self):
|
|
|
|
self.URL = securl('/', '/test.txt', 'abc')
|
|
|
|
return super(SecdownloadSuccess, self).Run()
|
|
|
|
|
|
|
|
class SecdownloadGone(CurlRequest):
|
|
|
|
EXPECT_RESPONSE_CODE = 410
|
|
|
|
|
|
|
|
def Run(self):
|
|
|
|
self.URL = securl('/', '/test.txt', 'abc', time.time() - 800)
|
|
|
|
return super(SecdownloadGone, self).Run()
|
|
|
|
|
|
|
|
class Test(GroupTest):
|
|
|
|
group = [SecdownloadFail, SecdownloadSuccess, SecdownloadGone]
|
2013-09-10 10:08:44 +00:00
|
|
|
config = """
|
|
|
|
secdownload ( "prefix" => "/", "document-root" => var.default_docroot, "secret" => "abc", "timeout" => 600 );
|
|
|
|
"""
|
2014-06-06 09:57:41 +00:00
|
|
|
no_docroot = True
|