Happy case test.

This commit is contained in:
LukeMathWalker 2021-01-16 23:01:08 +00:00
parent 50e660f82d
commit 3145991669
7 changed files with 457 additions and 45 deletions

373
Cargo.lock generated
View file

@ -7,13 +7,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78d1833b3838dbe990df0f1f87baf640cf6146e898166afe401839d1b001e570" checksum = "78d1833b3838dbe990df0f1f87baf640cf6146e898166afe401839d1b001e570"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bytes", "bytes 0.5.6",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"log", "log",
"pin-project 0.4.27", "pin-project 0.4.27",
"tokio", "tokio 0.2.24",
"tokio-util", "tokio-util 0.3.1",
] ]
[[package]] [[package]]
@ -50,7 +50,7 @@ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"bitflags", "bitflags",
"brotli2", "brotli2",
"bytes", "bytes 0.5.6",
"cookie", "cookie",
"copyless", "copyless",
"derive_more", "derive_more",
@ -61,7 +61,7 @@ dependencies = [
"futures-core", "futures-core",
"futures-util", "futures-util",
"fxhash", "fxhash",
"h2", "h2 0.2.7",
"http", "http",
"httparse", "httparse",
"indexmap", "indexmap",
@ -117,7 +117,7 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"smallvec", "smallvec",
"tokio", "tokio 0.2.24",
] ]
[[package]] [[package]]
@ -133,7 +133,7 @@ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"log", "log",
"mio", "mio 0.6.23",
"mio-uds", "mio-uds",
"num_cpus", "num_cpus",
"slab", "slab",
@ -201,7 +201,7 @@ dependencies = [
"actix-rt", "actix-rt",
"actix-service", "actix-service",
"bitflags", "bitflags",
"bytes", "bytes 0.5.6",
"either", "either",
"futures-channel", "futures-channel",
"futures-sink", "futures-sink",
@ -230,7 +230,7 @@ dependencies = [
"actix-utils", "actix-utils",
"actix-web-codegen", "actix-web-codegen",
"awc", "awc",
"bytes", "bytes 0.5.6",
"derive_more", "derive_more",
"encoding_rs", "encoding_rs",
"futures-channel", "futures-channel",
@ -311,12 +311,29 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "anyhow"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.5.2" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "async-channel"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9"
dependencies = [
"concurrent-queue",
"event-listener",
"futures-core",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.42" version = "0.1.42"
@ -354,7 +371,7 @@ dependencies = [
"actix-rt", "actix-rt",
"actix-service", "actix-service",
"base64 0.13.0", "base64 0.13.0",
"bytes", "bytes 0.5.6",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"derive_more", "derive_more",
"futures-core", "futures-core",
@ -497,15 +514,27 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]]
name = "bytes"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
[[package]] [[package]]
name = "bytestring" name = "bytestring"
version = "0.1.5" version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7c05fa5172da78a62d9949d662d2ac89d4cc7355d7b49adee5163f1fb3f363" checksum = "fc7c05fa5172da78a62d9949d662d2ac89d4cc7355d7b49adee5163f1fb3f363"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
] ]
[[package]]
name = "cache-padded"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba"
[[package]] [[package]]
name = "cargo_metadata" name = "cargo_metadata"
version = "0.12.1" version = "0.12.1"
@ -558,6 +587,15 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "concurrent-queue"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
dependencies = [
"cache-padded",
]
[[package]] [[package]]
name = "config" name = "config"
version = "0.10.1" version = "0.10.1"
@ -658,6 +696,26 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "data-encoding"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "993a608597367c6377b258c25d7120740f00ed23a2252b729b1932dd7866f908"
[[package]]
name = "deadpool"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d126179d86aee4556e54f5f3c6bf6d9884e7cc52cef82f77ee6f90a7747616d"
dependencies = [
"async-trait",
"config",
"crossbeam-queue",
"num_cpus",
"serde",
"tokio 1.0.2",
]
[[package]] [[package]]
name = "derive_more" name = "derive_more"
version = "0.99.11" version = "0.99.11"
@ -739,6 +797,12 @@ dependencies = [
"regex", "regex",
] ]
[[package]]
name = "event-listener"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59"
[[package]] [[package]]
name = "fake" name = "fake"
version = "2.3.0" version = "2.3.0"
@ -754,6 +818,15 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fastrand"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3"
dependencies = [
"instant",
]
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.19" version = "1.0.19"
@ -852,6 +925,21 @@ version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb"
[[package]]
name = "futures-lite"
version = "1.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb"
dependencies = [
"fastrand",
"futures-core",
"futures-io",
"memchr",
"parking",
"pin-project-lite 0.2.0",
"waker-fn",
]
[[package]] [[package]]
name = "futures-macro" name = "futures-macro"
version = "0.3.8" version = "0.3.8"
@ -879,6 +967,12 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "futures-timer"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"
[[package]] [[package]]
name = "futures-util" name = "futures-util"
version = "0.3.8" version = "0.3.8"
@ -984,7 +1078,7 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"fnv", "fnv",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
@ -992,8 +1086,28 @@ dependencies = [
"http", "http",
"indexmap", "indexmap",
"slab", "slab",
"tokio", "tokio 0.2.24",
"tokio-util", "tokio-util 0.3.1",
"tracing",
"tracing-futures",
]
[[package]]
name = "h2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5"
dependencies = [
"bytes 1.0.1",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap",
"slab",
"tokio 1.0.2",
"tokio-util 0.6.1",
"tracing", "tracing",
"tracing-futures", "tracing-futures",
] ]
@ -1067,7 +1181,7 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84129d298a6d57d246960ff8eb831ca4af3f96d29e2e28848dae275408658e26" checksum = "84129d298a6d57d246960ff8eb831ca4af3f96d29e2e28848dae275408658e26"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"fnv", "fnv",
"itoa", "itoa",
] ]
@ -1078,10 +1192,42 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"http", "http",
] ]
[[package]]
name = "http-body"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994"
dependencies = [
"bytes 1.0.1",
"http",
]
[[package]]
name = "http-types"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ab8d0085fb82859c9adf050bd53992297ecdd03a665a230dfa50c8c964bf3d"
dependencies = [
"anyhow",
"async-channel",
"base64 0.13.0",
"cookie",
"futures-lite",
"http",
"infer",
"pin-project-lite 0.1.11",
"rand",
"serde",
"serde_json",
"serde_qs",
"serde_urlencoded",
"url",
]
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.3.4" version = "1.3.4"
@ -1100,19 +1246,43 @@ version = "0.13.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf" checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-util", "futures-util",
"h2", "h2 0.2.7",
"http", "http",
"http-body", "http-body 0.3.1",
"httparse", "httparse",
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project 1.0.2", "pin-project 1.0.2",
"socket2", "socket2",
"tokio", "tokio 0.2.24",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe"
dependencies = [
"bytes 1.0.1",
"futures-channel",
"futures-core",
"futures-util",
"h2 0.3.0",
"http",
"http-body 0.4.0",
"httparse",
"httpdate",
"itoa",
"pin-project 1.0.2",
"socket2",
"tokio 1.0.2",
"tower-service", "tower-service",
"tracing", "tracing",
"want", "want",
@ -1124,12 +1294,12 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6" checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"futures-util", "futures-util",
"hyper", "hyper 0.13.9",
"log", "log",
"rustls", "rustls",
"tokio", "tokio 0.2.24",
"tokio-rustls", "tokio-rustls",
"webpki", "webpki",
] ]
@ -1155,6 +1325,12 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "infer"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64e9829a50b42bb782c1df523f78d332fe371b10c661e78b7a3c34b0198e9fac"
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.9" version = "0.1.9"
@ -1376,12 +1552,25 @@ dependencies = [
"kernel32-sys", "kernel32-sys",
"libc", "libc",
"log", "log",
"miow", "miow 0.2.2",
"net2", "net2",
"slab", "slab",
"winapi 0.2.8", "winapi 0.2.8",
] ]
[[package]]
name = "mio"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7"
dependencies = [
"libc",
"log",
"miow 0.3.6",
"ntapi",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "mio-uds" name = "mio-uds"
version = "0.6.8" version = "0.6.8"
@ -1390,7 +1579,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
dependencies = [ dependencies = [
"iovec", "iovec",
"libc", "libc",
"mio", "mio 0.6.23",
] ]
[[package]] [[package]]
@ -1405,6 +1594,16 @@ dependencies = [
"ws2_32-sys", "ws2_32-sys",
] ]
[[package]]
name = "miow"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897"
dependencies = [
"socket2",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "net2" name = "net2"
version = "0.2.37" version = "0.2.37"
@ -1439,6 +1638,15 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "ntapi"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
dependencies = [
"winapi 0.3.9",
]
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.44" version = "0.1.44"
@ -1492,6 +1700,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.1" version = "0.11.1"
@ -1777,13 +1991,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"bytes", "bytes 0.5.6",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
"futures-util", "futures-util",
"http", "http",
"http-body", "http-body 0.3.1",
"hyper", "hyper 0.13.9",
"hyper-rustls", "hyper-rustls",
"ipnet", "ipnet",
"js-sys", "js-sys",
@ -1797,7 +2011,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"tokio", "tokio 0.2.24",
"tokio-rustls", "tokio-rustls",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
@ -1966,6 +2180,18 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_qs"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5af82de3c6549b001bec34961ff2d6a54339a87bab37ce901b693401f27de6cb"
dependencies = [
"data-encoding",
"percent-encoding",
"serde",
"thiserror",
]
[[package]] [[package]]
name = "serde_urlencoded" name = "serde_urlencoded"
version = "0.7.0" version = "0.7.0"
@ -2104,7 +2330,7 @@ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"bitflags", "bitflags",
"byteorder", "byteorder",
"bytes", "bytes 0.5.6",
"chrono", "chrono",
"crc", "crc",
"crossbeam-channel", "crossbeam-channel",
@ -2175,7 +2401,7 @@ dependencies = [
"actix-rt", "actix-rt",
"actix-threadpool", "actix-threadpool",
"once_cell", "once_cell",
"tokio", "tokio 0.2.24",
"tokio-rustls", "tokio-rustls",
] ]
@ -2384,14 +2610,14 @@ version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48" checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"fnv", "fnv",
"futures-core", "futures-core",
"iovec", "iovec",
"lazy_static", "lazy_static",
"libc", "libc",
"memchr", "memchr",
"mio", "mio 0.6.23",
"mio-uds", "mio-uds",
"num_cpus", "num_cpus",
"pin-project-lite 0.1.11", "pin-project-lite 0.1.11",
@ -2401,6 +2627,20 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "tokio"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec"
dependencies = [
"autocfg",
"bytes 1.0.1",
"libc",
"memchr",
"mio 0.7.7",
"pin-project-lite 0.2.0",
]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "0.2.6" version = "0.2.6"
@ -2420,22 +2660,48 @@ checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"rustls", "rustls",
"tokio", "tokio 0.2.24",
"webpki", "webpki",
] ]
[[package]]
name = "tokio-stream"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd"
dependencies = [
"futures-core",
"pin-project-lite 0.2.0",
"tokio 1.0.2",
]
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.3.1" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499"
dependencies = [ dependencies = [
"bytes", "bytes 0.5.6",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"log", "log",
"pin-project-lite 0.1.11", "pin-project-lite 0.1.11",
"tokio", "tokio 0.2.24",
]
[[package]]
name = "tokio-util"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ae4751faa60b9f96dd8344d74592e5a17c0c9a220413dbc6942d14139bbfcc"
dependencies = [
"bytes 1.0.1",
"futures-core",
"futures-sink",
"log",
"pin-project-lite 0.2.0",
"tokio 1.0.2",
"tokio-stream",
] ]
[[package]] [[package]]
@ -2576,7 +2842,7 @@ dependencies = [
"rand", "rand",
"smallvec", "smallvec",
"thiserror", "thiserror",
"tokio", "tokio 0.2.24",
"url", "url",
] ]
@ -2596,7 +2862,7 @@ dependencies = [
"resolv-conf", "resolv-conf",
"smallvec", "smallvec",
"thiserror", "thiserror",
"tokio", "tokio 0.2.24",
"trust-dns-proto", "trust-dns-proto",
] ]
@ -2679,6 +2945,7 @@ dependencies = [
"idna", "idna",
"matches", "matches",
"percent-encoding", "percent-encoding",
"serde",
] ]
[[package]] [[package]]
@ -2718,6 +2985,12 @@ version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "waker-fn"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
[[package]] [[package]]
name = "want" name = "want"
version = "0.3.0" version = "0.3.0"
@ -2914,6 +3187,26 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "wiremock"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9297d85d701557878bb9b768b048f464874b8c287b1426499f385f804817db1"
dependencies = [
"async-trait",
"deadpool",
"futures",
"futures-timer",
"http-types",
"hyper 0.14.2",
"log",
"once_cell",
"regex",
"serde",
"serde_json",
"tokio 1.0.2",
]
[[package]] [[package]]
name = "ws2_32-sys" name = "ws2_32-sys"
version = "0.2.1" version = "0.2.1"
@ -2955,8 +3248,9 @@ dependencies = [
"reqwest", "reqwest",
"serde", "serde",
"serde-aux", "serde-aux",
"serde_json",
"sqlx", "sqlx",
"tokio", "tokio 0.2.24",
"tracing", "tracing",
"tracing-actix-web", "tracing-actix-web",
"tracing-bunyan-formatter", "tracing-bunyan-formatter",
@ -2966,4 +3260,5 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
"uuid", "uuid",
"validator", "validator",
"wiremock",
] ]

