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

mendersoftware / mender / 1332919177

14 Jun 2024 02:53PM UTC coverage: 75.535% (+0.001%) from 75.534%
1332919177

push

gitlab-ci

web-flow
Merge pull request #1637 from kacf/direct_linking

feat: Implement support for compiling without DBus.

47 of 60 new or added lines in 2 files covered. (78.33%)

3 existing lines in 3 files now uncovered.

7058 of 9344 relevant lines covered (75.54%)

11667.04 hits per line

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

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

15
#include <api/auth.hpp>
16

17
#include <string>
18
#include <vector>
19

20
#include <common/common.hpp>
21
#include <common/error.hpp>
22
#include <common/log.hpp>
23
#include <common/expected.hpp>
24

25
namespace mender {
26
namespace api {
27
namespace auth {
28

29

30
using namespace std;
31
namespace error = mender::common::error;
32
namespace common = mender::common;
33

34

35
namespace mlog = mender::common::log;
36
namespace expected = mender::common::expected;
37

38
error::Error AuthenticatorDBus::StartWatchingTokenSignal() {
22✔
39
        if (watching_token_signal_) {
22✔
40
                return error::NoError;
10✔
41
        }
42

43
        auto err = dbus_client_.RegisterSignalHandler<dbus::ExpectedStringPair>(
44
                "io.mender.Authentication1",
45
                "JwtTokenStateChange",
46
                [this](dbus::ExpectedStringPair ex_auth_dbus_data) {
4✔
47
                        HandleReceivedToken(ex_auth_dbus_data, NoTokenAction::Finish);
4✔
48
                });
28✔
49

50
        watching_token_signal_ = (err == error::NoError);
12✔
51
        return err;
12✔
52
}
53

54
error::Error AuthenticatorDBus::GetJwtToken() {
15✔
55
        // Try to get token from mender-auth
56
        return dbus_client_.CallMethod<dbus::ExpectedStringPair>(
57
                "io.mender.AuthenticationManager",
58
                "/io/mender/AuthenticationManager",
59
                "io.mender.Authentication1",
60
                "GetJwtToken",
61
                [this](dbus::ExpectedStringPair ex_auth_dbus_data) {
15✔
62
                        HandleReceivedToken(ex_auth_dbus_data, NoTokenAction::RequestNew);
15✔
63
                });
45✔
64
}
65

66
error::Error AuthenticatorDBus::FetchJwtToken() {
29✔
67
        return dbus_client_.CallMethod<expected::ExpectedBool>(
68
                "io.mender.AuthenticationManager",
69
                "/io/mender/AuthenticationManager",
70
                "io.mender.Authentication1",
71
                "FetchJwtToken",
72
                [this](expected::ExpectedBool ex_value) {
6✔
73
                        if (!ex_value) {
6✔
NEW
74
                                token_fetch_in_progress_ = false;
×
NEW
75
                                mlog::Error("Failed to request new token fetching: " + ex_value.error().String());
×
NEW
76
                                ExpectedAuthData ex_auth_data = expected::unexpected(ex_value.error());
×
NEW
77
                                PostPendingActions(ex_auth_data);
×
78
                        } else if (!ex_value.value()) {
6✔
79
                                // mender-auth encountered an error not sent over DBus (should never happen)
NEW
80
                                token_fetch_in_progress_ = false;
×
NEW
81
                                mlog::Error(
×
NEW
82
                                        "Failed to request new token fetching (see mender-auth logs for details)");
×
NEW
83
                                ExpectedAuthData ex_auth_data = expected::unexpected(MakeError(
×
NEW
84
                                        AuthenticationError, "Failed to request new token fetching from mender-auth"));
×
NEW
85
                                PostPendingActions(ex_auth_data);
×
86
                        }
87
                });
64✔
88
}
89

90
} // namespace auth
91
} // namespace api
92
} // namespace mender
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

© 2026 Coveralls, Inc