#  Licensed to the Apache Software Foundation (ASF) under one
#  or more contributor license agreements.  See the NOTICE file
#  distributed with this work for additional information
#  regarding copyright ownership.  The ASF licenses this file
#  to you under the Apache License, Version 2.0 (the
#  "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

#
# Try a get request on /path/404 and verify it is not cached. This is used
# to verify that the object was aged out of the cache.
#

meta:
  version: "1.0"

  blocks:
  - 403_response: &403_response
      server-response:
        status: 403
        reason: "Forbidden"
        headers:
          fields:
          - [ Content-Length, 8 ]

  - 404_response: &404_response
      server-response:
        status: 404
        reason: "Not Found"
        headers:
          fields:
          - [ Content-Length, 0 ]

sessions:
- transactions:

  #
  # Test 1: Verify that a 404 response is no longer in the cache.
  #
  - all: { headers: { fields: [[ uuid, 10 ]]}}
    client-request:
      method: "GET"
      version: "1.1"
      scheme: "http"
      url: /path/404
      headers:
        fields:
        - [ Host, example.com ]

    # This should go to the server. Verify we get a 403 response instead of the
    # previously cached 404.
    <<: *403_response

    # Expect the origin server 403, not the stale, cached 404.
    proxy-response:
      status: 403

  # For good measure, verify that the new 403 response is cached.
  - all: { headers: { fields: [[ uuid, 11 ]]}}
    client-request:
      method: "GET"
      version: "1.1"
      scheme: "http"
      url: /path/404
      headers:
        fields:
        - [ Host, example.com ]

      # Add a delay so ATS has time to finish any caching IO for the previous
      # transaction.
      delay: 100ms

    # 403 responses should be cached when negative caching is enabled, so this
    # should not get to the server.  But if it does, return a 404 so the test
    # knows that something went wrong.
    <<: *404_response

    # Expect the cached 403 response.
    proxy-response:
      status: 403
