Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113985
D162.1732499735.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D162.1732499735.diff
View Options
diff --git a/src/base/types.hpp b/src/base/types.hpp
--- a/src/base/types.hpp
+++ b/src/base/types.hpp
@@ -63,6 +63,17 @@
}
};
+ template<>
+ struct AddToJsonIfNeededT<JsonWrap>
+ {
+ template<class T>
+ static void call(json &j, std::string name, T &&arg) {
+ if (!arg.get().is_null()) {
+ j[name] = std::forward<T>(arg).get();
+ }
+ }
+ };
+
}
template<class T>
diff --git a/src/tests/base/types-test.cpp b/src/tests/base/types-test.cpp
--- a/src/tests/base/types-test.cpp
+++ b/src/tests/base/types-test.cpp
@@ -51,3 +51,18 @@
j = m;
REQUIRE(j.is_array());
}
+
+TEST_CASE("addToJsonIfNeeded", "[base][types]")
+{
+ json j = json::object();
+ WHEN("default-constructed JsonWrap") {
+ addToJsonIfNeeded(j, "a", JsonWrap());
+ REQUIRE(!j.contains("a"));
+ }
+
+ WHEN("non-default-constructed JsonWrap") {
+ addToJsonIfNeeded(j, "a", JsonWrap(json::object({{"mew", 1}})));
+ REQUIRE(j.contains("a"));
+ REQUIRE(j.at("a") == json::object({{"mew", 1}}));
+ }
+}
diff --git a/src/tests/client/keys-test.cpp b/src/tests/client/keys-test.cpp
--- a/src/tests/client/keys-test.cpp
+++ b/src/tests/client/keys-test.cpp
@@ -1,6 +1,6 @@
/*
* This file is part of libkazv.
- * SPDX-FileCopyrightText: 2022 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2022-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@@ -9,10 +9,12 @@
#include <catch2/catch_all.hpp>
#include <client-model.hpp>
-
+#include <actions/encryption.hpp>
#include "client-test-util.hpp"
+#include "factory.hpp"
using namespace Kazv;
+using namespace Kazv::Factory;
TEST_CASE("Query keys", "[client][keys]")
{
@@ -34,3 +36,17 @@
}
}
}
+
+TEST_CASE("Upload identity keys", "[client][keys]")
+{
+ auto m = makeClient(withCrypto(makeCrypto()));
+ auto [next, _] = updateClient(m, UploadIdentityKeysAction{});
+
+ assert1Job(next);
+ for1stJob(next, [](const BaseJob &job) {
+ auto body = json::parse(std::get<BytesBody>(job.requestBody()));
+ REQUIRE(!body.contains("one_time_keys"));
+ REQUIRE(!body.contains("fallback_keys"));
+ REQUIRE(body.contains("device_keys"));
+ });
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 5:55 PM (8 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39924
Default Alt Text
D162.1732499735.diff (2 KB)
Attached To
Mode
D162: Do not add an optional null json value to request body
Attached
Detach File
Event Timeline
Log In to Comment