#  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.

# This expects a remap.config that allows GET and POST, but denies all other
# methods.

meta:
  version: "1.0"

  blocks:
  - standard_response: &standard_response
      server-response:
        status: 200
        reason: OK
        headers:
          fields:
          - [ Content-Length, 20 ]

sessions:
- protocol:
  - name: http
    version: 1
  - name: proxy-protocol
    version: 2
    src-addr: "1.2.3.4:1111"
    dst-addr: "5.6.7.8:2222"
  transactions:

  - client-request:
      method: "GET"
      version: "1.1"
      url: /test/ip_allow/test_get
      headers:
        fields:
        - [ Content-Length, 0 ]
        - [ uuid, get ]
        - [ X-Request, get ]

    <<: *standard_response

    proxy-response:
      status: 200

  # POST also is in the allow list.
  - client-request:
      method: "POST"
      version: "1.1"
      url: /test/ip_allow/test_post
      headers:
        fields:
        - [Content-Length, 10]
        - [ uuid, post ]
        - [ X-Request, post ]

    <<: *standard_response

    proxy-response:
      status: 200

  # PUT rejected
  - client-request:
      method: "PUT"
      version: "1.1"
      url: /test/ip_allow/test_put
      headers:
        fields:
        - [ Host, example.com ]
        - [ uuid, put ]
        - [ X-Request, put ]
        - [ Content-Length, 113 ]
      content:
        encoding: plain
        data: "HTTP/1.1 200 OK\nServer: ATS/10.0.0\nAccept-Ranges: bytes\nContent-Length: 6\nCache-Control: public,max-age=2\n\nCACHED"

    # Not received.
    <<: *standard_response

    # Verify that ATS rejected the PUSH.
    proxy-response:
      status: 403

- protocol:
  - name: http
    version: 1
  - name: proxy-protocol
    version: 2
    src-addr: "1.2.3.4:1111"
    dst-addr: "5.6.7.8:2222"
  delay: 2s
  transactions:

  # DELETE rejected
  - client-request:
      method: "DELETE"
      version: "1.1"
      url: /test/ip_allow/test_delete
      headers:
        fields:
        - [ Host, example.com ]
        - [ uuid, delete ]
        - [ X-Request, delete ]
        - [ Content-Length, 0 ]

    <<: *standard_response

    # Verify that ATS rejects the DELETE.
    proxy-response:
      status: 403

- protocol:
  - name: http
    version: 1
  - name: proxy-protocol
    version: 2
    src-addr: "1.2.3.4:1111"
    dst-addr: "5.6.7.8:2222"
  delay: 4s
  transactions:

  # PUSH rejected
  - client-request:
      method: "PUSH"
      version: "1.1"
      url: /test/ip_allow/test_push
      headers:
        fields:
        - [ Host, example.com ]
        - [ uuid, push ]
        - [ X-Request, push ]
        - [ Content-Length, 113 ]
      content:
        encoding: plain
        data: "HTTP/1.1 200 OK\nServer: ATS/10.0.0\nAccept-Ranges: bytes\nContent-Length: 6\nCache-Control: public,max-age=2\n\nCACHED"

    <<: *standard_response

    # Verify that ATS rejected the PUSH.
    proxy-response:
      status: 403
