Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ on:

jobs:
check:
uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@feaa011dafd85fecb67aa058fbcf6424cf605e86
uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@4ea982dc3e7839b05bc0bd65a3e4a2868d44e1a1
88 changes: 5 additions & 83 deletions LAWS.bend

Large diffs are not rendered by default.

88 changes: 5 additions & 83 deletions PROOF.bend

Large diffs are not rendered by default.

20 changes: 4 additions & 16 deletions bolt.bend
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# bolt.bend: how bolt lints this repo. See bolt/config.bend for groups and
# levels. `param` and `wrap` are warn: this port keeps ez net's short framing
# parameters and compact multi-line headers.
# levels.
import Base

# what will fail or blow up
Expand All @@ -15,25 +14,14 @@ def suspicious() -> String:
def style() -> String:
"error"

# single-letter parameters (ez net idiom)
def param() -> String:
"warn"

# multi-line headers without one-param-per-line (ez net idiom)
def wrap() -> String:
"warn"

# a pure def named by no law
def laws() -> String:
"error"

# bolt 1.8.0 closed: warn until the findings are fixed (see the tracking issue)
# a law with no `for` or `exs` binder
def closed() -> String:
"warn"
"error"

# a def no quantified law reaches. main.bend's re-exports, the bench program
# and src/client.bend's Response type (the wire effect keeps it out of every
# law file) carry `# noqa: L001` with the reason; dotted defs are helpers,
# which bolt never grades
# a def no quantified law reaches
def coverage() -> String:
"error"
6 changes: 3 additions & 3 deletions ez.lock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ LICENSE = "309f5aae946e4db157750e002fb179a74ed0fe27fce09a7be68a6977b14f205f"
[tools]
[tools.bolt]
git = "https://github.com/Emerging-Patterns/bolt"
rev = "9700daf3a447089a8795d311912014382a74a2a9"
tag = "v1.27.0"
rev = "26391508a28b69077aaf59b75a80f774a455bca5"
tag = "v1.66.0"
root = "."
narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM="
narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM="
entry = "main.bend"
6 changes: 3 additions & 3 deletions ez.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ entry = "main.bend"
[tools]
[tools.bolt]
git = "https://github.com/Emerging-Patterns/bolt"
rev = "9700daf3a447089a8795d311912014382a74a2a9"
tag = "v1.27.0"
rev = "26391508a28b69077aaf59b75a80f774a455bca5"
tag = "v1.66.0"
root = "."
narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM="
narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM="
entry = "main.bend"
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions laws/AbsoluteFormTargetRejected.bend
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# For every method, target, header lines and body, a request-target that
# does not start with `/` and is not `*` (absolute-form such as
# `http://example.com/a`, or a bare `relative` path) is not origin-form, and
# the request is bad (RFC 9112 §3.2).
import Base
import ../src/http.bend as Http

# LAW (RFC 9112 §3.2.2): absolute-form is not accepted as origin-form
# LAW (RFC 9112 §3.2.1, §3.2.2): a target with no leading `/` that is not `*`
# is rejected
law ask_rejects_absolute_form:
{Http.ask("GET http://example.com/a HTTP/1.1\r\nHost: h\r\n\r\n")
for +method: String
for +target: String
for +ls: List<&2, String>
for body: String
for es: {False{} == String.starts_with(target, "/") : Bool}
for ea: {False{} == String.eq(target, "*") : Bool}
{Http.ask.line(method, target, ls, body)
== Http.Bad{"the request-target is not in origin-form"} : Http.Request}
6 changes: 0 additions & 6 deletions laws/Base64EmptyIsEmpty.bend

This file was deleted.

37 changes: 37 additions & 0 deletions laws/Base64EncodesByQuantum.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# For every string, Base64 (`b64.encode`, RFC 4648 §4) writes each group of
# three octets as the four alphabet characters of its 24 bits and goes on
# with the rest; a final group of two octets is three characters and one
# `=`, a final group of one octet is two characters and `==`; and the
# encoding is empty exactly when the input is. The RFC 4648 §10 test vectors
# (`f` is `Zg==`, `fo` is `Zm8=`, `foo` is `Zm9v`) and `user:pass` as
# `dXNlcjpwYXNz` are instances.
import Base
import ../src/b64.bend as B64

# LAW (RFC 4648 §4): three octets are one full quantum, then the rest
law b64_three:
for +a: Char
for +b: Char
for +c: Char
for s: String
{B64.b64.encode(SCon{a, SCon{b, SCon{c, s}}})
== B64.b64.quad(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c), 0n)
++ B64.b64.encode(s) : String}

