18
18
19
19
import datetime
20
20
21
+ import pytest
22
+
21
23
import snippets
22
24
23
25
@@ -27,7 +29,7 @@ def test_sign_url() -> None:
27
29
"http://35.186.234.33/index.html" ,
28
30
"my-key" ,
29
31
"nZtRohdNF9m3cKM24IcK4w==" ,
30
- datetime .datetime .utcfromtimestamp (1549751401 ),
32
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
31
33
)
32
34
== "http://35.186.234.33/index.html?Expires=1549751401&KeyName=my-key&Signature=CRFqQnVfFyiUyR63OQf-HRUpIwc="
33
35
)
@@ -37,7 +39,7 @@ def test_sign_url() -> None:
37
39
"http://www.example.com/" ,
38
40
"my-key" ,
39
41
"nZtRohdNF9m3cKM24IcK4w==" ,
40
- datetime .datetime .utcfromtimestamp (1549751401 ),
42
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
41
43
)
42
44
== "http://www.example.com/?Expires=1549751401&KeyName=my-key&Signature=OqDUFfHpN5Vxga6r80bhsgxKves="
43
45
)
@@ -46,19 +48,36 @@ def test_sign_url() -> None:
46
48
"http://www.example.com/some/path?some=query&another=param" ,
47
49
"my-key" ,
48
50
"nZtRohdNF9m3cKM24IcK4w==" ,
49
- datetime .datetime .utcfromtimestamp (1549751401 ),
51
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
50
52
)
51
53
== "http://www.example.com/some/path?some=query&another=param&Expires=1549751401&KeyName=my-key&Signature=9Q9TCxSju8-W5nUkk5CuTrun2_o="
52
54
)
53
55
54
56
57
+ def test_sign_url_raise_exception_on_naive_expiration_datetime () -> None :
58
+ with pytest .raises (TypeError ):
59
+ snippets .sign_url (
60
+ "http://www.example.com/some/path?some=query&another=param" ,
61
+ "my-key" ,
62
+ "nZtRohdNF9m3cKM24IcK4w==" ,
63
+ datetime .datetime .fromtimestamp (1549751401 ),
64
+ )
65
+ with pytest .raises (TypeError ):
66
+ snippets .sign_url (
67
+ "http://www.example.com/some/path?some=query&another=param" ,
68
+ "my-key" ,
69
+ "nZtRohdNF9m3cKM24IcK4w==" ,
70
+ datetime .datetime .utcfromtimestamp (1549751401 ),
71
+ )
72
+
73
+
55
74
def test_sign_url_prefix () -> None :
56
75
assert snippets .sign_url_prefix (
57
76
"http://35.186.234.33/index.html" ,
58
77
"http://35.186.234.33/" ,
59
78
"my-key" ,
60
79
"nZtRohdNF9m3cKM24IcK4w==" ,
61
- datetime .datetime .utcfromtimestamp (1549751401 ),
80
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
62
81
) == (
63
82
"http://35.186.234.33/index.html?URLPrefix=aHR0cDovLzM1LjE4Ni4yMzQuMzMv&"
64
83
"Expires=1549751401&KeyName=my-key&Signature=j7HYgoQ8dIOVsW3Rw4cpkjWfRMA="
@@ -68,7 +87,7 @@ def test_sign_url_prefix() -> None:
68
87
"http://www.example.com/" ,
69
88
"my-key" ,
70
89
"nZtRohdNF9m3cKM24IcK4w==" ,
71
- datetime .datetime .utcfromtimestamp (1549751401 ),
90
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
72
91
) == (
73
92
"http://www.example.com/?URLPrefix=aHR0cDovL3d3dy5leGFtcGxlLmNvbS8=&"
74
93
"Expires=1549751401&KeyName=my-key&Signature=UdT5nVks6Hh8QFMJI9kmXuXYBk0="
@@ -78,21 +97,40 @@ def test_sign_url_prefix() -> None:
78
97
"http://www.example.com/some/" ,
79
98
"my-key" ,
80
99
"nZtRohdNF9m3cKM24IcK4w==" ,
81
- datetime .datetime .utcfromtimestamp (1549751401 ),
100
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
82
101
) == (
83
102
"http://www.example.com/some/path?some=query&another=param&"
84
103
"URLPrefix=aHR0cDovL3d3dy5leGFtcGxlLmNvbS9zb21lLw==&"
85
104
"Expires=1549751401&KeyName=my-key&Signature=3th4ThmpS95I1TAKYyYSCSq3dnQ="
86
105
)
87
106
88
107
108
+ def test_sign_url_prefix_raise_exception_on_naive_expiration_datetime () -> None :
109
+ with pytest .raises (TypeError ):
110
+ snippets .sign_url_prefix (
111
+ "http://www.example.com/some/path?some=query&another=param" ,
112
+ "http://www.example.com/some/" ,
113
+ "my-key" ,
114
+ "nZtRohdNF9m3cKM24IcK4w==" ,
115
+ datetime .datetime .fromtimestamp (1549751401 ),
116
+ )
117
+ with pytest .raises (TypeError ):
118
+ snippets .sign_url_prefix (
119
+ "http://www.example.com/some/path?some=query&another=param" ,
120
+ "http://www.example.com/some/" ,
121
+ "my-key" ,
122
+ "nZtRohdNF9m3cKM24IcK4w==" ,
123
+ datetime .datetime .utcfromtimestamp (1549751401 ),
124
+ )
125
+
126
+
89
127
def test_sign_cookie () -> None :
90
128
assert (
91
129
snippets .sign_cookie (
92
130
"http://35.186.234.33/index.html" ,
93
131
"my-key" ,
94
132
"nZtRohdNF9m3cKM24IcK4w==" ,
95
- datetime .datetime .utcfromtimestamp (1549751401 ),
133
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
96
134
)
97
135
== "Cloud-CDN-Cookie=URLPrefix=aHR0cDovLzM1LjE4Ni4yMzQuMzMvaW5kZXguaHRtbA==:Expires=1549751401:KeyName=my-key:Signature=uImwlOBCPs91mlCyG9vyyZRrNWU="
98
136
)
@@ -102,7 +140,24 @@ def test_sign_cookie() -> None:
102
140
"http://www.example.com/foo/" ,
103
141
"my-key" ,
104
142
"nZtRohdNF9m3cKM24IcK4w==" ,
105
- datetime .datetime .utcfromtimestamp (1549751401 ),
143
+ datetime .datetime .fromtimestamp (1549751401 , datetime . timezone . utc ),
106
144
)
107
145
== "Cloud-CDN-Cookie=URLPrefix=aHR0cDovL3d3dy5leGFtcGxlLmNvbS9mb28v:Expires=1549751401:KeyName=my-key:Signature=Z9uYAu73YHioRScZDxnP-TnS274="
108
146
)
147
+
148
+
149
+ def test_sign_cookie_raise_exception_on_naive_expiration_datetime () -> None :
150
+ with pytest .raises (TypeError ):
151
+ snippets .sign_cookie (
152
+ "http://www.example.com/foo/" ,
153
+ "my-key" ,
154
+ "nZtRohdNF9m3cKM24IcK4w==" ,
155
+ datetime .datetime .fromtimestamp (1549751401 ),
156
+ )
157
+ with pytest .raises (TypeError ):
158
+ snippets .sign_cookie (
159
+ "http://www.example.com/foo/" ,
160
+ "my-key" ,
161
+ "nZtRohdNF9m3cKM24IcK4w==" ,
162
+ datetime .datetime .utcfromtimestamp (1549751401 ),
163
+ )
0 commit comments