@@ -86,44 +86,50 @@ def test_create_message_wrong_method(self):
8686 signing .create_base_message (params , url , method = 'WRONG' )
8787
8888 def test_sign (self ):
89+ signature = '5b341f4321476715ab1ae252794783c6dffa32dbdcc94512193ea3cf'
8990 params = {
9091 u'parĄm1' : u'valuĘ' ,
91- 'param2 ' : ['value2' , 'value3' ],
92- 'hmac' : 'to -be-removed' ,
93- 'gettoken' : 'to -be-removed-too' ,
92+ b'par \xc4 \x84 m1 ' : ['value2' , 'value3' ],
93+ b 'hmac' : 'will -be-removed' ,
94+ u 'gettoken' : 'will -be-removed-too' ,
9495 }
95- url = u'https://endpoint.com/api'
96+ url = b'https://endpoint.com/api'
97+ secret = b'secret'
9698
97- secret = u'secret' # unicode is what we usually get from api/db..
99+ # sha224 hmac
100+ self .assertEqual (signing .sign (secret , params , url ), signature )
98101
99- mac = signing .sign (secret , params , url )
100- self .assertNotIn ('hmac' , params )
101- self .assertNotIn ('gettoken' , params )
102+ # Test that `hmac` and `gettoken` are not being removed from the
103+ # original arguments passed to the function
104+ self .assertIn (b'hmac' , params )
105+ self .assertIn (u'gettoken' , params )
102106
103- # sha224 hmac
104- self .assertEqual (
105- mac ,
106- '346f3d53ad762f3ed3fb7f2427dec2bbfaf0338bb7f91f0460aff15c' ,
107- )
107+ del params [b'hmac' ]
108+ del params [u'gettoken' ]
109+ self .assertEqual (signing .sign (secret , params , url ), signature )
108110
109111 def test_sign_unicode_secret (self ):
112+ signature = '635cef6498fc5f1a829275cc1b24a191d5267d6023034e3e0953e4c6'
110113 params = {
111114 u'parĄm1' : u'valuĘ' ,
112115 'param2' : ['value2' , 'value3' ],
113- 'hmac' : 'will -be-removed' ,
114- 'gettoken' : 'will -be-removed-too' ,
116+ u 'hmac' : 'to -be-removed' ,
117+ b 'gettoken' : 'to -be-removed-too' ,
115118 }
116119 url = u'https://endpoint.com/api'
117-
118120 secret = u'☃🐍' # unicode is what we usually get from api/db..
119121
120- mac = signing .sign (secret , params , url )
121-
122122 # sha224 hmac
123- self .assertEqual (
124- mac ,
125- '635cef6498fc5f1a829275cc1b24a191d5267d6023034e3e0953e4c6' ,
126- )
123+ self .assertEqual (signing .sign (secret , params , url ), signature )
124+
125+ # Test that `hmac` and `gettoken` are not being removed from the
126+ # original arguments passed to the function
127+ self .assertIn (u'hmac' , params )
128+ self .assertIn (b'gettoken' , params )
129+
130+ del params [u'hmac' ]
131+ del params [b'gettoken' ]
132+ self .assertEqual (signing .sign (secret , params , url ), signature )
127133
128134 def test_verify_byte_signature (self ):
129135 params = {
0 commit comments