| 184 | SC_TEST_EXPECT(roundTrip.name == "id"); |
| 185 | SC_TEST_EXPECT(roundTrip.value == "42"); |
| 186 | SC_TEST_EXPECT(roundTrip.path == "/app"); |
| 187 | SC_TEST_EXPECT(roundTrip.domain == "example.com"); |
| 188 | SC_TEST_EXPECT(roundTrip.maxAge == "3600"); |
| 189 | SC_TEST_EXPECT(roundTrip.secure); |
| 190 | SC_TEST_EXPECT(roundTrip.httpOnly); |
| 191 | SC_TEST_EXPECT(roundTrip.sameSite == "Strict"); |
| 192 | |
| 193 | SC_TEST_EXPECT(resultHasHttpError(builder.writeTo({storage, 4}, output), HttpError::SetCookieOutputTooSmall)); |
| 194 | SC_TEST_EXPECT(output.isEmpty()); |
| 195 | SC_TEST_EXPECT(resultHasHttpError(cookie.parse(""), HttpError::SetCookieHeaderEmpty)); |
| 196 | SC_TEST_EXPECT(resultHasHttpError(cookie.parse("=missing-name"), HttpError::SetCookieNameEmpty)); |
| 197 | SC_TEST_EXPECT(resultHasHttpError(cookie.parse("missing-value"), HttpError::SetCookieNameValueMissing)); |
| 198 | builder.name = {}; |
| 199 | SC_TEST_EXPECT(resultHasHttpError(builder.writeTo(storage, output), HttpError::SetCookieNameEmpty)); |
| 200 | } |
| 201 | |
| 202 | void HttpHeadersTest::headerBuilders() |
| 203 | { |
| 204 | SC_TEST_EXPECT(HttpContentTypeTextPlainUtf8() == "text/plain; charset=utf-8"); |
| 205 | SC_TEST_EXPECT(HttpContentTypeTextHtmlUtf8() == "text/html; charset=utf-8"); |
| 206 | SC_TEST_EXPECT(HttpContentTypeApplicationJson() == "application/json"); |
| 207 | SC_TEST_EXPECT(HttpContentTypeApplicationOctetStream() == "application/octet-stream"); |
| 208 | |
| 209 | char storage[128]; |
| 210 | StringSpan output; |
| 211 | |
| 212 | HttpCacheControlBuilder cache; |
| 213 | cache.publicCache = true; |
| 214 | cache.hasMaxAge = true; |
| 215 | cache.maxAgeSeconds = 3600; |
| 216 | cache.mustRevalidate = true; |
| 217 | cache.immutable = true; |
| 218 | SC_TEST_EXPECT(cache.writeTo({storage, sizeof(storage)}, output)); |
| 219 | SC_TEST_EXPECT(output == "public, max-age=3600, must-revalidate, immutable"); |
| 220 | |
| 221 | cache = {}; |
| 222 | cache.noStore = true; |
| 223 | SC_TEST_EXPECT(cache.writeTo({storage, sizeof(storage)}, output)); |
| 224 | SC_TEST_EXPECT(output == "no-store"); |
| 225 | |
| 226 | cache = {}; |
| 227 | cache.publicCache = true; |
| 228 | cache.privateCache = true; |
| 229 | SC_TEST_EXPECT(resultHasHttpError(cache.writeTo(storage, output), HttpError::CacheControlConflictingVisibility)); |
| 230 | SC_TEST_EXPECT(output.isEmpty()); |
| 231 | |
| 232 | cache = {}; |
| 233 | cache.hasMaxAge = true; |
| 234 | cache.maxAgeSeconds = 42; |
| 235 | SC_TEST_EXPECT(resultHasHttpError(cache.writeTo({storage, 8}, output), HttpError::CacheControlOutputTooSmall)); |
| 236 | SC_TEST_EXPECT(output.isEmpty()); |
| 237 | cache = {}; |
| 238 | SC_TEST_EXPECT(resultHasHttpError(cache.writeTo(storage, output), HttpError::CacheControlNoDirectives)); |
| 239 | SC_TEST_EXPECT(output.isEmpty()); |
| 240 | |
| 241 | SC_TEST_EXPECT(HttpWriteBearerAuthorization("token", {storage, sizeof(storage)}, output)); |
| 242 | SC_TEST_EXPECT(output == "Bearer token"); |
| 243 | SC_TEST_EXPECT(HttpWriteBasicAuthorization("dXNlcjpwYXNz", {storage, sizeof(storage)}, output)); |
nothing calls this directly
no test coverage detected