|
4 | 4 |
|
5 | 5 | describe ApiAuth::RequestDrivers::ActionControllerRequest do |
6 | 6 | let(:timestamp) { Time.now.utc.httpdate } |
| 7 | + let(:content_sha256) { '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' } |
7 | 8 |
|
8 | 9 | let(:request) do |
9 | 10 | ActionController::Request.new( |
10 | 11 | 'AUTHORIZATION' => 'APIAuth 1044:12345', |
11 | 12 | 'PATH_INFO' => '/resource.xml', |
12 | 13 | 'QUERY_STRING' => 'foo=bar&bar=foo', |
13 | 14 | 'REQUEST_METHOD' => 'PUT', |
14 | | - 'HTTP_X_AUTHORIZATION_CONTENT_SHA256' => '47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=', |
| 15 | + 'HTTP_X_AUTHORIZATION_CONTENT_SHA256' => content_sha256, |
| 16 | + 'CONTENT_TYPE' => 'text/plain', |
| 17 | + 'CONTENT_LENGTH' => '11', |
| 18 | + 'HTTP_DATE' => timestamp, |
| 19 | + 'rack.input' => StringIO.new("hello\nworld") |
| 20 | + ) |
| 21 | + end |
| 22 | + |
| 23 | + let(:request2) do |
| 24 | + ActionController::Request.new( |
| 25 | + 'AUTHORIZATION' => 'APIAuth 1044:12345', |
| 26 | + 'PATH_INFO' => '/resource.xml', |
| 27 | + 'QUERY_STRING' => 'foo=bar&bar=foo', |
| 28 | + 'REQUEST_METHOD' => 'PUT', |
| 29 | + 'X_AUTHORIZATION_CONTENT_SHA256' => content_sha256, |
| 30 | + 'CONTENT_TYPE' => 'text/plain', |
| 31 | + 'CONTENT_LENGTH' => '11', |
| 32 | + 'HTTP_DATE' => timestamp, |
| 33 | + 'rack.input' => StringIO.new("hello\nworld") |
| 34 | + ) |
| 35 | + end |
| 36 | + |
| 37 | + let(:request3) do |
| 38 | + ActionController::Request.new( |
| 39 | + 'AUTHORIZATION' => 'APIAuth 1044:12345', |
| 40 | + 'PATH_INFO' => '/resource.xml', |
| 41 | + 'QUERY_STRING' => 'foo=bar&bar=foo', |
| 42 | + 'REQUEST_METHOD' => 'PUT', |
| 43 | + 'X-AUTHORIZATION-CONTENT-SHA256' => content_sha256, |
15 | 44 | 'CONTENT_TYPE' => 'text/plain', |
16 | 45 | 'CONTENT_LENGTH' => '11', |
17 | 46 | 'HTTP_DATE' => timestamp, |
|
27 | 56 | end |
28 | 57 |
|
29 | 58 | it 'gets the content_hash' do |
30 | | - expect(driven_request.content_hash).to eq('47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=') |
| 59 | + expect(driven_request.content_hash).to eq(content_sha256) |
| 60 | + end |
| 61 | + |
| 62 | + it 'gets the content_hash for request 2' do |
| 63 | + example_request = ApiAuth::RequestDrivers::ActionControllerRequest.new(request2) |
| 64 | + expect(example_request.content_hash).to eq(content_sha256) |
| 65 | + end |
| 66 | + |
| 67 | + it 'gets the content_hash for request 3' do |
| 68 | + example_request = ApiAuth::RequestDrivers::ActionControllerRequest.new(request3) |
| 69 | + expect(example_request.content_hash).to eq(content_sha256) |
31 | 70 | end |
32 | 71 |
|
33 | 72 | it 'gets the request_uri' do |
|
50 | 89 | it 'treats no body as empty string' do |
51 | 90 | request.env['rack.input'] = StringIO.new |
52 | 91 | request.env['CONTENT_LENGTH'] = 0 |
53 | | - expect(driven_request.calculated_hash).to eq('47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=') |
| 92 | + expect(driven_request.calculated_hash).to eq(content_sha256) |
54 | 93 | end |
55 | 94 | end |
56 | 95 |
|
|
0 commit comments