# LAW (RFC 4648 §4): two final octets are three characters and one `=`
law b64_two:
for +a: Char
for +b: Char
{B64.b64.encode(SCon{a, SCon{b, SNil{}}})
== B64.b64.quad(Char.to_u32(a), Char.to_u32(b), 0, 1n) : String}

# LAW (RFC 4648 §4): one final octet is two characters and `==`
law b64_one:
for +a: Char
{B64.b64.encode(SCon{a, SNil{}}) == B64.b64.quad(Char.to_u32(a), 0, 0, 2n)
: String}

# LAW (RFC 4648 §4): the encoding is empty exactly when the input is
law b64_empty:
for s: String
{String.is_empty(B64.b64.encode(s)) == String.is_empty(s) : Bool}
6 changes: 0 additions & 6 deletions laws/Base64EncodesF.bend

This file was deleted.

6 changes: 0 additions & 6 deletions laws/Base64EncodesFo.bend

This file was deleted.

6 changes: 0 additions & 6 deletions laws/Base64EncodesFoo.bend

This file was deleted.

6 changes: 0 additions & 6 deletions laws/Base64EncodesUserPass.bend

This file was deleted.

12 changes: 10 additions & 2 deletions laws/BasicIsBase64OfUserPassword.bend
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# For every user and password, Basic credentials (`auth.basic`) are the
# Authorization field `Basic ` and the Base64 of `user:password`
# (laws/Base64EncodesByQuantum.bend); `user`/`pass` as
# `Basic dXNlcjpwYXNz` is an instance.
import Base
import ../src/http.bend as Http
import ../src/auth.bend as Auth
import ../src/b64.bend as B64

# LAW (RFC 7617 §2): Basic credentials are Base64 of user:password
law basic_user_pass:
{Auth.auth.basic("user", "pass")
== Http.H{"Authorization", "Basic dXNlcjpwYXNz"} : Http.Header}
for user: String
for password: String
{Auth.auth.basic(user, password)
== Http.H{"Authorization", "Basic " ++ B64.b64.encode(user ++ ":" ++ password)}
: Http.Header}
8 changes: 0 additions & 8 deletions laws/BearerTokenAcceptsPlain.bend

This file was deleted.

24 changes: 24 additions & 0 deletions laws/BearerTokenHasNoWhitespace.bend
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# For every string, a bearer token (`token.ok`, RFC 6750 §2.1) is rejected
# when a whitespace character (space, tab, newline, CR, VT, FF) appears
# anywhere in it, and a leading non-whitespace character leaves the verdict
# to the rest; so a token is accepted exactly when it has no whitespace
# (`abc` is accepted; `a b`, `a\tb` and `a\nb` are rejected).
import Base
import ../src/http.bend as Http

# --- RFC 6750 / 7617 / 4648 credentials ---

# LAW (RFC 6750 §2.1): a whitespace character anywhere rejects the token
law token_ok_space:
for a: String
for +c: Char
for +b: String
for +e: {Char.is_space(c) == True{} : Bool}
{Http.token.ok(a ++ SCon{c, b}) == False{} : Bool}

# LAW (RFC 6750 §2.1): a non-whitespace character leaves the rest to decide
law token_ok_plain:
for c: Char
for t: String
for e: {Char.is_space(c) == False{} : Bool}
{Http.token.ok(SCon{c, t}) == Http.token.ok(t) : Bool}
6 changes: 0 additions & 6 deletions laws/BearerTokenRejectsNewline.bend

This file was deleted.

6 changes: 0 additions & 6 deletions laws/BearerTokenRejectsSpace.bend

This file was deleted.

6 changes: 0 additions & 6 deletions laws/BearerTokenRejectsTab.bend

This file was deleted.

9 changes: 0 additions & 9 deletions laws/CacheDirectiveNamesIgnoreCase.bend

This file was deleted.

7 changes: 0 additions & 7 deletions laws/CacheIgnoresUnknownDirective.bend

This file was deleted.

7 changes: 0 additions & 7 deletions laws/CacheMaxAgeIgnoresJunk.bend

This file was deleted.

