-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixup CfProperty lazy parsing (#1159)
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2017-2022 Cloudflare, Inc. | ||
// Licensed under the Apache 2.0 license found in the LICENSE file or at: | ||
// https://opensource.org/licenses/Apache-2.0 | ||
|
||
#include "cf-property.h" | ||
#include <workerd/jsg/jsg.h> | ||
#include <workerd/tests/test-fixture.h> | ||
|
||
namespace workerd::api { | ||
namespace { | ||
|
||
KJ_TEST("Test that CfProperty is frozen by default") { | ||
TestFixture fixture({ | ||
.mainModuleSource = R"SCRIPT( | ||
export default { | ||
async fetch(request) { | ||
request.cf.foo = 100; | ||
return new Response(`OK`); | ||
}, | ||
}; | ||
)SCRIPT"_kj}); | ||
|
||
try { | ||
auto result = fixture.runRequest(kj::HttpMethod::POST, "http://www.example.com"_kj, "TEST"_kj); | ||
KJ_FAIL_REQUIRE("exception expected"); | ||
} catch (kj::Exception& e) { | ||
KJ_EXPECT(e.getDescription() == "jsg.TypeError: Cannot add property foo, object is not extensible"_kj); | ||
} | ||
} | ||
|
||
|
||
KJ_TEST("Test that CfProperty::deepClone returns editable object") { | ||
TestFixture fixture({ | ||
.mainModuleSource = R"SCRIPT( | ||
export default { | ||
async fetch(request) { | ||
const req = new Request(request); | ||
req.cf.foo = 100; | ||
return new Response(`OK`); | ||
}, | ||
}; | ||
)SCRIPT"_kj}); | ||
auto result = fixture.runRequest(kj::HttpMethod::POST, "http://www.example.com"_kj, "TEST"_kj); | ||
KJ_EXPECT(result.statusCode == 200); | ||
} | ||
|
||
} // namespace | ||
} // namespace workerd::api |
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