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

realm / realm-core / jonathan.reams_3577

21 Jan 2025 05:41PM UTC coverage: 91.105% (-0.02%) from 91.124%
jonathan.reams_3577

Pull #8064

Evergreen

jbreams
fix test
Pull Request #8064: Sync access token refreshes shouldn't extend SyncSession lifetime

102714 of 181514 branches covered (56.59%)

73 of 73 new or added lines in 3 files covered. (100.0%)

109 existing lines in 18 files now uncovered.

217338 of 238558 relevant lines covered (91.1%)

5558106.05 hits per line

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

81.18
/src/realm/sync/noinst/server/server_dir.cpp
1
#include <locale>
2

3
#include <realm/sync/noinst/server/server_dir.hpp>
4

5
using namespace realm;
6

7
namespace {
8

9
bool valid_virt_path_segment(const std::string& seg)
10
{
6,614✔
11
    if (seg.empty())
6,614✔
12
        return false;
20✔
13
    // Prevent `.`, `..`, and `.foo` (hidden files)
14
    if (seg.front() == '.')
6,594✔
15
        return false;
44✔
16
    // Prevent spurious clashes between directory names and file names
17
    // created by appending `.realm`, `.realm.lock`, or `.realm.management`
18
    // to the last component of client specified virtual paths.
19
    bool possible_clash = (StringData(seg).ends_with(".realm") || StringData(seg).ends_with(".realm.lock") ||
6,550✔
20
                           StringData(seg).ends_with(".realm.management"));
6,550✔
21
    if (possible_clash)
6,550✔
22
        return false;
16✔
23
    std::locale c_loc = std::locale::classic();
6,534✔
24
    for (char ch : seg) {
34,580✔
25
        if (std::isalnum(ch, c_loc)) // A-Za-z0-9
34,580✔
26
            continue;
33,488✔
27
        if (ch == '_' || ch == '-' || ch == '.' || ch == '"')
1,092✔
28
            continue;
1,064✔
29
        return false;
28✔
30
    }
1,092✔
31
    return true;
6,506✔
32
}
6,534✔
33

34
} // unnamed namespace
35

36

37
_impl::VirtualPathComponents _impl::parse_virtual_path(const std::string& root_path, const std::string& virt_path)
38
{
6,416✔
39
    VirtualPathComponents result;
6,416✔
40
    if (virt_path.empty())
6,416✔
41
        return result;
4✔
42

43
    std::string real_path = root_path;
6,412✔
44
    size_t prev_pos = 0;
6,412✔
45
    if (virt_path.front() != '/') {
6,412✔
46
        --prev_pos;
974✔
47
        real_path += '/';
974✔
48
    }
974✔
49
    for (;;) {
6,616✔
50
        ++prev_pos; // Skip previous slash
6,616✔
51
        size_t pos = virt_path.find('/', prev_pos);
6,616✔
52
        bool last = (pos == std::string::npos);
6,616✔
53
        if (last)
6,616✔
54
            pos = virt_path.size();
6,400✔
55
        std::string segment = virt_path.substr(prev_pos, pos - prev_pos);
6,616✔
56
        // Parition key style paths will be surrounded in quotes, which Windows
57
        // doesn't allow in paths.
58
        segment.erase(std::remove(segment.begin(), segment.end(), '"'), segment.end());
6,616✔
59

60
        if (!valid_virt_path_segment(segment))
6,616✔
61
            return result;
108✔
62

63
        real_path = util::File::resolve(segment, real_path);
6,508✔
64
        if (last)
6,508✔
65
            break;
6,304✔
66
        prev_pos = pos;
204✔
67
    }
204✔
68
    result.is_valid = true;
6,304✔
69
    result.real_realm_path = real_path + ".realm";
6,304✔
70
    return result;
6,304✔
71
}
6,412✔
72

73

74
bool _impl::map_virt_to_real_realm_path(const std::string& root_path, const std::string& virt_path,
75
                                        std::string& real_path)
76
{
72✔
77
    VirtualPathComponents result = parse_virtual_path(root_path, virt_path); // Throws
72✔
78
    if (result.is_valid) {
72✔
79
        real_path = std::move(result.real_realm_path);
72✔
80
        return true;
72✔
81
    }
72✔
82
    return false;
×
83
}
72✔
84

85

86
bool _impl::map_partial_to_reference_virt_path(const std::string& partial_path, std::string& reference_path)
87
{
×
88
    std::string root_path = "";                                                 // Immaterial
×
89
    VirtualPathComponents result = parse_virtual_path(root_path, partial_path); // Throws
×
90
    if (result.is_valid && result.is_partial_view) {
×
91
        reference_path = std::move(result.reference_path);
×
92
        return true;
×
93
    }
×
94
    return false;
×
95
}
×
96

97

98
void _impl::make_dirs(const std::string& root_path, const std::string& virt_path)
99
{
1,142✔
100
    REALM_ASSERT(!virt_path.empty());
1,142✔
101
    size_t prev_pos = 0;
1,142✔
102
    std::string real_path = root_path;
1,142✔
103
    if (virt_path.front() != '/') {
1,142✔
104
        real_path += '/';
418✔
105
        --prev_pos;
418✔
106
    }
418✔
107
    for (;;) {
1,142✔
108
        ++prev_pos; // Skip previous slash
1,142✔
109
        size_t pos = virt_path.find('/', prev_pos);
1,142✔
110
        if (pos == std::string::npos)
1,142✔
111
            break;
1,142✔
UNCOV
112
        std::string name = virt_path.substr(prev_pos, pos - prev_pos);
×
UNCOV
113
        REALM_ASSERT(valid_virt_path_segment(name));
×
UNCOV
114
        real_path = util::File::resolve(name, real_path);
×
UNCOV
115
        util::try_make_dir(real_path);
×
UNCOV
116
        prev_pos = pos;
×
UNCOV
117
    }
×
118
}
1,142✔
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