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

mendersoftware / mender / 957728569

pending completion
957728569

push

gitlab-ci

oleorhagen
feat(mender-auth): Add the main event loop

Ticket: MEN-6467
Changelog: None

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>

65 of 65 new or added lines in 2 files covered. (100.0%)

5237 of 6624 relevant lines covered (79.06%)

199.93 hits per line

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

63.27
/mender-auth/ipc/server.cpp
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
#include <mender-auth/ipc/server.hpp>
16

17
#include <functional>
18
#include <iostream>
19
#include <string>
20

21
#include <common/common.hpp>
22
#include <common/error.hpp>
23
#include <common/events_io.hpp>
24
#include <common/http.hpp>
25
#include <common/log.hpp>
26

27
namespace mender {
28
namespace auth {
29
namespace ipc {
30

31
using namespace std;
32

33
namespace type {
34
namespace webserver {
35

36
auto NoOpHeaderHandler = [](http::ExpectedIncomingRequestPtr exp_req) {};
2✔
37

38
// Run a webserver and handle the events as requests
39
error::Error Caching::Listen(
2✔
40
        const string &server_url, const string &private_key_path, const string &identity_script_path) {
41
        return this->server_.AsyncServeUrl(
42
                server_url,
43
                NoOpHeaderHandler,
44
                [this, private_key_path, identity_script_path](http::ExpectedIncomingRequestPtr exp_req) {
6✔
45
                        if (!exp_req) {
2✔
46
                                log::Error("Expected request failure: " + exp_req.error().message);
×
47
                                return;
×
48
                        }
49
                        auto req = exp_req.value();
2✔
50

51
                        auto exp_resp = req->MakeResponse();
2✔
52
                        if (!exp_resp) {
2✔
53
                                log::Error("Failed to create the response: " + exp_resp.error().message);
×
54
                                return;
×
55
                        }
56
                        auto resp = exp_resp.value();
2✔
57

58
                        log::Debug("Got path: " + req->GetPath());
2✔
59

60
                        if (req->GetPath() == "/getjwttoken") {
2✔
61
                                resp->SetHeader("X-MEN-JWTTOKEN", this->GetJWTToken());
1✔
62
                                resp->SetHeader("X-MEN-SERVERURL", this->GetServerURL());
1✔
63
                                resp->SetStatusCodeAndMessage(200, "Success");
1✔
64
                                resp->AsyncReply([](error::Error err) {
1✔
65
                                        if (err != error::NoError) {
1✔
66
                                                log::Error("Failed to reply: " + err.message);
×
67
                                        };
68
                                });
3✔
69
                        } else if (req->GetPath() == "/fetchjwttoken") {
1✔
70
                                auto err = auth_client::FetchJWTToken(
71
                                        this->client_,
1✔
72
                                        this->server_url_,
1✔
73
                                        private_key_path,
1✔
74
                                        identity_script_path,
1✔
75
                                        [this](auth_client::APIResponse resp) {
2✔
76
                                                this->CacheAPIResponse(this->server_url_, resp);
1✔
77
                                        },
1✔
78
                                        this->tenant_token_);
1✔
79
                                if (err != error::NoError) {
1✔
80
                                        log::Error("Failed to set up the fetch request: " + err.message);
×
81
                                        resp->SetStatusCodeAndMessage(500, "Internal Server Error");
×
82
                                        resp->AsyncReply([](error::Error err) {
×
83
                                                if (err != error::NoError) {
×
84
                                                        log::Error("Failed to reply: " + err.message);
×
85
                                                };
86
                                        });
×
87
                                        return;
×
88
                                }
89
                                resp->SetStatusCodeAndMessage(200, "Success");
1✔
90
                                resp->AsyncReply([](error::Error err) {
1✔
91
                                        if (err != error::NoError) {
1✔
92
                                                log::Error("Failed to reply: " + err.message);
×
93
                                        };
94
                                });
3✔
95
                        } else {
96
                                resp->SetStatusCodeAndMessage(404, "Not Found");
×
97
                                resp->AsyncReply([](error::Error err) {
×
98
                                        if (err != error::NoError) {
×
99
                                                log::Error("Failed to reply: " + err.message);
×
100
                                        };
101
                                });
×
102
                        }
103
                });
2✔
104
}
105
} // namespace webserver
106
} // namespace type
107

108
} // namespace ipc
109
} // namespace auth
110
} // 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

© 2025 Coveralls, Inc