|
113 | 113 | expect( metadata.checksum ).to eq "{sha256}#{sha256}" |
114 | 114 | end |
115 | 115 | end |
| 116 | + |
| 117 | + context "with an ETag header" do |
| 118 | + context "without checksum => etag" do |
| 119 | + let(:md5) { "f5ffec8d8d16b43d5e9ac6ad4330c445" } |
| 120 | + |
| 121 | + it "does not auto-activate ETag and falls back to mtime" do |
| 122 | + http_response.add_field('ETag', %("#{md5}")) |
| 123 | + metadata = described_class.new(http_response) |
| 124 | + metadata.collect |
| 125 | + expect( metadata.checksum_type ).to eq :mtime |
| 126 | + end |
| 127 | + end |
| 128 | + |
| 129 | + context "with checksum_type => etag" do |
| 130 | + context "containing an MD5 hash" do |
| 131 | + let(:md5) { "f5ffec8d8d16b43d5e9ac6ad4330c445" } |
| 132 | + |
| 133 | + it "resolves to md5" do |
| 134 | + http_response.add_field('ETag', %("#{md5}")) |
| 135 | + metadata = described_class.new(http_response) |
| 136 | + metadata.checksum_type = :etag |
| 137 | + metadata.collect |
| 138 | + expect( metadata.checksum_type ).to eq :md5 |
| 139 | + expect( metadata.checksum ).to eq "{md5}#{md5}" |
| 140 | + end |
| 141 | + |
| 142 | + it "normalizes uppercase hex to lowercase" do |
| 143 | + http_response.add_field('ETag', %("#{md5.upcase}")) |
| 144 | + metadata = described_class.new(http_response) |
| 145 | + metadata.checksum_type = :etag |
| 146 | + metadata.collect |
| 147 | + expect( metadata.checksum ).to eq "{md5}#{md5}" |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + context "containing a SHA1 hash" do |
| 152 | + let(:sha1) { "01e4d15746f4274b84d740a93e04b9fd2882e3ea" } |
| 153 | + |
| 154 | + it "resolves to sha1" do |
| 155 | + http_response.add_field('ETag', %("#{sha1}")) |
| 156 | + metadata = described_class.new(http_response) |
| 157 | + metadata.checksum_type = :etag |
| 158 | + metadata.collect |
| 159 | + expect( metadata.checksum_type ).to eq :sha1 |
| 160 | + expect( metadata.checksum ).to eq "{sha1}#{sha1}" |
| 161 | + end |
| 162 | + end |
| 163 | + |
| 164 | + context "containing a SHA256 hash" do |
| 165 | + let(:sha256) { "a3eda98259c30e1e75039c2123670c18105e1c46efb672e42ca0e4cbe77b002a" } |
| 166 | + |
| 167 | + it "resolves to sha256" do |
| 168 | + http_response.add_field('ETag', %("#{sha256}")) |
| 169 | + metadata = described_class.new(http_response) |
| 170 | + metadata.checksum_type = :etag |
| 171 | + metadata.collect |
| 172 | + expect( metadata.checksum_type ).to eq :sha256 |
| 173 | + expect( metadata.checksum ).to eq "{sha256}#{sha256}" |
| 174 | + end |
| 175 | + end |
| 176 | + |
| 177 | + context "that is a weak ETag" do |
| 178 | + it "ignores the ETag and falls back to mtime" do |
| 179 | + http_response.add_field('ETag', 'W/"f5ffec8d8d16b43d5e9ac6ad4330c445"') |
| 180 | + metadata = described_class.new(http_response) |
| 181 | + metadata.checksum_type = :etag |
| 182 | + metadata.collect |
| 183 | + expect( metadata.checksum_type ).to eq :mtime |
| 184 | + end |
| 185 | + end |
| 186 | + |
| 187 | + context "that is not a recognizable hash" do |
| 188 | + it "ignores the ETag and falls back to mtime" do |
| 189 | + http_response.add_field('ETag', '"5e8c5-27a-3e8b8840"') |
| 190 | + metadata = described_class.new(http_response) |
| 191 | + metadata.checksum_type = :etag |
| 192 | + metadata.collect |
| 193 | + expect( metadata.checksum_type ).to eq :mtime |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + context "when explicit checksum headers are also present" do |
| 198 | + let(:explicit_md5) { "c58989e9740a748de4f5054286faf99b" } |
| 199 | + let(:etag_md5) { "f5ffec8d8d16b43d5e9ac6ad4330c445" } |
| 200 | + |
| 201 | + it "prefers the ETag over X-Checksum-Md5" do |
| 202 | + http_response.add_field('X-Checksum-Md5', explicit_md5) |
| 203 | + http_response.add_field('ETag', %("#{etag_md5}")) |
| 204 | + metadata = described_class.new(http_response) |
| 205 | + metadata.checksum_type = :etag |
| 206 | + metadata.collect |
| 207 | + expect( metadata.checksum_type ).to eq :md5 |
| 208 | + expect( metadata.checksum ).to eq "{md5}#{etag_md5}" |
| 209 | + end |
| 210 | + end |
| 211 | + |
| 212 | + context "with ETag and Last-Modified" do |
| 213 | + let(:md5) { "f5ffec8d8d16b43d5e9ac6ad4330c445" } |
| 214 | + let(:time) { Time.now.utc } |
| 215 | + |
| 216 | + it "prefers ETag-derived md5 over mtime" do |
| 217 | + http_response.add_field('ETag', %("#{md5}")) |
| 218 | + http_response.add_field('last-modified', time.strftime("%a, %d %b %Y %T GMT")) |
| 219 | + metadata = described_class.new(http_response) |
| 220 | + metadata.checksum_type = :etag |
| 221 | + metadata.collect |
| 222 | + expect( metadata.checksum_type ).to eq :md5 |
| 223 | + expect( metadata.checksum ).to eq "{md5}#{md5}" |
| 224 | + end |
| 225 | + end |
| 226 | + |
| 227 | + it "skips ETag-derived md5 on FIPS platforms and falls back" do |
| 228 | + allow(Puppet::Util::Platform).to receive(:fips_enabled?).and_return(true) |
| 229 | + http_response.add_field('ETag', '"f5ffec8d8d16b43d5e9ac6ad4330c445"') |
| 230 | + metadata = described_class.new(http_response) |
| 231 | + metadata.checksum_type = :etag |
| 232 | + metadata.collect |
| 233 | + expect( metadata.checksum_type ).to eq :mtime |
| 234 | + end |
| 235 | + |
| 236 | + it "falls back to other checksums when no ETag is present" do |
| 237 | + metadata = described_class.new(http_response) |
| 238 | + metadata.checksum_type = :etag |
| 239 | + metadata.collect |
| 240 | + expect( metadata.checksum_type ).to eq :mtime |
| 241 | + end |
| 242 | + end |
| 243 | + end |
116 | 244 | end |
117 | 245 | end |
0 commit comments