96 changes: 92 additions & 4 deletions laws/CacheReadsKnownDirectives.bend
Original file line number Diff line number Diff line change
@@ -1,7 +1,95 @@
# For every directive state `c` read so far and every directive text
# `piece`, Cache-Control is read one directive at a time, left to right,
# each over what the ones before it recorded (`cache.fold`). A directive with
# no `=` whose name, trimmed and in any case, is no-store, no-cache, public
# or private sets that flag and keeps the rest. A `max-age=` directive whose
# name is max-age in any case records its trimmed argument when that is
# delta-seconds and is ignored otherwise. A `name=value` directive with any
# other name is ignored (RFC 9111 §5.2: names are case-insensitive and
# unrecognized directives are ignored).
import Base
import ../src/http.bend as Http
import ../src/cache.bend as Cache

# LAW (RFC 9111 §5.2): no-store, no-cache, public, private, and max-age
law cache_directives:
{Cache.cache.parse("no-store, no-cache, public, private, max-age=5")
== Cache.Cc{True{}, True{}, True{}, True{}, "5", ""} : Cache.Cc}
# LAW (RFC 9111 §5.2): directives are read left to right
law fold_each:
for h: String
for t: List<&2, String>
for c: Cache.Cc
{Cache.cache.fold(h <> t, c) == Cache.cache.fold(t, Cache.cache.one(c, String.trim(h)))
: Cache.Cc}

# LAW (RFC 9111 §5.2): after the last directive, what was read is the result
law fold_end:
for c: Cache.Cc
{Cache.cache.fold([], c) == c : Cache.Cc}

# LAW (RFC 9111 §5.2.2.5): no-store, in any case, sets no-store
law one_no_store:
for c: Cache.Cc
for +piece: String
for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut}
for e2: {"no-store" == String.to_lower(String.trim(piece)) : String}
{Cache.cache.one(c, piece) == Cache.cache.store(c) : Cache.Cc}

# LAW (RFC 9111 §5.2.2.4): no-cache, in any case, sets no-cache
law one_no_cache:
for c: Cache.Cc
for +piece: String
for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut}
for e2: {"no-cache" == String.to_lower(String.trim(piece)) : String}
{Cache.cache.one(c, piece) == Cache.cache.revalidate(c) : Cache.Cc}

# LAW (RFC 9111 §5.2.2.9): public, in any case, sets public
law one_public:
for c: Cache.Cc
for +piece: String
for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut}
for e2: {"public" == String.to_lower(String.trim(piece)) : String}
{Cache.cache.one(c, piece) == Cache.cache.pub(c) : Cache.Cc}

# LAW (RFC 9111 §5.2.2.7): private, in any case, sets private
law one_private:
for c: Cache.Cc
for +piece: String
for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut}
for e2: {"private" == String.to_lower(String.trim(piece)) : String}
{Cache.cache.one(c, piece) == Cache.cache.priv(c) : Cache.Cc}

# LAW (RFC 9111 §5.2.2.1): max-age, in any case, records delta-seconds
law one_max_age:
for c: Cache.Cc
for +piece: String
for +before: String
for +after: String
for n: Nat
for e1: {Http.Cut{before, after} == Http.divide(piece, "=") : Http.Cut}
for e2: {"max-age" == String.to_lower(String.trim(before)) : String}
for e3: {Some{n} == Http.digits.read(String.trim(after)) : Maybe<&2, Nat>}
{Cache.cache.one(c, piece) == Cache.cache.age(c, String.trim(after)) : Cache.Cc}

# LAW (RFC 9111 §5.2.1.1): a max-age argument that is not delta-seconds is
# ignored
law one_max_age_junk:
for c: Cache.Cc
for +piece: String
for +before: String
for +after: String
for e1: {Http.Cut{before, after} == Http.divide(piece, "=") : Http.Cut}
for e2: {"max-age" == String.to_lower(String.trim(before)) : String}
for e3: {None{} == Http.digits.read(String.trim(after)) : Maybe<&2, Nat>}
{Cache.cache.one(c, piece) == c : Cache.Cc}

# LAW (RFC 9111 §5.2): a name=value directive of no recorded name is ignored
law one_unknown:
for c: Cache.Cc
for +piece: String
for +before: String
for +after: String
for e1: {Http.Cut{before, after} == Http.divide(piece, "=") : Http.Cut}
for e2: {False{} == String.eq(String.to_lower(String.trim(before)), "no-store") : Bool}
for e3: {False{} == String.eq(String.to_lower(String.trim(before)), "no-cache") : Bool}
for e4: {False{} == String.eq(String.to_lower(String.trim(before)), "max-age") : Bool}
for e5: {False{} == String.eq(String.to_lower(String.trim(before)), "public") : Bool}
for e6: {False{} == String.eq(String.to_lower(String.trim(before)), "private") : Bool}
{Cache.cache.one(c, piece) == c : Cache.Cc}
Loading
Loading