Page MenuHomePhorge

D162.1732325401.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D162.1732325401.diff

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

Mime Type
text/plain
Expires
Fri, Nov 22, 5:30 PM (3 m, 4 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38904
Default Alt Text
D162.1732325401.diff (2 KB)

Event Timeline