diff options
author | Juan J. Martinez <jjm@usebox.net> | 2021-08-31 22:57:23 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2021-08-31 23:04:09 +0100 |
commit | a6bd4cba833bd576c20ca05badc3aa26ce7f0f91 (patch) | |
tree | fe66763fbc353a8ab435b5dfdb4fedad12a42ce2 /server/test/src/ServerSpec.scala | |
parent | c09ffd688c1edd43c545aaf442a1cb582d5ad20d (diff) | |
download | spacebeans-a6bd4cba833bd576c20ca05badc3aa26ce7f0f91.tar.gz spacebeans-a6bd4cba833bd576c20ca05badc3aa26ce7f0f91.zip |
Support to pass env variables to CGIs
Env variables are configured per virtual host.
Diffstat (limited to 'server/test/src/ServerSpec.scala')
-rw-r--r-- | server/test/src/ServerSpec.scala | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/server/test/src/ServerSpec.scala b/server/test/src/ServerSpec.scala index 7a2b501..bd909ca 100644 --- a/server/test/src/ServerSpec.scala +++ b/server/test/src/ServerSpec.scala @@ -455,6 +455,7 @@ class ServerSpec extends AnyFlatSpec with Matchers { "cgi", TestData.host, TestData.portStr, + _, _ ) => } @@ -473,6 +474,7 @@ class ServerSpec extends AnyFlatSpec with Matchers { "cgi", TestData.host, TestData.portStr, + _, _ ) => } @@ -491,6 +493,7 @@ class ServerSpec extends AnyFlatSpec with Matchers { "cgi", TestData.host, TestData.portStr, + _, _ ) => } @@ -509,6 +512,7 @@ class ServerSpec extends AnyFlatSpec with Matchers { "cgi", TestData.host, TestData.portStr, + _, _ ) => } @@ -566,6 +570,57 @@ class ServerSpec extends AnyFlatSpec with Matchers { bad.body should include(meta) } + it should "enviroment variables are optional" in { + Server(TestData.cgiConf).handleReq( + "gemini://localhost/dir/cgi/", + "127.0.0.1" + ) should matchPattern { + case Cgi( + _, + _, + _, + _, + "cgi", + TestData.host, + TestData.portStr, + _, + m + ) if m == Map() => + } + } + + it should "pass enviroment variables to the CGI" in { + Server(TestData.cgiEnvConf).handleReq( + "gemini://localhost/dir/cgi/", + "127.0.0.1" + ) should matchPattern { + case Cgi( + _, + _, + _, + _, + "cgi", + TestData.host, + TestData.portStr, + _, + m + ) if m == Map("env1" -> "value") => + } + } + + it should "execute a CGI with the environment variables" in { + val cgi = Server(TestData.cgiEnvConf) + .handleReq( + "gemini://localhost/dir/cgi", + "127.0.0.1" + ) + .asInstanceOf[Cgi] + + cgi.status should be(20) + cgi.meta should be("text/gemini") + cgi.body should include("env1=value") + } + object TestData { val host = "localhost" @@ -607,6 +662,16 @@ class ServerSpec extends AnyFlatSpec with Matchers { ) ) + val cgiEnvConf = cgiConf.copy(virtualHosts = + List( + cgiConf + .virtualHosts(0) + .copy( + environment = Some(Map("env1" -> "value")) + ) + ) + ) + val confUserDir = conf.copy(virtualHosts = List( conf |