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

mendersoftware / mender / 974575668

21 Aug 2023 12:04PM UTC coverage: 78.829% (-0.05%) from 78.877%
974575668

push

gitlab-ci

kacf
chore: Implement pushing of logs to the server.

Ticket: MEN-6581

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

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

5492 of 6967 relevant lines covered (78.83%)

238.75 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 == "" ? default_identity_script_path_
1✔
75
                                                                                           : identity_script_path,
76
                                        [this](auth_client::APIResponse resp) {
2✔
77
                                                this->CacheAPIResponse(this->server_url_, resp);
1✔
78
                                        },
1✔
79
                                        this->tenant_token_);
2✔
80
                                if (err != error::NoError) {
1✔
81
                                        log::Error("Failed to set up the fetch request: " + err.message);
×
82
                                        resp->SetStatusCodeAndMessage(500, "Internal Server Error");
×
83
                                        resp->AsyncReply([](error::Error err) {
×
84
                                                if (err != error::NoError) {
×
85
                                                        log::Error("Failed to reply: " + err.message);
×
86
                                                };
87
                                        });
×
88
                                        return;
×
89
                                }
90
                                resp->SetStatusCodeAndMessage(200, "Success");
1✔
91
                                resp->AsyncReply([](error::Error err) {
1✔
92
                                        if (err != error::NoError) {
1✔
93
                                                log::Error("Failed to reply: " + err.message);
×
94
                                        };
95
                                });
3✔
96
                        } else {
97
                                resp->SetStatusCodeAndMessage(404, "Not Found");
×
98
                                resp->AsyncReply([](error::Error err) {
×
99
                                        if (err != error::NoError) {
×
100
                                                log::Error("Failed to reply: " + err.message);
×
101
                                        };
102
                                });
×
103
                        }
104
                });
2✔
105
}
106
} // namespace webserver
107
} // namespace type
108

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