View file

@ -38,3 +38,5 @@ claim = "0.4.0"
quickcheck = "0.9.2" quickcheck = "0.9.2"
quickcheck_macros = "0.9.1" quickcheck_macros = "0.9.1"
fake = "~2.3.0" fake = "~2.3.0"
wiremock = "0.4.7"
serde_json = "1.0.61"

View file

@ -10,3 +10,5 @@ database:
require_ssl: false require_ssl: false
email_client: email_client:
base_url: "localhost" base_url: "localhost"
sender_email: "test@gmail.com"
authorization_token: "my-secret-token"

View file

@ -1,3 +1,4 @@
use crate::domain::SubscriberEmail;
use serde_aux::field_attributes::deserialize_number_from_string; use serde_aux::field_attributes::deserialize_number_from_string;
use sqlx::postgres::{PgConnectOptions, PgSslMode}; use sqlx::postgres::{PgConnectOptions, PgSslMode};
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
@ -50,6 +51,14 @@ impl DatabaseSettings {
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
pub struct EmailClientSettings { pub struct EmailClientSettings {
pub base_url: String, pub base_url: String,
pub sender_email: String,
pub authorization_token: String,
}
impl EmailClientSettings {
pub fn sender(&self) -> Result<SubscriberEmail, String> {
SubscriberEmail::parse(self.sender_email.clone())
}
} }
pub fn get_configuration() -> Result<Settings, config::ConfigError> { pub fn get_configuration() -> Result<Settings, config::ConfigError> {

View file

@ -4,13 +4,17 @@ use reqwest::Client;
pub struct EmailClient { pub struct EmailClient {
http_client: Client, http_client: Client,
base_url: String, base_url: String,
sender: SubscriberEmail,
authorization_token: String,
} }
impl EmailClient { impl EmailClient {
pub fn new(base_url: String) -> Self { pub fn new(base_url: String, sender: SubscriberEmail, authorization_token: String) -> Self {
Self { Self {
http_client: Client::new(), http_client: Client::new(),
base_url, base_url,
sender,
authorization_token,
} }
} }
@ -20,7 +24,89 @@ impl EmailClient {
subject: &str, subject: &str,
html_content: &str, html_content: &str,
text_content: &str, text_content: &str,
) -> Result<(), String> { ) -> Result<(), reqwest::Error> {
todo!() let url = format!("{}/email", self.base_url);
let request_body = SendEmailRequest {
from: self.sender.as_ref().to_owned(),
to: recipient.as_ref().to_owned(),
subject: subject.into(),
html_body: html_content.into(),
text_body: text_content.into(),
};
self.http_client
.post(&url)
.header("X-Postmark-Server-Token", &self.authorization_token)
.json(&request_body)
.send()
.await?;
Ok(())
}
}
#[derive(serde::Serialize)]
#[serde(rename_all = "PascalCase")]
struct SendEmailRequest {
from: String,
to: String,
subject: String,
html_body: String,
text_body: String,
}
#[cfg(test)]
mod tests {
use crate::domain::SubscriberEmail;
use crate::email_client::EmailClient;
use fake::faker::internet::en::SafeEmail;
use fake::faker::lorem::en::{Paragraph, Sentence};
use fake::{Fake, Faker};
use wiremock::matchers::{header, header_exists, method, path};
use wiremock::{Mock, MockServer, Request, ResponseTemplate};
struct SendEmailBodyMatcher;
impl wiremock::Match for SendEmailBodyMatcher {
fn matches(&self, request: &Request) -> bool {
let result: Result<serde_json::Value, _> = serde_json::from_slice(&request.body);
if let Ok(body) = result {
dbg!(&body);
body.get("From").is_some()
&& body.get("To").is_some()
&& body.get("Subject").is_some()
&& body.get("HtmlBody").is_some()
&& body.get("TextBody").is_some()
} else {
false
}
}
}
#[actix_rt::test]
async fn send_email_fires_a_request_to_base_url() {
// Arrange
let mock_server = MockServer::start().await;
let sender = SubscriberEmail::parse(SafeEmail().fake()).unwrap();
let email_client = EmailClient::new(mock_server.uri(), sender, Faker.fake());
let subscriber_email = SubscriberEmail::parse(SafeEmail().fake()).unwrap();
let subject: String = Sentence(1..2).fake();
let content: String = Paragraph(1..10).fake();
Mock::given(header_exists("X-Postmark-Server-Token"))
.and(header("Content-Type", "application/json"))
.and(path("/email"))
.and(method("POST"))
.and(SendEmailBodyMatcher)
.respond_with(ResponseTemplate::new(200))
.expect(1)
.mount(&mock_server)
.await;
// Act
let _ = email_client
.send_email(subscriber_email, &subject, &content, &content)
.await;
// Assert
} }
} }

View file

@ -16,7 +16,16 @@ async fn main() -> std::io::Result<()> {
.connect_with(configuration.database.with_db()) .connect_with(configuration.database.with_db())
.await .await
.expect("Failed to connect to Postgres."); .expect("Failed to connect to Postgres.");
let email_client = EmailClient::new(configuration.email_client.base_url);
let sender_email = configuration
.email_client
.sender()
.expect("Invalid sender email address.");
let email_client = EmailClient::new(
configuration.email_client.base_url,
sender_email,
configuration.email_client.authorization_token,
);
let address = format!( let address = format!(
"{}:{}", "{}:{}",

View file

@ -33,7 +33,16 @@ async fn spawn_app() -> TestApp {
let mut configuration = get_configuration().expect("Failed to read configuration."); let mut configuration = get_configuration().expect("Failed to read configuration.");
configuration.database.database_name = Uuid::new_v4().to_string(); configuration.database.database_name = Uuid::new_v4().to_string();
let connection_pool = configure_database(&configuration.database).await; let connection_pool = configure_database(&configuration.database).await;
let email_client = EmailClient::new(configuration.email_client.base_url);
let sender_email = configuration
.email_client
.sender()
.expect("Invalid sender email address.");
let email_client = EmailClient::new(
configuration.email_client.base_url,
sender_email,
configuration.email_client.authorization_token,
);
let server = let server =
run(listener, connection_pool.clone(), email_client).expect("Failed to bind address"); run(listener, connection_pool.clone(), email_client).expect("Failed to bind address");