-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
zio-http/src/test/scala/zio/http/headers/ClearSiteDataSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2021 - 2023 Sporta Technologies PVT LTD & the ZIO HTTP contributors. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package zio.http.headers | ||
|
||
import zio.Scope | ||
import zio.test._ | ||
|
||
import zio.http.Header.{CacheControl, ClearSiteData, ClearSiteDataDirective} | ||
import zio.http.ZIOHttpSpec | ||
import zio.http.internal.HttpGen | ||
|
||
object ClearSiteDataSpec extends ZIOHttpSpec { | ||
override def spec: Spec[TestEnvironment with Scope, Any] = suite("ClearSiteData suite")( | ||
test("ClearSiteData header value transformation should be symmetrical") { | ||
check(HttpGen.clearSiteData) { value => | ||
assertTrue(ClearSiteData.parse(ClearSiteData.render(value)) == Right(value)) | ||
} | ||
}, | ||
test("Unquoted ClearSiteData header value should not parse") { | ||
val headerValue = "cache, cookies, storage, executionContexts" | ||
assertTrue(ClearSiteData.parse(headerValue) == Left("Invalid Clear-Site-Data header")) | ||
}, | ||
) | ||
} |
62 changes: 62 additions & 0 deletions
62
zio-http/src/test/scala/zio/http/headers/ForwardedSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2021 - 2023 Sporta Technologies PVT LTD & the ZIO HTTP contributors. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package zio.http.headers | ||
|
||
import zio.Scope | ||
import zio.test._ | ||
|
||
import zio.http.{Header, ZIOHttpSpec} | ||
|
||
object ForwardedSpec extends ZIOHttpSpec { | ||
override def spec: Spec[TestEnvironment with Scope, Any] = suite("Forwarded suite")( | ||
test("parse Forwarded header") { | ||
val headerValue = """for="[2001:db8:cafe::17]:4711"""" | ||
val header = Header.Forwarded(forValues = List(""""[2001:db8:cafe::17]:4711"""")) | ||
assertTrue(Header.Forwarded.parse(headerValue) == Right(header)) | ||
}, | ||
test("parse Forwarded header with multiple for values") { | ||
val headerValue = """for="[2001:db8:cafe::17]:4711", for=192.0.0.25""" | ||
val header = Header.Forwarded(forValues = List(""""[2001:db8:cafe::17]:4711"""", "192.0.0.25")) | ||
assertTrue(Header.Forwarded.parse(headerValue) == Right(header)) | ||
}, | ||
test("parse Forwarded header with by") { | ||
val headerValue = """for="[2001:db8:cafe::17]:4711";by=_value""" | ||
val header = Header.Forwarded(forValues = List(""""[2001:db8:cafe::17]:4711""""), by = Some("_value")) | ||
assertTrue(Header.Forwarded.parse(headerValue) == Right(header)) | ||
}, | ||
test("parse Forwarded header with host") { | ||
val headerValue = """for="[2001:db8:cafe::17]:4711";host=example.com""" | ||
val header = Header.Forwarded(forValues = List(""""[2001:db8:cafe::17]:4711""""), host = Some("example.com")) | ||
assertTrue(Header.Forwarded.parse(headerValue) == Right(header)) | ||
}, | ||
test("parse Forwarded header with proto") { | ||
val headerValue = """for="[2001:db8:cafe::17]:4711";proto=https""" | ||
val header = Header.Forwarded(forValues = List(""""[2001:db8:cafe::17]:4711""""), proto = Some("https")) | ||
assertTrue(Header.Forwarded.parse(headerValue) == Right(header)) | ||
}, | ||
test("parse Forwarded header with all attributes") { | ||
val headerValue = """for="[2001:db8:cafe::17]:4711";by=_value;host=example.com;proto=https""" | ||
val header = Header.Forwarded( | ||
forValues = List(""""[2001:db8:cafe::17]:4711""""), | ||
by = Some("_value"), | ||
host = Some("example.com"), | ||
proto = Some("https"), | ||
) | ||
assertTrue(Header.Forwarded.parse(headerValue) == Right(header)) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2021 - 2023 Sporta Technologies PVT LTD & the ZIO HTTP contributors. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package zio.http.headers | ||
|
||
import java.net.URI | ||
|
||
import zio.Scope | ||
import zio.test._ | ||
|
||
import zio.http.Header.ClearSiteData | ||
import zio.http.internal.HttpGen | ||
import zio.http.{Header, URL, ZIOHttpSpec} | ||
|
||
object LinkSpec extends ZIOHttpSpec { | ||
override def spec: Spec[TestEnvironment with Scope, Any] = suite("Link suite")( | ||
test("Parse links in the form of <uri>") { | ||
val headerValue = "<https://example.com/TheBook/chapter2>; rel=\"previous\"" | ||
val uri = URL.decode("https://example.com/TheBook/chapter2").getOrElse(throw new Exception("Invalid URL")) | ||
assertTrue(Header.Link.parse(headerValue) == Right(Header.Link(uri, Map("rel" -> "previous")))) | ||
}, | ||
test("Fail to parse links without a URI") { | ||
val headerValue = "rel=\"previous\"" | ||
assertTrue(Header.Link.parse(headerValue) == Left("Invalid Link header")) | ||
}, | ||
test("Fail to parse links without pointy brackets") { | ||
val headerValue = "https://example.com/TheBook/chapter2; rel=\"previous\"" | ||
assertTrue(Header.Link.parse(headerValue) == Left("Invalid Link header")) | ||
}, | ||
test("Parse links with multiple parameters") { | ||
val headerValue = "<https://example.com/TheBook/chapter2>; rel=\"previous\"; title=\"previous chapter\"" | ||
val uri = URL.decode("https://example.com/TheBook/chapter2").getOrElse(throw new Exception("Invalid URL")) | ||
assertTrue( | ||
Header.Link.parse(headerValue) == Right( | ||
Header.Link(uri, Map("rel" -> "previous", "title" -> "previous chapter")), | ||
), | ||
) | ||
}, | ||
test("Parse links with multiple parameters and spaces") { | ||
val headerValue = "<https://example.com/TheBook/chapter2>; rel=\"previous\"; title=\"previous chapter\"" | ||
val uri = URL.decode("https://example.com/TheBook/chapter2").getOrElse(throw new Exception("Invalid URL")) | ||
assertTrue( | ||
Header.Link.parse(headerValue) == Right( | ||
Header.Link(uri, Map("rel" -> "previous", "title" -> "previous chapter")), | ||
), | ||
) | ||
}, | ||
test("Parse unquoted parameters") { | ||
val headerValue = "<https://example.com/TheBook/chapter2>; rel=previous; title=previous chapter" | ||
val uri = URL.decode("https://example.com/TheBook/chapter2").getOrElse(throw new Exception("Invalid URL")) | ||
assertTrue( | ||
Header.Link.parse(headerValue) == Right( | ||
Header.Link(uri, Map("rel" -> "previous", "title" -> "previous chapter")), | ||
), | ||
) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters