-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
Copy pathsnippets_test.py
110 lines (95 loc) · 3.92 KB
/
snippets_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
#
# Copyright 2017 Google, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for snippets."""
import datetime
import snippets
def test_sign_url(capsys):
snippets.sign_url(
'http://35.186.234.33/index.html',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
snippets.sign_url(
'http://www.example.com/',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
snippets.sign_url(
'http://www.example.com/some/path?some=query&another=param',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
out, _ = capsys.readouterr()
results = out.splitlines()
assert results[0] == (
'http://35.186.234.33/index.html?Expires=1549751401&KeyName=my-key&'
'Signature=CRFqQnVfFyiUyR63OQf-HRUpIwc=')
assert results[1] == (
'http://www.example.com/?Expires=1549751401&KeyName=my-key&'
'Signature=OqDUFfHpN5Vxga6r80bhsgxKves=')
assert results[2] == (
'http://www.example.com/some/path?some=query&another=param&Expires='
'1549751401&KeyName=my-key&Signature=9Q9TCxSju8-W5nUkk5CuTrun2_o=')
def test_sign_url_prefix(capsys):
snippets.sign_url_prefix(
'http://35.186.234.33/index.html',
'http://35.186.234.33/',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
snippets.sign_url_prefix(
'http://www.example.com/',
'http://www.example.com/',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
snippets.sign_url_prefix(
'http://www.example.com/some/path?some=query&another=param',
'http://www.example.com/some/',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
out, _ = capsys.readouterr()
results = out.splitlines()
assert results[0] == (
'http://35.186.234.33/index.html?URLPrefix=aHR0cDovLzM1LjE4Ni4yMzQuMzMv&'
'Expires=1549751401&KeyName=my-key&Signature=j7HYgoQ8dIOVsW3Rw4cpkjWfRMA=')
assert results[1] == (
'http://www.example.com/?URLPrefix=aHR0cDovL3d3dy5leGFtcGxlLmNvbS8=&'
'Expires=1549751401&KeyName=my-key&Signature=UdT5nVks6Hh8QFMJI9kmXuXYBk0=')
assert results[2] == (
'http://www.example.com/some/path?some=query&another=param&'
'URLPrefix=aHR0cDovL3d3dy5leGFtcGxlLmNvbS9zb21lLw==&'
'Expires=1549751401&KeyName=my-key&Signature=3th4ThmpS95I1TAKYyYSCSq3dnQ=')
def test_sign_cookie(capsys):
snippets.sign_cookie(
'http://35.186.234.33/index.html',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
snippets.sign_cookie(
'http://www.example.com/foo/',
'my-key',
'nZtRohdNF9m3cKM24IcK4w==',
datetime.datetime.utcfromtimestamp(1549751401))
out, _ = capsys.readouterr()
results = out.splitlines()
assert results[0] == (
'Cloud-CDN-Cookie=URLPrefix=aHR0cDovLzM1LjE4Ni4yMzQuMzMvaW5kZXguaHRtbA==:'
'Expires=1549751401:KeyName=my-key:Signature=uImwlOBCPs91mlCyG9vyyZRrNWU=')
assert results[1] == (
'Cloud-CDN-Cookie=URLPrefix=aHR0cDovL3d3dy5leGFtcGxlLmNvbS9mb28v:'
'Expires=1549751401:KeyName=my-key:Signature=Z9uYAu73YHioRScZDxnP-TnS274=')