@@ -139,16 +139,36 @@ def authenticate_long_credentials
139139    assert_equal ( expected ,  actual ) 
140140  end 
141141
142+   test  "token_and_options returns correct token with nounce option"  do 
143+     token  =  "rcHu+HzSFw89Ypyhn/896A=" 
144+     nonce_hash  =  { nonce : "123abc" } 
145+     actual  =  ActionController ::HttpAuthentication ::Token . token_and_options ( sample_request ( token ,  nonce_hash ) ) 
146+     expected_token  =  token 
147+     expected_nonce  =  { "nonce"  =>  nonce_hash [ :nonce ] } 
148+     assert_equal ( expected_token ,  actual . first ) 
149+     assert_equal ( expected_nonce ,  actual . last ) 
150+   end 
151+ 
142152  test  "token_and_options returns nil with no value after the equal sign"  do 
143153    actual  =  ActionController ::HttpAuthentication ::Token . token_and_options ( malformed_request ) . first 
144154    expected  =  nil 
145155    assert_equal ( expected ,  actual ) 
146156  end 
147157
158+   test  "raw_params returns a tuple of two key value pair strings"  do 
159+     auth  =  sample_request ( "rcHu+HzSFw89Ypyhn/896A=" ) . authorization . to_s 
160+     actual  =  ActionController ::HttpAuthentication ::Token . raw_params ( auth ) 
161+     expected  =  [ "token=\" rcHu+HzSFw89Ypyhn/896A=\" " ,  "nonce=\" def\" " ] 
162+     assert_equal ( expected ,  actual ) 
163+   end 
164+ 
148165  private 
149166
150-     def  sample_request ( token ) 
151-       @sample_request  ||= OpenStruct . new  authorization : %{Token token="#{ token }  ", nonce="def"} 
167+     def  sample_request ( token ,  options  =  { nonce : "def" } ) 
168+       authorization  =  options . inject ( [ %{Token token="#{ token }  "} ] )  do  |arr ,  ( k ,  v ) |
169+         arr  << "#{ k }  =\" #{ v } \" " 
170+       end . join ( ", " ) 
171+       @sample_request  ||= OpenStruct . new  authorization : authorization 
152172    end 
153173
154174    def  malformed_request 
0 commit comments