# Generated by: tfg preset eject upload-validation
# Does my upload form take what it should and turn the rest away?
#
# Edit it, commit it, it is an ordinary recipe from here on.

version: 1
targets:
  - id: under_1b
    format: jpg
    count: 1
    size: 10485759
    name: 10mb_under_1b.jpg
    group: size-limit
    purpose: "A JPEG file 1 B under the limit of 10mb. Your system should take it - a refusal means the limit is enforced lower than it is declared."
    expected: accept
  - id: at_limit
    format: jpg
    count: 1
    size: 10485760
    name: 10mb_at_limit.jpg
    group: size-limit
    purpose: A JPEG file of exactly 10mb, the limit itself. Your system should take it. A refusal here usually means the comparison is off by one, or your system counts a kilobyte as 1000 bytes where this set counts 1024.
    expected: accept
  - id: over_1b
    format: jpg
    count: 1
    size: 10485761
    name: 10mb_over_1b.jpg
    group: size-limit
    purpose: "A JPEG file 1 B over the limit of 10mb. Your system should turn it away - taking it means the limit is not enforced, or enforced only in the browser."
    expected:
      outcome: reject
      reason: size_limit
  - id: far_over_2x
    format: jpg
    count: 1
    size: 20971520
    name: 10mb_far_over_2x.jpg
    group: size-limit
    purpose: "A JPEG file 2 times the limit of 10mb. Your form should turn it away before it has read the whole of it - one that reads the body into memory first shows it here."
    expected:
      outcome: reject
      reason: size_limit
  - id: empty
    format: txt
    count: 1
    size: 0
    name: empty.jpg
    group: degenerate
    purpose: "An empty file, nought bytes, under a name your form accepts - somebody pressed upload on nothing. Whether your form takes it or turns it away is its own policy - decide which, and check that it does that."
    expected:
      outcome: unspecified
      reason: size_zero
  - id: allowed_jpg
    format: jpg
    count: 1
    size: 5242880
    name: allowed_jpg.jpg
    group: allowed-types
    purpose: "A real JPEG file well inside the limit, of a type your form accepts. Your form should take it - if it does not, every refusal in the rest of the set means nothing."
    expected: accept
  - id: allowed_pdf
    format: pdf
    count: 1
    size: 5242880
    name: allowed_pdf.pdf
    group: allowed-types
    purpose: "A real Portable Document Format file well inside the limit, of a type your form accepts. Your form should take it - if it does not, every refusal in the rest of the set means nothing."
    expected: accept
  - id: allowed_png
    format: png
    count: 1
    size: 5242880
    name: allowed_png.png
    group: allowed-types
    purpose: "A real Portable Network Graphics file well inside the limit, of a type your form accepts. Your form should take it - if it does not, every refusal in the rest of the set means nothing."
    expected: accept
  - id: denied_exe
    format: txt
    count: 1
    size: 4096
    name: denied.exe
    group: denied-types
    purpose: A file ending in .exe, an extension your form turns away. It should be refused by its name, whatever it holds. This build has no format of that name, so the file holds plain text.
    expected:
      outcome: reject
      reason: extension_rule
  - id: denied_html
    format: html
    count: 1
    size: 4096
    name: denied.html
    group: denied-types
    purpose: A file ending in .html, an extension your form turns away. It should be refused by its name, whatever it holds.
    expected:
      outcome: reject
      reason: extension_rule
  - id: denied_sh
    format: txt
    count: 1
    size: 4096
    name: denied.sh
    group: denied-types
    purpose: A file ending in .sh, an extension your form turns away. It should be refused by its name, whatever it holds. This build has no format of that name, so the file holds plain text.
    expected:
      outcome: reject
      reason: extension_rule
  - id: denied_svg
    format: svg
    count: 1
    size: 4096
    name: denied.svg
    group: denied-types
    purpose: A file ending in .svg, an extension your form turns away. It should be refused by its name, whatever it holds.
    expected:
      outcome: reject
      reason: extension_rule
  - id: mismatch_jpg
    format: pdf
    count: 1
    size: 4096
    name: pdf_as_jpg.jpg
    group: extension-content-mismatch
    purpose: "A real Portable Document Format file under a name ending in .jpg. Your form takes both types and should still refuse this one - a form that checks only the extension, and never looks inside, takes it."
    expected:
      outcome: reject
      reason: mime_mismatch
  - id: mismatch_pdf
    format: png
    count: 1
    size: 4096
    name: png_as_pdf.pdf
    group: extension-content-mismatch
    purpose: "A real Portable Network Graphics file under a name ending in .pdf. Your form takes both types and should still refuse this one - a form that checks only the extension, and never looks inside, takes it."
    expected:
      outcome: reject
      reason: mime_mismatch
  - id: mismatch_png
    format: jpg
    count: 1
    size: 4096
    name: jpg_as_png.png
    group: extension-content-mismatch
    purpose: "A real JPEG file under a name ending in .png. Your form takes both types and should still refuse this one - a form that checks only the extension, and never looks inside, takes it."
    expected:
      outcome: reject
      reason: mime_mismatch
  - id: no_extension
    format: jpg
    count: 1
    size: 4096
    name: invoice
    group: extension-anomalies
    purpose: "A file of a type your form accepts, named invoice with no extension at all. Whether your form insists on an extension is its own rule - check that it gives the answer you meant."
    expected:
      outcome: unspecified
      reason: extension_rule
  - id: uppercase_extension
    format: jpg
    count: 1
    size: 4096
    name: PHOTO.JPG
    group: extension-anomalies
    purpose: "A file of a type your form accepts, with the name and the extension in capitals. A form that compares extensions with case turns it away where it takes the same file in lower case - decide which you want."
    expected:
      outcome: unspecified
      reason: extension_rule
  - id: double_extension
    format: jpg
    count: 1
    size: 4096
    name: invoice.jpg.exe
    group: extension-anomalies
    purpose: "An allowed extension followed by a denied one. Your form should turn it away - one that looks for an allowed extension anywhere in the name takes it, and a server may then run it."
    expected:
      outcome: reject
      reason: extension_rule
  - id: long_name
    format: jpg
    count: 1
    size: 4096
    name: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg
    group: hostile-names
    purpose: "A name of 204 letters and the extension. A database column or a path limit shorter than that cuts it or refuses it - check which, and that the file is never stored under a shortened name without a word."
    expected:
      outcome: unspecified
      reason: filename_too_long
  - id: outside_ascii
    format: jpg
    count: 1
    size: 4096
    name: wiadomość_日本語_🎉.jpg
    group: hostile-names
    purpose: A name with Polish letters, Japanese and an emoji. A form that handles names as bytes, or in a single encoding, stores or shows it garbled.
    expected:
      outcome: unspecified
      reason: filename_invalid
  - id: spaces_and_brackets
    format: jpg
    count: 1
    size: 4096
    name: my report (final) v2.jpg
    group: hostile-names
    purpose: "A name with spaces and brackets, legal on every system. Your form should take it - a script that does not quote names breaks on it."
    expected: accept
  - id: bulk
    format: jpg
    count: 50
    size: 1048576
    name: bulk_{index:04}.jpg
    group: bulk-upload
    purpose: "50 files of a type your form accepts, uploaded together. Your form should take every one of them - the set checks a limit on how many files arrive at once, and that none of them is lost."
    expected: accept
  - id: climbing_name
    format: jpg
    count: 1
    size: 4096
    name: climbing_name.jpg
    send-as: ../tfg_climbed_out.jpg
    group: hostile-names
    purpose: A name that steps one directory up, written with a forward slash. A form that joins the name to its upload directory writes the file outside it. Your form should turn the name away or store the file under a name with no path in it. Then check that no file called tfg_climbed_out.jpg appeared above the upload directory.
    expected:
      outcome: unspecified
      reason: filename_traversal
  - id: climbing_name_backslash
    format: jpg
    count: 1
    size: 4096
    name: climbing_name_backslash.jpg
    send-as: "..\\tfg_climbed_out.jpg"
    group: hostile-names
    purpose: The same step up written with a backslash, which only Windows reads as a separator. A check made on Linux lets the name through whole, and a Windows machine that stores the file later steps out. Your form should turn the name away or store the file under a name with no path in it. Then check that no file called tfg_climbed_out.jpg appeared above the upload directory.
    expected:
      outcome: unspecified
      reason: filename_traversal
  - id: absolute_name
    format: jpg
    count: 1
    size: 4096
    name: absolute_name.jpg
    send-as: /tmp/tfg_climbed_out.jpg
    group: hostile-names
    purpose: A name that is a whole path on Linux and macOS, starting at the root of the disk. A form that uses it as given writes to /tmp. Your form should turn the name away or store the file under a name with no path in it. Then check that /tmp holds no file called tfg_climbed_out.jpg.
    expected:
      outcome: unspecified
      reason: filename_traversal
  - id: drive_name
    format: jpg
    count: 1
    size: 4096
    name: drive_name.jpg
    send-as: "C:\\Windows\\Temp\\tfg_climbed_out.jpg"
    group: hostile-names
    purpose: A name that is a whole path on Windows, drive letter included. A form that uses it as given writes to that folder. Your form should turn the name away or store the file under a name with no path in it. Then check that the folder holds no file called tfg_climbed_out.jpg.
    expected:
      outcome: unspecified
      reason: filename_traversal
