@@ -2271,5 +2271,135 @@ def test_delete_bucket_style(self, do_request):
22712271
22722272 self .assertRequest (req_info , request_text )
22732273
2274+
2275+ @patch ('oss2.Session.do_request' )
2276+ def test_put_black_referer (self , do_request ):
2277+ from oss2 .models import BucketReferer
2278+
2279+ request_text = '''PUT /?referer= HTTP/1.1
2280+ Host: ming-oss-share.oss-cn-hangzhou.aliyuncs.com
2281+ Accept-Encoding: identity
2282+ Connection: keep-alive
2283+ Content-Length: 249
2284+ date: Sat, 12 Dec 2015 00:35:46 GMT
2285+ User-Agent: aliyun-sdk-python/2.0.2(Windows/7/;3.3.3)
2286+ Accept: */*
2287+ authorization: OSS ZCDmm7TPZKHtx77j:Kq2RS9nmT44C1opXGbcLzNdTt1A=
2288+
2289+ <RefererConfiguration>
2290+ <AllowEmptyReferer>true</AllowEmptyReferer>
2291+ <RefererList>
2292+ <Referer>http://hello.com</Referer>
2293+ <Referer>mibrowser:home</Referer>
2294+ <Referer>{0}</Referer>
2295+ </RefererList>
2296+ <AllowTruncateQueryString>true</AllowTruncateQueryString>
2297+ <RefererBlacklist>
2298+ <Referer>http://hello2.com</Referer>
2299+ <Referer>mibrowser2:home</Referer>
2300+ <Referer>{1}</Referer>
2301+ </RefererBlacklist>
2302+ </RefererConfiguration>'''
2303+
2304+ response_text = '''HTTP/1.1 200 OK
2305+ Server: AliyunOSS
2306+ Date: Sat, 12 Dec 2015 00:35:46 GMT
2307+ Content-Length: 0
2308+ Connection: keep-alive
2309+ x-oss-request-id: 566B6BE244ABFA2608E5A8AD'''
2310+
2311+ req_info = mock_response (do_request , response_text )
2312+
2313+ bucket ().put_bucket_referer (BucketReferer (True , ['http://hello.com' , 'mibrowser:home' , '阿里巴巴' ], True , ['http://hello2.com' , 'mibrowser2:home' , '阿里巴巴2' ]))
2314+
2315+ self .assertRequest (req_info , request_text .format ('阿里巴巴' , '阿里巴巴2' ))
2316+
2317+
2318+ @patch ('oss2.Session.do_request' )
2319+ def test_get_black_referer (self , do_request ):
2320+ request_text = '''GET /?referer= HTTP/1.1
2321+ Host: ming-oss-share.oss-cn-hangzhou.aliyuncs.com
2322+ Accept-Encoding: identity
2323+ Connection: keep-alive
2324+ date: Sat, 12 Dec 2015 00:35:47 GMT
2325+ User-Agent: aliyun-sdk-python/2.0.2(Windows/7/;3.3.3)
2326+ Accept: */*
2327+ authorization: OSS ZCDmm7TPZKHtx77j:nWqS3JExf/lsVxm+Sbxbg2cQyrc='''
2328+
2329+ response_text = '''HTTP/1.1 200 OK
2330+ Server: AliyunOSS
2331+ Date: Sat, 12 Dec 2015 00:35:47 GMT
2332+ Content-Type: application/xml
2333+ Content-Length: 319
2334+ Connection: keep-alive
2335+ x-oss-request-id: 566B6BE3BCD1D4FE65D449A2
2336+
2337+ <?xml version="1.0" encoding="UTF-8"?>
2338+ <RefererConfiguration>
2339+ <AllowEmptyReferer>true</AllowEmptyReferer>
2340+ <AllowTruncateQueryString>false</AllowTruncateQueryString>
2341+ <RefererList>
2342+ <Referer>http://hello.com</Referer>
2343+ <Referer>mibrowser:home</Referer>
2344+ <Referer>{0}</Referer>
2345+ </RefererList>
2346+ <RefererBlacklist>
2347+ <Referer>http://www.aliyun.com</Referer>
2348+ <Referer>mibrowser:home.com</Referer>
2349+ </RefererBlacklist>
2350+ </RefererConfiguration>''' .format ('阿里巴巴' )
2351+
2352+ req_info = mock_response (do_request , response_text )
2353+
2354+ result = bucket ().get_bucket_referer ()
2355+
2356+ self .assertRequest (req_info , request_text )
2357+
2358+ self .assertEqual (result .allow_empty_referer , True )
2359+ self .assertEqual (result .allow_truncate_query_string , False )
2360+ self .assertSortedListEqual (result .referers , ['http://hello.com' , 'mibrowser:home' , '阿里巴巴' ])
2361+ self .assertSortedListEqual (result .black_referers , ['http://www.aliyun.com' , 'mibrowser:home.com' ])
2362+
2363+
2364+ @patch ('oss2.Session.do_request' )
2365+ def test_get_black_referer2 (self , do_request ):
2366+ request_text = '''GET /?referer= HTTP/1.1
2367+ Host: ming-oss-share.oss-cn-hangzhou.aliyuncs.com
2368+ Accept-Encoding: identity
2369+ Connection: keep-alive
2370+ date: Sat, 12 Dec 2015 00:35:47 GMT
2371+ User-Agent: aliyun-sdk-python/2.0.2(Windows/7/;3.3.3)
2372+ Accept: */*
2373+ authorization: OSS ZCDmm7TPZKHtx77j:nWqS3JExf/lsVxm+Sbxbg2cQyrc='''
2374+
2375+ response_text = '''HTTP/1.1 200 OK
2376+ Server: AliyunOSS
2377+ Date: Sat, 12 Dec 2015 00:35:47 GMT
2378+ Content-Type: application/xml
2379+ Content-Length: 319
2380+ Connection: keep-alive
2381+ x-oss-request-id: 566B6BE3BCD1D4FE65D449A2
2382+
2383+ <?xml version="1.0" encoding="UTF-8"?>
2384+ <RefererConfiguration>
2385+ <AllowEmptyReferer>true</AllowEmptyReferer>
2386+ <RefererList>
2387+ <Referer>http://hello.com</Referer>
2388+ <Referer>mibrowser:home</Referer>
2389+ <Referer>{0}</Referer>
2390+ </RefererList>
2391+
2392+ </RefererConfiguration>''' .format ('阿里巴巴' )
2393+
2394+ req_info = mock_response (do_request , response_text )
2395+
2396+ result = bucket ().get_bucket_referer ()
2397+
2398+ self .assertRequest (req_info , request_text )
2399+ self .assertEqual (result .allow_empty_referer , True )
2400+ self .assertSortedListEqual (result .referers , ['http://hello.com' , 'mibrowser:home' , '阿里巴巴' ])
2401+
2402+
2403+
22742404if __name__ == '__main__' :
22752405 unittest .main ()
0 commit comments