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

mendersoftware / mender / 1019238693

28 Sep 2023 06:41AM UTC coverage: 77.563% (-0.5%) from 78.091%
1019238693

push

gitlab-ci

kacf
chore: Send 501 to client when server tries unsupported protocol switch.

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

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

6696 of 8633 relevant lines covered (77.56%)

10658.93 hits per line

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

0.0
/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_CLIENT_HPP
17
#define MENDER_AUTH_CLIENT_HPP
18

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

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

28
#include <api/api.hpp>
29
#include <api/auth.hpp>
30

31
namespace mender {
32
namespace auth {
33
namespace ipc {
34

35

36
using namespace std;
37

38
namespace auth_client = mender::api::auth;
39
namespace conf = mender::common::conf;
40
namespace error = mender::common::error;
41
namespace events = mender::common::events;
42
namespace log = mender::common::log;
43
namespace path = mender::common::path;
44

45

46
namespace type {
47
namespace webserver {
48

49
class Caching {
50
public:
51
        Caching(events::EventLoop &loop, const conf::MenderConfig &config) :
×
52
                server_url_ {config.server_url},
×
53
                tenant_token_ {config.tenant_token},
×
54
                client_config_ {
55
                        config.server_certificate, config.https_client.certificate, config.https_client.key},
×
56
                client_ {client_config_, loop},
×
57
                server_config_ {},
58
                server_ {server_config_, loop},
×
59
                default_identity_script_path_ {config.paths.GetIdentityScript()} {};
×
60

61
        Caching(Caching &&) = default;
62

63
        error::Error Listen(
64
                const string &server_url,
65
                const string &identity_script_path = "",
66
                const string &private_key_path = "");
67

68
        string GetServerURL() {
69
                return this->cached_server_url_;
70
        }
71

72
        string GetJWTToken() {
73
                return this->cached_jwt_token_;
74
        }
75

76
        void Cache(const string &token, const string &url) {
77
                this->cached_jwt_token_ = token;
78
                this->cached_server_url_ = url;
79
        }
80

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

86
        void CacheAPIResponse(const string &server_url, auth_client::APIResponse resp) {
87
                if (resp) {
88
                        Cache(resp.value(), server_url);
89
                        return;
90
                }
91
                ClearCache();
92
        };
93

94
        string cached_jwt_token_;
95
        string cached_server_url_;
96

97
        const string server_url_;
98
        const string tenant_token_;
99
        http::ClientConfig client_config_;
100
        http::Client client_;
101
        http::ServerConfig server_config_;
102
        http::Server server_;
103
        string default_identity_script_path_;
104
};
105

106
} // namespace webserver
107
} // namespace type
108

109
using Server = type::webserver::Caching;
110

111
} // namespace ipc
112
} // namespace auth
113
} // namespace mender
114

115

116
#endif // MENDER_AUTH_CLIENT_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