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

mendersoftware / mender / 1583599051

11 Dec 2024 09:04AM UTC coverage: 76.259% (-0.2%) from 76.43%
1583599051

push

gitlab-ci

vpodzime
fix: Cancel the previous request before scheduling a new one in HTTP resumer

The `http::Client()` class is designed to always have only one
HTTP request in progress. Thus, before scheduling a new request
using the same `http::Client` instance, cancel the previous
request to make sure everything is properly reset for the new
one.

Ticket: MEN-7810
Changelog: Fix download resuming to reset the HTTP state and
avoid repeatedly hitting the same error in case of a bad state

Signed-off-by: Vratislav Podzimek <vratislav.podzimek@northern.tech>

1 of 1 new or added line in 1 file covered. (100.0%)

55 existing lines in 11 files now uncovered.

7375 of 9671 relevant lines covered (76.26%)

11182.97 hits per line

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

22.22
/src/mender-auth/ipc/server.hpp
1
// Copyright 2023 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

16
#ifndef MENDER_AUTH_IPC_SERVER_HPP
17
#define MENDER_AUTH_IPC_SERVER_HPP
18

19
#include <functional>
20
#include <string>
21

22
#include <client_shared/conf.hpp>
23
#include <common/platform/dbus.hpp>
24
#include <common/error.hpp>
25
#include <common/events.hpp>
26
#include <common/http.hpp>
27

28
#include <api/api.hpp>
29

30
#include <mender-auth/api/auth.hpp>
31
#include <mender-auth/http_forwarder.hpp>
32

33
namespace mender {
34
namespace auth {
35
namespace ipc {
36

37

38
using namespace std;
39

40
namespace conf = mender::client_shared::conf;
41
namespace crypto = mender::common::crypto;
42
namespace dbus = mender::common::dbus;
43
namespace error = mender::common::error;
44
namespace events = mender::common::events;
45
namespace http = mender::common::http;
46
namespace log = mender::common::log;
47

48
namespace auth_client = mender::auth::api::auth;
49

50
namespace http_forwarder = mender::auth::http_forwarder;
51

52
class AuthenticatingForwarder {
53
public:
54
        AuthenticatingForwarder(events::EventLoop &loop, const conf::MenderConfig &config) :
55
                servers_ {config.servers},
56
                tenant_token_ {config.tenant_token},
57
                client_ {config.GetHttpClientConfig(), loop},
58
                forwarder_ {http::ServerConfig {}, config.GetHttpClientConfig(), loop},
59
                default_identity_script_path_ {config.paths.GetIdentityScript()},
60
                dbus_server_ {loop, "io.mender.AuthenticationManager"} {};
61

62
        error::Error Listen(const crypto::Args &args, const string &identity_script_path = "");
63

64
        string GetServerURL() {
65
                return this->cached_server_url_;
1✔
66
        }
67

68
        string GetJWTToken() {
69
                return this->cached_jwt_token_;
1✔
70
        }
71

UNCOV
72
        void Cache(const string &token, const string &url) {
×
UNCOV
73
                this->cached_jwt_token_ = token;
×
UNCOV
74
                this->cached_server_url_ = url;
×
UNCOV
75
        }
×
76

77
        const http_forwarder::Server &GetForwarder() const {
78
                return forwarder_;
79
        }
80

81
private:
UNCOV
82
        void ClearCache() {
×
UNCOV
83
                Cache("", "");
×
UNCOV
84
        }
×
85

86
        void FetchJwtTokenHandler(auth_client::APIResponse &resp);
87

88
        string cached_jwt_token_;
89
        string cached_server_url_;
90
        bool auth_in_progress_ = false;
91

92
        const vector<string> &servers_;
93
        const string tenant_token_;
94
        http::Client client_;
95
        http_forwarder::Server forwarder_;
96
        string default_identity_script_path_;
97
        dbus::DBusServer dbus_server_;
98
};
99

100
using Server = AuthenticatingForwarder;
101

102
} // namespace ipc
103
} // namespace auth
104
} // namespace mender
105

106

107
#endif // MENDER_AUTH_IPC_SERVER_HPP
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