• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / github_pull_request_312964

19 Feb 2025 07:31PM UTC coverage: 90.814% (-0.3%) from 91.119%
github_pull_request_312964

Pull #8071

Evergreen

web-flow
Bump serialize-javascript and mocha

Bumps [serialize-javascript](https://github.com/yahoo/serialize-javascript) to 6.0.2 and updates ancestor dependency [mocha](https://github.com/mochajs/mocha). These dependencies need to be updated together.


Updates `serialize-javascript` from 6.0.0 to 6.0.2
- [Release notes](https://github.com/yahoo/serialize-javascript/releases)
- [Commits](https://github.com/yahoo/serialize-javascript/compare/v6.0.0...v6.0.2)

Updates `mocha` from 10.2.0 to 10.8.2
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mochajs/mocha/compare/v10.2.0...v10.8.2)

---
updated-dependencies:
- dependency-name: serialize-javascript
  dependency-type: indirect
- dependency-name: mocha
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #8071: Bump serialize-javascript and mocha

96552 of 179126 branches covered (53.9%)

212672 of 234185 relevant lines covered (90.81%)

3115802.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.26
/test/object-store/util/test_utils.cpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2016 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#include <util/test_utils.hpp>
20

21
#include <realm/string_data.hpp>
22
#include <realm/object-store/impl/realm_coordinator.hpp>
23
#include <realm/util/base64.hpp>
24
#include <realm/util/demangle.hpp>
25
#include <realm/util/file.hpp>
26

27
#include <external/json/json.hpp>
28

29
#include <iostream>
30
#include <random>
31
#include <sys/stat.h>
32

33
#ifndef _WIN32
34
#include <unistd.h>
35
#include <sys/types.h>
36
#endif
37

38
#if REALM_PLATFORM_APPLE
39
#include <sys/mount.h>
40
#include <sys/param.h>
41
#endif
42

43
namespace realm {
44

45
bool ExceptionMatcher<void>::match(Exception const& ex) const
46
{
1,305✔
47
    return ex.code() == m_code && ex.what() == m_message;
1,305✔
48
}
1,305✔
49

50
std::string ExceptionMatcher<void>::describe() const
51
{
×
52
    return util::format("Exception(%1, \"%2\")", ErrorCodes::error_string(m_code), m_message);
×
53
}
×
54

55
bool OutOfBoundsMatcher::match(OutOfBounds const& ex) const
56
{
105✔
57
    return ex.code() == ErrorCodes::OutOfBounds && ex.index == m_index && ex.size == m_size && ex.what() == m_message;
105✔
58
}
105✔
59

60
std::string OutOfBoundsMatcher::describe() const
61
{
×
62
    return util::format("OutOfBounds(index=%1, size=%2, \"%3\")", m_index, m_size, m_message);
×
63
}
×
64

65
bool LogicErrorMatcher::match(LogicError const& ex) const
66
{
7✔
67
    return ex.code() == m_code;
7✔
68
}
7✔
69

70
std::string LogicErrorMatcher::describe() const
71
{
×
72
    return util::format("LogicError(%1)", ErrorCodes::error_string(m_code));
×
73
}
×
74

75
std::ostream& operator<<(std::ostream& os, const Exception& e)
76
{
×
77
    os << util::get_type_name(e) << "(" << e.code_string() << ", \"" << e.what() << "\")";
×
78
    return os;
×
79
}
×
80

81
void create_dummy_realm(std::string path, std::shared_ptr<Realm>* out)
82
{
7✔
83
    Realm::Config config;
7✔
84
    config.path = path;
7✔
85
    auto realm = _impl::RealmCoordinator::get_coordinator(path)->get_realm(config, none);
7✔
86
    REQUIRE_REALM_EXISTS(path);
7!
87
    if (out) {
7✔
88
        *out = std::move(realm);
×
89
    }
×
90
}
7✔
91

92
std::vector<char> make_test_encryption_key(const char start)
93
{
12✔
94
    std::vector<char> vector;
12✔
95
    vector.reserve(64);
12✔
96
    for (int i = 0; i < 64; i++) {
780✔
97
        vector.emplace_back((start + i) % 128);
768✔
98
    }
768✔
99
    return vector;
12✔
100
}
12✔
101

102
// FIXME: Catch2 limitation on old compilers (currently our android CI)
103
// https://github.com/catchorg/Catch2/blob/master/docs/limitations.md#clangg----skipping-leaf-sections-after-an-exception
104
void catch2_ensure_section_run_workaround(bool did_run_a_section, std::string section_name,
105
                                          util::FunctionRef<void()> func)
106
{
14✔
107
    if (did_run_a_section) {
14✔
108
        func();
14✔
109
    }
14✔
110
    else {
×
111
        std::cout << "Skipping test section '" << section_name << "' on this run." << std::endl;
×
112
    }
×
113
}
14✔
114

115
std::string encode_fake_jwt(const std::string& in, util::Optional<int64_t> exp, util::Optional<int64_t> iat)
116
{
65✔
117
    // by default make a valid expiry time so that the sync session pre check
118
    // doesn't trigger a token refresh on first open
119
    using namespace std::chrono_literals;
65✔
120
    if (!exp) {
65✔
121
        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
10✔
122
        exp = std::chrono::system_clock::to_time_t(now + 60min);
10✔
123
    }
10✔
124
    if (!iat) {
65✔
125
        std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
11✔
126
        iat = std::chrono::system_clock::to_time_t(now - 1s);
11✔
127
    }
11✔
128

129
    std::string unencoded_prefix = nlohmann::json({"alg", "HS256"}).dump();
65✔
130
    std::string unencoded_body =
65✔
131
        nlohmann::json(
65✔
132
            {{"user_data", {{"token", in}}}, {"exp", *exp}, {"iat", *iat}, {"access", {"download", "upload"}}})
65✔
133
            .dump();
65✔
134

135
    std::string encoded_prefix, encoded_body;
65✔
136
    encoded_prefix.resize(util::base64_encoded_size(unencoded_prefix.size()));
65✔
137
    encoded_body.resize(util::base64_encoded_size(unencoded_body.size()));
65✔
138
    util::base64_encode(unencoded_prefix, encoded_prefix);
65✔
139
    util::base64_encode(unencoded_body, encoded_body);
65✔
140
    std::string suffix = "Et9HFtf9R3GEMA0IICOfFMVXY7kkTX1wr4qCyhIf58U";
65✔
141
    return encoded_prefix + "." + encoded_body + "." + suffix;
65✔
142
}
65✔
143

144
std::string random_string(std::string::size_type length)
145
{
16,539✔
146
    static auto& chrs = "abcdefghijklmnopqrstuvwxyz"
16,539✔
147
                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
16,539✔
148
    thread_local static std::mt19937 rg{std::random_device{}()};
16,539✔
149
    thread_local static std::uniform_int_distribution<std::string::size_type> pick(0, sizeof(chrs) - 2);
16,539✔
150
    std::string s;
16,539✔
151
    s.reserve(length);
16,539✔
152
    while (length--)
118,196,294✔
153
        s += chrs[pick(rg)];
118,179,755✔
154
    return s;
16,539✔
155
}
16,539✔
156

157
int64_t random_int()
158
{
14,436✔
159
    thread_local std::mt19937_64 rng(std::random_device{}());
14,436✔
160
    return rng();
14,436✔
161
}
14,436✔
162

163
static bool file_is_on_exfat(const std::string& path)
164
{
×
165
#if REALM_PLATFORM_APPLE
166
    if (path.empty())
167
        return false;
168

169
    struct statfs fsbuf;
170
    int ret = statfs(path.c_str(), &fsbuf);
171
    REALM_ASSERT_RELEASE(ret == 0);
172
    // The documentation and headers helpfully don't list any of the values of
173
    // f_type or provide constants for them
174
    return fsbuf.f_type == 28 /* exFAT */;
175
#else
176
    static_cast<void>(path);
×
177
    return false;
×
178
#endif
×
179
}
×
180

181
bool chmod_supported(const std::string& path)
182
{
×
183
#ifndef _WIN32
×
184
    if (getuid() == 0) {
×
185
        return false; // running as root
×
186
    }
×
187
    if (file_is_on_exfat(path)) {
×
188
        return false;
×
189
    }
×
190
    return true;
×
191
#else
192
    static_cast<void>(path);
193
    return false;
194
#endif
195
}
×
196

197
int get_permissions(const std::string& path)
198
{
×
199
    int perms = 0;
×
200
#ifndef _WIN32
×
201
    REALM_ASSERT(!path.empty());
×
202
    struct stat statbuf;
×
203
    int ret = ::stat(path.c_str(), &statbuf);
×
204
    REALM_ASSERT_EX(ret == 0, ret, errno);
×
205
    perms = statbuf.st_mode;
×
206
#else
207
    static_cast<void>(path);
208
#endif
209
    return perms;
×
210
}
×
211

212
void chmod(const std::string& path, int permissions)
213
{
×
214
#ifndef _WIN32
×
215
    int ret = ::chmod(path.c_str(), permissions);
×
216
    REALM_ASSERT_EX(ret == 0, ret, errno);
×
217
#else
218
    static_cast<void>(path);
219
    static_cast<void>(permissions);
220
#endif
221
}
×
222

223
} // namespace realm
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc